Advertisement
overactive

SFd

Jul 31st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import pygame
  2. import random
  3.  
  4. WIDTH, HEIGHT = 600, 700
  5. WHITE = (255, 255, 255)
  6. BLUE = (0,100,200)
  7. RAIN_DENSITY = 50
  8. dropList = []
  9. canvas = pygame.display.set_mode((WIDTH,HEIGHT))
  10. background  = pygame.Surface((WIDTH,HEIGHT))
  11. pygame.display.set_caption('Rain')
  12. pygame.init()
  13.  
  14. def quitGame():
  15.     pygame.quit()
  16.     sys.exit(0)
  17.  
  18. for i in range(RAIN_DENSITY):
  19.     x = random.randint(0, WIDTH-2)
  20.     y = random.randint(-700, -10)
  21.     speed = random.randint(2, 3)
  22.     dropList.append([x, y, speed])
  23.  
  24. while True:
  25.     for event in pygame.event.get():
  26.         if event.type == pygame.QUIT:
  27.             quitGame()
  28.  
  29.     canvas.blit(background, (0,0))
  30.     for i in dropList:
  31.         i[1] += i[2]
  32.         drop = (i[0], i[1], 2, 20)
  33.         pygame.draw.rect(canvas, BLUE, drop, 2)
  34.  
  35.         if i[1] > HEIGHT:
  36.             i[0] = random.randint(0, WIDTH-2)
  37.             i[1] = random.randint(-50, -10)
  38.             i[2] = random.randint(2,3)
  39.            
  40.     pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement