overactive

jhsad

Jul 31st, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. import pygame
  2. import random
  3. import sys
  4. import time
  5.  
  6. WIDTH, HEIGHT = 600, 700
  7. WHITE = (255, 255, 255)
  8. BLUE = (0,100,200)
  9. RAIN_DENSITY = 50
  10. dropList = []
  11.  
  12. canvas = pygame.display.set_mode((WIDTH,HEIGHT))
  13. background  = pygame.Surface((WIDTH,HEIGHT))
  14. pygame.display.set_caption('Rain')
  15. pygame.init()
  16.  
  17. def quitGame():
  18.     pygame.quit()
  19.     sys.exit(0)
  20.  
  21. class Drop():
  22.     def __init__(self):
  23.         pass
  24.  
  25.     def randomize(self):
  26.         self.x = random.randint(0, WIDTH-2)
  27.         self.y = random.randint(-700, -10)
  28.         self.speed = random.randint(1, 2)
  29.  
  30.         return self.x, self.y, self.speed
  31.  
  32.     def getDropList(self):
  33.         dropList.append([self.x, self.y, self.speed])
  34.         return dropList
  35.  
  36.     def update(self, dropList):
  37.         for d in dropList:
  38.             d[1] += d[2]
  39.             self.drop = (d[0], d[1], 2, 20)
  40.            
  41.             rain.show()
  42.            
  43.             if d[1] > HEIGHT:
  44.                 d[0], d[1], d[2] = rain.randomize()
  45.  
  46.     def show(self):
  47.         pygame.draw.rect(canvas, BLUE, self.drop, 3)
  48.  
  49. rain = Drop()
  50. for i in range(RAIN_DENSITY):
  51.     rain.randomize()
  52.     dropList = rain.getDropList()
  53.  
  54. while True:
  55.     for event in pygame.event.get():
  56.         if event.type == pygame.QUIT:
  57.             quitGame()
  58.  
  59.     canvas.blit(background, (0,0))
  60.     rain.update(dropList)
  61.     pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment