Skip to content
Snippets Groups Projects
Commit 7057ff21 authored by Jere Jaakkola's avatar Jere Jaakkola
Browse files

Upload New File

parent 011f09a7
No related branches found
No related tags found
No related merge requests found
import pygame
def alusta():
pygame.init()
naytto = pygame.display.set_mode((640, 480))
return naytto
def piirra_lumiukko(naytto, x: int, y: int):
pygame.draw.circle(naytto, (255, 255, 255), (x, y), 40)
pygame.draw.circle(naytto, (255, 255, 255), (x, y - 50), 30)
pygame.draw.circle(naytto, (255, 255, 255), (x, y - 90), 20)
naytto = alusta()
lumiukko_x = 320
lumiukko_y = 200
YLAREUNA = 0
VASEN_REUNA = 0
OIKEA_REUNA = 640
ALAREUNA = 480
NOPEUS = 2
ajastin = pygame.time.Clock()
while True:
for tapahtuma in pygame.event.get():
if tapahtuma.type == pygame.QUIT:
pygame.quit()
exit()
painetut_nappulat = pygame.key.get_pressed()
if painetut_nappulat[pygame.K_LEFT]:
lumiukko_x -= NOPEUS
if painetut_nappulat[pygame.K_RIGHT]:
lumiukko_x += NOPEUS
if painetut_nappulat[pygame.K_DOWN]:
lumiukko_y += NOPEUS
if painetut_nappulat[pygame.K_UP]:
lumiukko_y -= NOPEUS
if lumiukko_x < VASEN_REUNA:
lumiukko_x = VASEN_REUNA
if lumiukko_x > OIKEA_REUNA:
lumiukko_x = OIKEA_REUNA
if lumiukko_y < YLAREUNA:
lumiukko_y = YLAREUNA
if lumiukko_y > ALAREUNA:
lumiukko_y = ALAREUNA
naytto.fill((0, 0, 0))
piirra_lumiukko(naytto, lumiukko_x, lumiukko_y)
pygame.display.flip()
ajastin.tick(160)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment