python - Hard to find bug that involves strange physics behaviour in pygame code -


first i'll i'm pretty tired i've been 22 hours straight. anyway have funky physics problem in pong game. know old classic. have been looking @ code long time trying different variation, commenting out parts etc. , can't find damn bug!

can give me hand, please?

it's physics ball that's problem. bounces off top , bottom screen fine when going left fine.

but can't send going right after collides paddle coming left. forces bounces off bit , forces it's way , on paddle?!

however can send ball right when program bounce right after hitting 1 of top or bottom sides, don't think there wrong actual code moves ball right.

but movement right opposite of desired physics game, it's useless because it's supposed bounce off , go right when hits paddle on left, it's not supposed "force" self on paddle , go left.

it's kind of funny if see it:)

can make sense of , give me explanation this?

[code]

    # move ball around      # if ball disappears off either side of screen, send heading  left     if ballrect.left > windowwidth or ballrect.right < 0:         direction = getrandomdirection()         ballrect.center = (windowwidth - ballrect.width, random.randint(100, 200))      if direction == 'downleft':         ballrect.left -= ballspeedx         ballrect.top += ballspeedy     if direction == 'upleft':         ballrect.left -= ballspeedx         ballrect.top -= ballspeedy     if direction == 'downright':         ballrect.left += ballspeedx         ballrect.top += ballspeedy     if direction == 'upright':         ballrect.left += ballspeedx         ballrect.top -= ballspeedy      if ballrect.top < 0:         if direction == 'upleft':             direction = 'downleft'         if direction == 'upright':             direction = 'downright'     if ballrect.bottom > windowheight:         if direction == 'downleft':             direction = 'upleft'         if direction == 'downright':             direction = 'upright'      if paddlerect.colliderect(ballrect):         if direction == 'upleft':             direction = 'upright'             ballrect.left += ballspeedx             ballrect.top -= ballspeedy         if direction == 'upright':             direction = 'upleft'             ballrect.left += ballspeedx             ballrect.top -= ballspeedy         if direction == 'downleft':             direction = 'upleft'             ballrect.left += ballspeedx             ballrect.top += ballspeedy         if direction == 'downright':             direction = 'upright'             ballrect.left -= ballspeedx             ballrect.top += ballspeedy 

[/code]

if directions == 'upleft', both these blocks execute

if paddlerect.colliderect(ballrect):     if direction == 'upleft':         direction = 'upright'         ballrect.left += ballspeedx * 4         ballrect.top -= ballspeedy * 4     if direction == 'upright':         direction = 'upleft'         ballrect.left += ballspeedx * 4         ballrect.top -= ballspeedy * 4 

probably should more this

if paddlerect.colliderect(ballrect):     if direction == 'upleft':         direction = 'upright'         ballrect.left += ballspeedx * 4         ballrect.top -= ballspeedy * 4     elif direction == 'upright':         direction = 'upleft'         ballrect.left += ballspeedx * 4         ballrect.top -= ballspeedy * 4     elif ... 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -