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 class Waiter(GridElement): def __init__(self, x, y, game): GridElement.__init__(self, x, y, game) self.image = pygame.image.load("./Images/waiter.png").convert() self.image.set_colorkey((0, 0, 0)) self.type = "waiter" #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]: 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]: 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]: 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]: 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)