Advertisement
cookertron

Bouncing Ball - Pygame

Nov 24th, 2018
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. import pygame
  2. import sys
  3.  
  4. W, H = 200, 500
  5. JUMP_HEIGHT = 300
  6. STEPS = 60
  7. G = 2.0 * JUMP_HEIGHT / (STEPS * (STEPS - 1))
  8. V = -(G * (STEPS - 1))
  9.  
  10. r = 25
  11. y = H - r
  12. x = W / 2
  13. v = V
  14.  
  15. pygame.init()
  16. DS = pygame.display.set_mode((W, H))
  17. clock = pygame.time.Clock()
  18.  
  19. while True:
  20.     for event in pygame.event.get():
  21.         if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
  22.             pygame.quit()
  23.             sys.exit()
  24.            
  25.     pygame.draw.circle(DS, (255, 255, 255), (x, int(y)), r, 0)
  26.     pygame.display.update()
  27.     clock.tick(60)
  28.     DS.fill((0, 0, 0))
  29.    
  30.     y += v
  31.     v += G
  32.     if y > H - r:
  33.         v = V
  34.         y = H - r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement