diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 160c6ab..728c259 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,15 +2,9 @@ - - - - - - @@ -494,23 +488,11 @@ - + - - - - - - - - - - - - - - - + + + @@ -534,28 +516,40 @@ - + - - + + - + - - - + + + + + + + + + + + + + + + - - + + @@ -564,8 +558,8 @@ - - + + diff --git a/__pycache__/gridElement.cpython-36.pyc b/__pycache__/gridElement.cpython-36.pyc index 97ec230..e4d17c4 100644 Binary files a/__pycache__/gridElement.cpython-36.pyc and b/__pycache__/gridElement.cpython-36.pyc differ diff --git a/__pycache__/waiter.cpython-36.pyc b/__pycache__/waiter.cpython-36.pyc index 7e92afb..0dec3a5 100644 Binary files a/__pycache__/waiter.cpython-36.pyc and b/__pycache__/waiter.cpython-36.pyc differ diff --git a/game.py b/game.py index 96b6601..af3dba8 100644 --- a/game.py +++ b/game.py @@ -19,7 +19,8 @@ class Game(object): self.idOrder = 0 self.idItem = -1 self.idOrderTable = 0 - self.waiter = Waiter(5, 0, self) #Waiter jest atrybutem klasy Game + self.waiter = Waiter(5, 0, self) #Waiter jest atrybutem klasy Game i nie ma go w gridzie + self.waiterMovesHistory = [] pygame.display.set_caption('Automatic Waiter') self.background = pygame.image.load("./Images/tlo.jpg") diff --git a/gridElement.py b/gridElement.py index 2886e2d..3094dcf 100644 --- a/gridElement.py +++ b/gridElement.py @@ -11,7 +11,7 @@ class GridElement(object): game.idItem += 1 self.number = game.idItem - #Cała matematyka rysowania odbywa się tutaj + #Cała matematyka skalowania odbywa się tutaj def draw(self): self.rect = pygame.Rect(self.position.x * self.game.gridElementWidth, self.position.y * self.game.gridElementHeight, self.game.gridElementWidth, self.game.gridElementHeight) self.game.screen.blit(self.image, (self.position.x * self.game.gridElementWidth, self.position.y * self.game.gridElementHeight)) \ No newline at end of file diff --git a/waiter.py b/waiter.py index 4945f9c..8268099 100644 --- a/waiter.py +++ b/waiter.py @@ -1,4 +1,5 @@ import pygame +from pygame.math import Vector2 from gridElement import GridElement #Klasa Waiter dziedziczy z klasy GridElement ale obiekt Waiter nie należy do listy grid @@ -10,48 +11,43 @@ class Waiter(GridElement): self.image.set_colorkey((0, 0, 0)) self.type = "waiter" - def moveLeft(self, game): - if int(self.position.x) != 0: - collisionObject = game.grid[int(self.position.y)][int(self.position.x) - 1] - if collisionObject.type == "path": - self.position.x -= 1 - else: - pass - - def moveRight(self, game): - if int(self.position.x) != game.x - 1: - collisionObject = game.grid[int(self.position.y)][int(self.position.x) + 1] - if collisionObject.type == "path": - self.position.x += 1 - else: - pass - - def moveUp(self, game): - if int(self.position.y) != 0: - collisionObject = game.grid[int(self.position.y) - 1][int(self.position.x)] - if collisionObject.type == "path": - self.position.y -= 1 - else: - pass - - def moveDown(self, game): - if int(self.position.y) != game.y - 1: - collisionObject = game.grid[int(self.position.y) + 1][int(self.position.x)] - if collisionObject.type == "path": - self.position.y += 1 - else: - pass - + #Waiter może wejść tylko na pole które znajduje się na gridzie i ma atrybut type równy "path" + #metoda move dodaje poprzednią pozycję waitera do listy waiterMovesHistory + #aktualna pozycja waitara jest w obiekcie position typu Vector2 (dziedziczonym z GridElement) def move(self, game): keys = pygame.key.get_pressed() + lastPosition = Vector2(self.position.x, self.position.y) if keys[pygame.K_LEFT]: - self.moveLeft(game) + if int(self.position.x) != 0: + collisionObject = game.grid[int(self.position.y)][int(self.position.x) - 1] + if collisionObject.type == "path": + self.position.x -= 1 + else: + pass if keys[pygame.K_RIGHT]: - self.moveRight(game) + if int(self.position.x) != game.x - 1: + collisionObject = game.grid[int(self.position.y)][int(self.position.x) + 1] + if collisionObject.type == "path": + self.position.x += 1 + else: + pass if keys[pygame.K_UP]: - self.moveUp(game) + if int(self.position.y) != 0: + collisionObject = game.grid[int(self.position.y) - 1][int(self.position.x)] + if collisionObject.type == "path": + self.position.y -= 1 + else: + pass if keys[pygame.K_DOWN]: - self.moveDown(game) + if int(self.position.y) != game.y - 1: + collisionObject = game.grid[int(self.position.y) + 1][int(self.position.x)] + if collisionObject.type == "path": + self.position.y += 1 + else: + pass if keys[pygame.K_s]: game.showGrid(game.grid) + if(lastPosition.x != self.position.x or lastPosition.y != self.position.y): + game.waiterMovesHistory.append(lastPosition) + print(game.waiterMovesHistory)