1
0
forked from s434673/AI_Waiter

Matrix implemented to waiter

This commit is contained in:
s444427 2020-04-03 20:15:07 +02:00
parent b06e382322
commit 431dadacbc
4 changed files with 24 additions and 27 deletions

18
main.py
View File

@ -3,23 +3,17 @@ from src.graphics import *
from src.matrix import Matrix from src.matrix import Matrix
from src.waiter import Waiter from src.waiter import Waiter
if __name__ == "__main__": if __name__ == "__main__":
# SETUP # SETUP
pygame.init() pygame.init()
clock = pygame.time.Clock() clock = pygame.time.Clock()
fps = 40 fps = 40
# matrix = [] waiter = Waiter()
waiterPly = Waiter()
graphics = Graphics() graphics = Graphics()
# init functions # init functions
graphics.drawBackground() graphics.drawBackground(waiter.matrix)
graphics.update(waiterPly.moveX, waiterPly.moveY) graphics.update(waiter.X, waiter.Y)
# matrix_creator()
matrix = Matrix()
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
@ -34,8 +28,8 @@ if __name__ == "__main__":
sys.exit() sys.exit()
break break
graphics.clear(waiterPly.moveX, waiterPly.moveY) graphics.clear(waiter.X, waiter.Y)
waiterPly.update(event) waiter.update(event)
graphics.update(waiterPly.moveX, waiterPly.moveY) graphics.update(waiter.X, waiter.Y)
pygame.display.flip() pygame.display.flip()
clock.tick(fps) clock.tick(fps)

View File

@ -11,10 +11,10 @@ class Graphics:
self.screen = pygame.display.set_mode((700, 750)) self.screen = pygame.display.set_mode((700, 750))
self.block_size = 50 self.block_size = 50
def drawBackground(self): def drawBackground(self, matrix):
for y in range(15): for y in range(15):
for x in range(14): for x in range(14):
self.screen.blit(self.image['floor'], (x * self.block_size, y * self.block_size)) self.screen.blit(self.image[matrix.get_type(x, y)], (x * self.block_size, y * self.block_size))
def clear(self, x, y): def clear(self, x, y):
self.screen.blit(self.image['floor'], (x * self.block_size, y * self.block_size)) self.screen.blit(self.image['floor'], (x * self.block_size, y * self.block_size))

View File

@ -10,6 +10,11 @@ class Matrix:
for x in range(14): for x in range(14):
for y in range(15): for y in range(15):
self.matrix[x][y] = Tile(type_='floor', watch_through=1) self.matrix[x][y] = Tile(type_='floor', watch_through=1)
self.matrix[1][0].type = 'waiter'
self.matrix[1][0].walk_through = 0
def get_name(self, x, y): def get_type(self, x, y):
return self.matrix[x][y].type return self.matrix[x][y].type
def walk_through(self, x, y):
return self.matrix[x][y].walk_through

View File

@ -1,25 +1,23 @@
import pygame import pygame
from src.matrix import Matrix
screen = pygame.display.set_mode((700, 750))
block_size = 50
# WAITER # WAITER
class Waiter(pygame.sprite.Sprite): class Waiter(pygame.sprite.Sprite):
def __init__(self): def __init__(self):
pygame.sprite.Sprite.__init__(self) pygame.sprite.Sprite.__init__(self)
self.moveX = 0 self.X = 0
self.moveY = 0 self.Y = 0
self.clearX = 0
self.clearY = 0
self.frame = 0 self.frame = 0
self.matrix = Matrix()
#Borders # Borders
def move(self, x, y): def move(self, x, y):
if 0 <= self.moveX + x <= 14: if self.matrix.walk_through(self.X + x, self.Y + y) == 1:
self.moveX += x if 0 <= self.X + x <= 14:
if 0 <= self.moveY + y <= 15: self.X += x
self.moveY += y if 0 <= self.Y + y <= 15:
self.Y += y
def update(self, event): def update(self, event):
if event.type == pygame.KEYDOWN: if event.type == pygame.KEYDOWN: