SHARE
TWEET

Untitled

a guest Jul 16th, 2019 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame
  2. import random
  3.  
  4. pygame.init()
  5.  
  6. DISPLAY_WIDTH = 800
  7. DISPLAY_HEIGHT = 600
  8.  
  9. gameDisplay = pygame.display.set_mode((DISPLAY_WIDTH, DISPLAY_HEIGHT))
  10. pygame.display.set_caption("DVD Screen Protection")
  11.  
  12. WHITE = (255, 255, 255)
  13. R = 0
  14. G = 0
  15. B = 0
  16.  
  17. ball_x = 400
  18. ball_y = 0
  19. direction_x = 1
  20. direction_y = 1
  21.  
  22. clock = pygame.time.Clock()
  23.  
  24. playing = True
  25. while playing:
  26.     for event in pygame.event.get():
  27.         if event.type == pygame.QUIT:
  28.             playing = False
  29.    
  30.     ball_y += 10 * direction_y
  31.     ball_x += 10 * direction_x
  32.     collision = 0
  33.  
  34.     if ball_y <= 0:
  35.         direction_y = 1
  36.         collision = 1
  37.     elif ball_y + 75 >= 600:
  38.         direction_y = -1
  39.         collision = 1
  40.     elif ball_x <= 0:
  41.         direction_x = 1
  42.         collision = 1
  43.     elif ball_x + 150 >= 800:
  44.         direction_x = -1
  45.         collision = 1
  46.     else:
  47.         collision = 0
  48.        
  49.    
  50.     if collision == 1:
  51.         R = random.randint(0, 255)
  52.         G = random.randint(0, 255)
  53.         B = random.randint(0, 255)
  54.  
  55.     COLOR = (R, G, B)
  56.     gameDisplay.fill(WHITE)     # fill the canvas with white to clean the screen
  57.     pygame.draw.ellipse(gameDisplay, COLOR, pygame.Rect(ball_x, ball_y, 150, 75))
  58.     pygame.display.update()
  59.     clock.tick(30)      # fps
  60.  
  61. pygame.quit()
  62. quit()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top