-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPygame_testi.py
More file actions
53 lines (40 loc) · 1.5 KB
/
Copy pathPygame_testi.py
File metadata and controls
53 lines (40 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Testaillaan Pygame-kirjastoa.
"""
import pygame
# Alustetaan Pygame
pygame.init()
# Ruudun leveys ja korkeus
width, height = 800, 800
# Luodaan ikkuna
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Paska peli")
# Vaihdetaan ikkunan väri
screen.fill((255, 255, 255))
# Piirretään ympyrä
pygame.draw.circle(screen, (0, 0, 0), (width / 2, height / 2), 25)
# Piirretään viiva
pygame.draw.line(screen, (0, 255, 0), (width / 2, 0), (width / 2, height / 2), 10)
# Pelisilmukka
running = True
while running:
# käsitellään tapahtumat
for event in pygame.event.get():
# Jos painetaan ruksia, poistutaan silmukasta ja suljetaan ohjelma
if event.type == pygame.QUIT:
running = False
# Jos painetaan vasenta nuolinäppäintä, muutetaan taustaväriä
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
screen.fill((255, 0, 0))
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
screen.fill((255, 255, 255))
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_k:
pygame.draw.circle(screen, (255, 255, 0), (width / 2, height / 2), 25)
# Päivitetään kaikkien objektien paikat ja nopeudet
# Päivitetään ruutu
pygame.draw.line(screen, (0, 255, 0), (width / 2, 0), (width / 2, height / 2), 10)
#pygame.draw.circle(screen, (0, 0, 0), (width / 2, height / 2), 25)
pygame.display.update()