import pygame 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" 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 def move(self, game): keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: self.moveLeft(game) if keys[pygame.K_RIGHT]: self.moveRight(game) if keys[pygame.K_UP]: self.moveUp(game) if keys[pygame.K_DOWN]: self.moveDown(game) if keys[pygame.K_s]: game.showGrid(game.grid)