0

No, there was a sys.MAXINT constant in older versions of python, but now integers are unlimited since int's become long's when they are too large. However, you can set MAXCNT to a very large value, so that your program only stops in the 22th century.

0

Here's the code I alluded to yesterday...

import sys, pygame, math

pygame.init()

xpos = 92
ypos = 0
gravity = 9.8
velocity = 0
# How much of the velocity of the ball is retained on a bounce
bounce = 0.8
win_h = 400

screen = pygame.display.set_mode((200, win_h), 0, 32)
ball = pygame.image.load('box.bmp')
clock = pygame.time.Clock()
size_bott = ball.get_rect().bottom


# The main loop
while True:
    # Test for exit
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()

    # The physics
    # Reverse velocity taking into account bounciness if we hit the ground
    if ypos >= (win_h - size_bott) and velocity > 0:
        # Avoid the ball sinking into the ground
        ypos = (win_h - size_bott)
        velocity = -velocity * bounce

    time_passed = clock.tick(60) / 1000.0
    newvelocity = velocity + (gravity * time_passed)
    # Use the average velocity over the period of the frame to change position
    ypos = ypos + int(((velocity + newvelocity) / 2) * time_passed * 160)
    velocity = newvelocity

    # Update the screen
    screen.fill((0, 0, 0))
    screen.blit(ball, (xpos, ypos))
    pygame.display.update()

The only change I made was to account for the height of the "box.bmp" dynamically since it was hard coded as 16 pixels before...

0

Thanks you very much! I understand the code now; I can't do "(ballSpeed[1]/4*3)", but in order for it to work, I must create separate variables for the numbers: "ypos = ypos + int(((velocity + newvelocity) / 2) * time_passed * 160)". A little bit longer math, but it's worth it! Thanks!

0

For completeness' sake be sure to let us know how you've implemented your changes once you get it working satisfactorily.

0

I'm still working on it, but I am working on including some code that will let you drag the ball around and throw it (hopefully more than just on the Y axis) and a Tk window that will let you change the gravity, ball weight, etc.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.