Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- 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)
- for i in range(RAIN_DENSITY):
- x = random.randint(0, WIDTH-2)
- y = random.randint(-700, -10)
- speed = random.randint(2, 3)
- dropList.append([x, y, speed])
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- quitGame()
- canvas.blit(background, (0,0))
- for i in dropList:
- i[1] += i[2]
- drop = (i[0], i[1], 2, 20)
- pygame.draw.rect(canvas, BLUE, drop, 2)
- if i[1] > HEIGHT:
- i[0] = random.randint(0, WIDTH-2)
- i[1] = random.randint(-50, -10)
- i[2] = random.randint(2,3)
- pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement