Skip to content
Snippets Groups Projects
Commit dad2a3a0 authored by Harri Vaara's avatar Harri Vaara
Browse files

Upload New File

parent 011f09a7
Branches
Tags
No related merge requests found
import pygame
# Alustetaan Pygame
pygame.init()
# Asetetaan ikkunan koko
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Lumiukko")
# Värit
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
ORANGE = (255, 165, 0)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
# Lumiukon koordinaatit ja nopeus
x, y = SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2
speed = 5
# Lumiukon piirtämisfunktio
def draw_snowman(x, y):
# Piirretään kolme päällekkäistä ympyrää (pallot)
pygame.draw.circle(screen, WHITE, (x, y), 50) # Alin pallo
pygame.draw.circle(screen, WHITE, (x, y - 100), 40) # Keskimmäinen pallo
pygame.draw.circle(screen, WHITE, (x, y - 200), 30) # Ylin pallo
# Piirretään silmät
pygame.draw.circle(screen, BLACK, (x - 10, y - 210), 5) # Vasemmassa silmä
pygame.draw.circle(screen, BLACK, (x + 10, y - 210), 5) # Oikeassa silmä
# Piirretään suu (kaarimuotoinen)
pygame.draw.arc(screen, BLACK, (x - 15, y - 200, 30, 20), 3.14, 2*3.14, 2)
# Piirretään nenä (pieni oranssi kolmio)
pygame.draw.polygon(screen, ORANGE, [(x, y - 205), (x + 10, y - 195), (x - 10, y - 195)])
# Piirretään kaulaliina (punainen suorakaide)
pygame.draw.rect(screen, RED, (x - 40, y - 175, 80, 15))
# Piirretään kädet (suorat viivat)
pygame.draw.line(screen, BLUE, (x - 50, y - 150), (x - 100, y - 150), 5) # Vasemman käden varsi
pygame.draw.line(screen, BLUE, (x + 50, y - 150), (x + 100, y - 150), 5) # Oikean käden varsi
# Piirretään hattu (mustalla suorakaide ja kolmio)
pygame.draw.rect(screen, BLACK, (x - 35, y - 230, 70, 10)) # Hattunauha
pygame.draw.polygon(screen, BLACK, [(x - 40, y - 230), (x + 40, y - 230), (x, y - 260)]) # Hattu
# Pygamen pääsilmukka
running = True
while running:
# Tapahtumakäsittely
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Näppäinpainallukset nuolinäppäimillä
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
x -= speed
if keys[pygame.K_RIGHT]:
x += speed
if keys[pygame.K_UP]:
y -= speed
if keys[pygame.K_DOWN]:
y += speed
# Täytetään tausta mustalla
screen.fill(BLACK)
# Piirretään lumiukko
draw_snowman(x, y)
# Päivitetään näyttö
pygame.display.update()
# Säilytetään 60 FPS
pygame.time.Clock().tick(60)
# Lopetetaan Pygame
pygame.quit()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment