forked from s434673/AI_Waiter
97 lines
2.4 KiB
Python
97 lines
2.4 KiB
Python
import sys
|
|
import pygame
|
|
|
|
|
|
# WAITER
|
|
class Waiter(pygame.sprite.Sprite):
|
|
def __init__(self):
|
|
pygame.sprite.Sprite.__init__(self)
|
|
self.moveX = 0
|
|
self.moveY = 0
|
|
self.clearX = 0
|
|
self.clearY = 0
|
|
self.frame = 0
|
|
self.imageWaiter = waiter
|
|
self.imageFloor = floor
|
|
|
|
def move(self, x, y):
|
|
self.moveX += x
|
|
self.moveY -= y
|
|
|
|
def clear(self, x, y):
|
|
cx = self.moveX + x
|
|
cy = self.moveY + y
|
|
screen.blit(self.imageFloor, (cx * block_size, cy * block_size))
|
|
|
|
def update(self):
|
|
screen.blit(self.imageWaiter, (self.moveX * block_size, self.moveY * block_size))
|
|
|
|
|
|
# TILE
|
|
class Tile:
|
|
def __init__(self):
|
|
self.x_position = 0
|
|
self.y_position = 0
|
|
|
|
|
|
# SETUP
|
|
pygame.init()
|
|
screen = pygame.display.set_mode((700, 750))
|
|
done = False
|
|
block_size = 50
|
|
clock = pygame.time.Clock()
|
|
fps = 40
|
|
ani = 40
|
|
rect = 1
|
|
|
|
floor = pygame.image.load('../resources/images/floor.jpg')
|
|
table = pygame.image.load('../resources/images/table.png')
|
|
waiter = pygame.image.load('../resources/images/waiter.png')
|
|
matrix = []
|
|
|
|
|
|
def drawBackground():
|
|
for y in range(15):
|
|
for x in range(14):
|
|
screen.blit(floor, (x * block_size, y * block_size))
|
|
|
|
|
|
def matrix_creator():
|
|
for x in range(14):
|
|
matrix.append([0] * 15)
|
|
|
|
for x in range(14):
|
|
for y in range(15):
|
|
matrix[x][y] = Tile()
|
|
matrix[x][y].x_position = x
|
|
matrix[x][y].y_position = y
|
|
|
|
|
|
waiterPly = Waiter()
|
|
|
|
if __name__ == "__main__":
|
|
drawBackground()
|
|
matrix_creator()
|
|
|
|
while not done:
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
pygame.quit()
|
|
sys.exit()
|
|
if event.type == pygame.KEYDOWN:
|
|
if event.key == pygame.K_LEFT:
|
|
waiterPly.move(-rect, 0)
|
|
waiterPly.clear(rect, 0)
|
|
if event.key == pygame.K_RIGHT:
|
|
waiterPly.move(rect, 0)
|
|
waiterPly.clear(-rect, 0)
|
|
if event.key == pygame.K_UP:
|
|
waiterPly.move(0, rect)
|
|
waiterPly.clear(0, rect)
|
|
if event.key == pygame.K_DOWN:
|
|
waiterPly.move(0, -rect)
|
|
waiterPly.clear(0, -rect)
|
|
waiterPly.update()
|
|
pygame.display.flip()
|
|
clock.tick(fps)
|