Advertisement
sec_goat

Python Pong Collision Detection

Mar 29th, 2013
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. def moveBall():
  2.     if ball['y'] > (COURT_HEIGHT - 25) and ball['x'] <= (computerPaddle.right + ball['radius']) and ball['x'] >= (computerPaddle.left - ball['radius']):
  3.         ball['speed'] += 1
  4.         if ball['dir'] == DOWNRIGHT:
  5.             ball['dir'] = UPRIGHT
  6.         if ball['dir'] == DOWNLEFT:
  7.             ball['dir'] = UPLEFT
  8.     elif ball['y'] > COURT_HEIGHT:
  9.         score['player'] += 1
  10.         newRound()
  11.  
  12.     if ball['y'] < 25 and ball['x'] <= (playerPaddle.right + ball['radius']) and ball['x'] >= (playerPaddle.left - ball['radius']):
  13.         ball['speed'] += 1
  14.         if ball['dir'] == UPRIGHT:
  15.             ball['dir'] = DOWNRIGHT
  16.         if ball['dir'] == UPLEFT:
  17.             ball['dir'] = DOWNLEFT
  18.     elif ball['y'] < 0:
  19.         score['computer'] += 1
  20.         newRound()
  21.  
  22.  
  23.     if ball['x'] > COURT_WIDTH - ball['radius']:
  24.         if ball['dir'] == UPRIGHT:
  25.             ball['dir'] = UPLEFT
  26.         if ball['dir'] == DOWNRIGHT:
  27.             ball['dir'] = DOWNLEFT
  28.  
  29.     if ball['x'] < ball['radius']:
  30.         if ball['dir'] == UPLEFT:
  31.             ball['dir'] = UPRIGHT
  32.         if ball['dir'] == DOWNLEFT:
  33.             ball['dir'] = DOWNRIGHT
  34.  
  35.  
  36.     if ball['dir'] == UPLEFT:
  37.         ball['x'] -= ball['speed']
  38.         ball['y'] -= ball['speed']
  39.  
  40.     if ball['dir'] == UPRIGHT:
  41.         ball['y'] -= ball['speed']
  42.         ball['x'] += ball['speed']
  43.  
  44.     if ball['dir'] == DOWNLEFT:
  45.         ball['y'] += ball['speed']
  46.         ball['x'] -= ball['speed']
  47.  
  48.     if ball['dir'] == DOWNRIGHT:
  49.         ball['y'] += ball['speed']
  50.         ball['x'] += ball['speed']
  51.  
  52.     #print(ballX, ballY)
  53.     pygame.draw.circle(windowSurface, WHITE, (ball['x'], ball['y']), ball['radius'], 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement