Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- import sys
- import time
- WIDTH, HEIGHT = 600, 700
- WHITE = (255, 255, 255)
- BLUE = (0,100,200)
- RAIN_DENSITY = 50
- dropList = []
- canvas = pygame.display.set_mode((WIDTH,HEIGHT))
- background = pygame.Surface((WIDTH,HEIGHT))
- pygame.display.set_caption('Rain')
- pygame.init()
- def quitGame():
- pygame.quit()
- sys.exit(0)
- class Drop():
- def __init__(self):
- pass
- def randomize(self):
- self.x = random.randint(0, WIDTH-2)
- self.y = random.randint(-700, -10)
- self.speed = random.randint(1, 2)
- return self.x, self.y, self.speed
- def getDropList(self):
- dropList.append([self.x, self.y, self.speed])
- return dropList
- def update(self, dropList):
- for d in dropList:
- d[1] += d[2]
- self.drop = (d[0], d[1], 2, 20)
- rain.show()
- if d[1] > HEIGHT:
- d[0], d[1], d[2] = rain.randomize()
- def show(self):
- pygame.draw.rect(canvas, BLUE, self.drop, 3)
- rain = Drop()
- for i in range(RAIN_DENSITY):
- rain.randomize()
- dropList = rain.getDropList()
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- quitGame()
- canvas.blit(background, (0,0))
- rain.update(dropList)
- pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment