forked from s444417/ProjektAI
60 lines
1.4 KiB
Python
60 lines
1.4 KiB
Python
import pygame
|
|
|
|
#initialize the pygame
|
|
pygame.init()
|
|
|
|
#create the screen
|
|
screen = pygame.display.set_mode((1000,1000))
|
|
|
|
#caption
|
|
pygame.display.set_caption("Bardzo mądry kelner")
|
|
|
|
#grid
|
|
gridImg = pygame.image.load("20x20grid.png")
|
|
gridX = 0
|
|
gridY = 0
|
|
|
|
#weiter
|
|
waiterImg = pygame.image.load("waiter.png")
|
|
waiterX = 10
|
|
waiterY = 1
|
|
waiterX_change = 0
|
|
waiterY_change = 0
|
|
|
|
def grid():
|
|
screen.blit(gridImg, (gridX,gridY))
|
|
|
|
def waiter(x, y):
|
|
screen.blit(waiterImg, (x,y))
|
|
|
|
#loop
|
|
running = True
|
|
while running:
|
|
|
|
# RGB
|
|
screen.fill((255, 255, 255))
|
|
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
running = False
|
|
|
|
if event.type == pygame.KEYDOWN:
|
|
if event.key == pygame.K_LEFT:
|
|
waiterX_change = -50
|
|
if event.key == pygame.K_RIGHT:
|
|
waiterX_change = 50
|
|
if event.key == pygame.K_UP:
|
|
waiterY_change = -50
|
|
if event.key == pygame.K_DOWN:
|
|
waiterY_change = 50
|
|
if event.type == pygame.KEYUP:
|
|
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
|
|
waiterX_change = 0
|
|
if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
|
|
waiterY_change = 0
|
|
|
|
grid()
|
|
waiterX += waiterX_change
|
|
waiterY += waiterY_change
|
|
waiter(waiterX, waiterY)
|
|
pygame.display.update() |