You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.2 KiB
56 lines
1.2 KiB
import pygame
|
|
import random
|
|
import sys
|
|
|
|
pygame.init()
|
|
|
|
SIRKA = 800
|
|
VYSKA = 600
|
|
okno = pygame.display.set_mode((SIRKA,VYSKA))
|
|
pygame.display.set_caption("Pohyb hráče")
|
|
|
|
|
|
CERNA = (0,0,0)
|
|
CERVENA = (255,0,0)
|
|
ZELENA = (0,255,0)
|
|
MODRA = (0,0,255)
|
|
|
|
hodiny = pygame.time.Clock()
|
|
|
|
#proměná hráče
|
|
hrac_x = 400
|
|
hrac_y = 300
|
|
hrac_sirka = 50
|
|
hrac_vyska = 50
|
|
rychlost = 5
|
|
|
|
bezime = True
|
|
while bezime:
|
|
for udalost in pygame.event.get():
|
|
if udalost.type == pygame.QUIT:
|
|
bezime = False
|
|
|
|
#POHYB HRÁČE NA STIKNUTÍ KLÁVES
|
|
klavesy = pygame.key.get_pressed()
|
|
if klavesy[pygame.K_LEFT]:
|
|
hrac_x -= rychlost
|
|
if klavesy[pygame.K_RIGHT]:
|
|
hrac_x += rychlost
|
|
if klavesy[pygame.K_UP]:
|
|
hrac_y -= rychlost
|
|
if klavesy[pygame.K_DOWN]:
|
|
hrac_y += rychlost
|
|
|
|
#omezení aby hráč nevyjel:
|
|
if hrac_x < 0 : hrac_x = 0
|
|
if hrac_y < 0 : hrac_y = 0
|
|
if hrac_x > SIRKA - hrac_sirka: hrac_x = SIRKA - hrac_sirka
|
|
if hrac_y > VYSKA - hrac_vyska: hrac_y = VYSKA - hrac_vyska
|
|
|
|
okno.fill(CERNA)
|
|
pygame.draw.rect(okno,MODRA,(hrac_x,hrac_y,hrac_sirka,hrac_vyska))
|
|
pygame.display.flip()
|
|
hodiny.tick(60)
|
|
|
|
pygame.quit()
|
|
sys.exit()
|
|
|