2020-03-22 02:01:57 +01:00
|
|
|
import pygame
|
2020-03-22 18:10:44 +01:00
|
|
|
import time
|
2020-03-22 02:01:57 +01:00
|
|
|
|
2020-03-22 18:10:44 +01:00
|
|
|
# initialize the pygame
|
2020-03-22 02:01:57 +01:00
|
|
|
pygame.init()
|
|
|
|
|
2020-03-22 18:10:44 +01:00
|
|
|
# initiate variables
|
2020-03-22 02:01:57 +01:00
|
|
|
screen = pygame.display.set_mode((1000,1000))
|
|
|
|
pygame.display.set_caption("Bardzo mądry kelner")
|
|
|
|
|
2020-03-22 18:10:44 +01:00
|
|
|
# Grid variables
|
2020-03-22 02:01:57 +01:00
|
|
|
gridImg = pygame.image.load("20x20grid.png")
|
|
|
|
gridX = 0
|
|
|
|
gridY = 0
|
|
|
|
|
2020-03-22 18:10:44 +01:00
|
|
|
# Waiter variables
|
2020-03-22 02:01:57 +01:00
|
|
|
waiterImg = pygame.image.load("waiter.png")
|
|
|
|
waiterX = 10
|
2020-03-22 18:10:44 +01:00
|
|
|
waiterY = 10
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: classes in separate folders
|
|
|
|
|
|
|
|
|
|
|
|
class Grid:
|
|
|
|
|
|
|
|
def __init__(self, g_x, g_y, grid_img):
|
|
|
|
self.g_x = g_x
|
|
|
|
self.g_y = g_y
|
|
|
|
|
|
|
|
self.grid_img = grid_img
|
|
|
|
|
|
|
|
def draw_grid(self):
|
|
|
|
global screen
|
|
|
|
screen.blit(self.grid_img, (self.g_x, self.g_y))
|
|
|
|
|
|
|
|
|
|
|
|
class Waiter:
|
|
|
|
def __init__(self, w_x, w_y, waiter_img):
|
|
|
|
self.waiter_img = waiter_img
|
|
|
|
self.w_x = w_x
|
|
|
|
self.w_y = w_y
|
|
|
|
self.position = [w_x, w_y]
|
|
|
|
|
|
|
|
def draw_waiter(self):
|
|
|
|
global screen
|
|
|
|
screen.blit(self.waiter_img, self.position)
|
|
|
|
|
|
|
|
def move_left(self, w_x):
|
|
|
|
self.position[0] = (self.position[0]-w_x) % 1000
|
|
|
|
screen.blit(self.waiter_img, self.position)
|
|
|
|
|
|
|
|
def move_right(self, w_x):
|
|
|
|
self.position[0] = (self.position[0]+w_x) % 1000
|
|
|
|
screen.blit(self.waiter_img, self.position)
|
|
|
|
|
|
|
|
def move_up(self, w_y):
|
|
|
|
self.position[1] = (self.position[1]-w_y) % 1000
|
|
|
|
screen.blit(self.waiter_img, self.position)
|
|
|
|
|
|
|
|
def move_down(self, w_y):
|
|
|
|
self.position[1] = (self.position[1]+w_y) % 1000
|
|
|
|
screen.blit(self.waiter_img, self.position)
|
|
|
|
|
|
|
|
|
|
|
|
# waiter
|
2020-03-22 02:01:57 +01:00
|
|
|
waiterX_change = 0
|
|
|
|
waiterY_change = 0
|
|
|
|
|
2020-03-22 18:10:44 +01:00
|
|
|
grid = Grid(gridX, gridY, gridImg)
|
|
|
|
waiter = Waiter(waiterX, waiterY, waiterImg)
|
2020-03-22 02:01:57 +01:00
|
|
|
|
2020-03-22 18:10:44 +01:00
|
|
|
# loop
|
2020-03-22 02:01:57 +01:00
|
|
|
running = True
|
|
|
|
while running:
|
|
|
|
|
|
|
|
# RGB
|
|
|
|
screen.fill((255, 255, 255))
|
|
|
|
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
running = False
|
2020-03-22 18:10:44 +01:00
|
|
|
# TODO: switch case
|
2020-03-22 02:01:57 +01:00
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
if event.key == pygame.K_LEFT:
|
2020-03-22 18:10:44 +01:00
|
|
|
waiter.move_left(20)
|
2020-03-22 02:01:57 +01:00
|
|
|
if event.key == pygame.K_RIGHT:
|
2020-03-22 18:10:44 +01:00
|
|
|
waiter.move_right(20)
|
2020-03-22 02:01:57 +01:00
|
|
|
if event.key == pygame.K_UP:
|
2020-03-22 18:10:44 +01:00
|
|
|
waiter.move_up(20)
|
2020-03-22 02:01:57 +01:00
|
|
|
if event.key == pygame.K_DOWN:
|
2020-03-22 18:10:44 +01:00
|
|
|
waiter.move_down(20)
|
|
|
|
|
|
|
|
# do czego to ???
|
2020-03-22 02:01:57 +01:00
|
|
|
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
|
|
|
|
|
2020-03-22 18:10:44 +01:00
|
|
|
grid.draw_grid()
|
|
|
|
waiter.draw_waiter()
|
|
|
|
pygame.display.update()
|
|
|
|
time.sleep(0.1)
|
|
|
|
|