Advertisement
Guest User

Pygame

a guest
Sep 17th, 2019
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. import pygame
  2. pygame.init()
  3.  
  4. win = pygame.display.set_mode((500, 500))
  5. pygame.display.set_caption("Bouncy Ball")
  6.  
  7. x = 210
  8. y = 400
  9. b_x = 250
  10. b_y = 100
  11. width = 100
  12. hight = 17
  13. speed = 16
  14. white = 255, 255, 255
  15. bold_drop = 17
  16.  
  17. run = True
  18. while run:
  19.     pygame.time.delay(40)
  20.  
  21.     for event in pygame.event.get():
  22.         if event.type == pygame.QUIT:
  23.             run = False
  24.  
  25.     keys = pygame.key.get_pressed()
  26.  
  27.     if keys[pygame.K_RIGHT]:
  28.         x += speed
  29.     if keys[pygame.K_LEFT]:
  30.         x -= speed
  31.  
  32.     win.fill((0, 0, 0))
  33.     rectancel = pygame.draw.rect(win, (white), (x, y, width, hight))
  34.     pygame.display.update()
  35.  
  36.     ball = pygame.draw.circle(win, (white), (b_x, b_y), 7)
  37.     pygame.display.update()
  38.  
  39.  
  40.     b_y += bold_drop
  41.  
  42.     if ball.colliderect(rectancel):
  43.         b_y -= bold_drop
  44.  
  45. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement