Sztuczna_Inteligencja_2020/main.py
2020-04-03 16:32:24 +02:00

109 lines
2.7 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, x_position, y_position):
self.x_position = x_position
self.y_position = y_position
self.watch_through = 1
self.walk_through = 1
self.action_required = 0
# TABLE
class Table(Tile):
def __init__(self, x_position, y_position):
super().__init__(x_position, y_position)
self.walk_through = 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(x, 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)
# # Testy funkcjonalne
# matrix[0][0] = Table(0, 0)
# print(matrix[0][0].walk_through, matrix[1][0].walk_through)