Skip to content
Snippets Groups Projects
Commit 607bdb04 authored by Lauri Miettinen's avatar Lauri Miettinen
Browse files

Upload New File

parent e20c9ea0
Branches main
No related tags found
No related merge requests found
import pygame
import random
import sys
pygame.init()
SCREEN_WIDTH, SCREEN_HEIGHT = 640, 480
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Lumihiutaleet")
lumihiutaleet_kuvat = [
pygame.image.load("lumihiutale1.png"),
pygame.image.load("lumihiutale2.png"),
pygame.image.load("lumihiutale3.png")
]
lumihiutaleet = []
for _ in range(10):
kuva = random.choice(lumihiutaleet_kuvat)
x = random.randint(0, SCREEN_WIDTH - kuva.get_width())
y = random.randint(-SCREEN_HEIGHT, 0)
speed = random.randint(1, 5)
lumihiutaleet.append({"x": x, "y": y, "speed": speed, "kuva": kuva})
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
for hiutale in lumihiutaleet:
hiutale["y"] += hiutale["speed"]
if hiutale["y"] > SCREEN_HEIGHT:
hiutale["y"] = -hiutale["kuva"].get_height()
hiutale["x"] = random.randint(0, SCREEN_WIDTH - hiutale["kuva"].get_width())
hiutale["speed"] = random.randint(1, 5)
screen.fill((0, 0, 0))
for hiutale in lumihiutaleet:
screen.blit(hiutale["kuva"], (hiutale["x"], hiutale["y"]))
pygame.display.flip()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment