1
0
forked from s444417/ProjektAI
ProjektAI/kelner/main.py

106 lines
2.6 KiB
Python

import pygame
import time
# initialize the pygame
pygame.init()
# initiate variables
screen = pygame.display.set_mode((1000,1000))
pygame.display.set_caption("Bardzo mądry kelner")
# Grid variables
gridImg = pygame.image.load("20x20grid.png")
gridX = 0
gridY = 0
# Waiter variables
waiterImg = pygame.image.load("waiter.png")
waiterX = 10
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
waiterX_change = 0
waiterY_change = 0
grid = Grid(gridX, gridY, gridImg)
waiter = Waiter(waiterX, waiterY, waiterImg)
# loop
running = True
while running:
# RGB
screen.fill((255, 255, 255))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# TODO: switch case
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
waiter.move_left(20)
if event.key == pygame.K_RIGHT:
waiter.move_right(20)
if event.key == pygame.K_UP:
waiter.move_up(20)
if event.key == pygame.K_DOWN:
waiter.move_down(20)
# do czego to ???
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.draw_grid()
waiter.draw_waiter()
pygame.display.update()
time.sleep(0.1)