2019-04-10 10:31:09 +02:00
|
|
|
import pygame
|
2019-04-16 13:28:11 +02:00
|
|
|
from gridElement import GridElement
|
2019-04-10 10:31:09 +02:00
|
|
|
|
2019-04-16 13:28:11 +02:00
|
|
|
#Klasa Waiter dziedziczy z klasy GridElement ale obiekt Waiter nie należy do listy grid
|
|
|
|
class Waiter(GridElement):
|
2019-04-10 10:31:09 +02:00
|
|
|
|
2019-04-16 13:28:11 +02:00
|
|
|
def __init__(self, x, y, game):
|
|
|
|
GridElement.__init__(self, x, y, game)
|
2019-04-14 18:33:30 +02:00
|
|
|
self.image = pygame.image.load("./Images/waiter.png").convert()
|
|
|
|
self.image.set_colorkey((0, 0, 0))
|
2019-04-10 10:31:09 +02:00
|
|
|
self.type = "waiter"
|
|
|
|
|
|
|
|
def moveLeft(self, game):
|
2019-04-16 13:28:11 +02:00
|
|
|
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
|
2019-04-10 10:31:09 +02:00
|
|
|
else:
|
|
|
|
pass
|
2019-04-16 13:28:11 +02:00
|
|
|
|
2019-04-10 10:31:09 +02:00
|
|
|
def moveRight(self, game):
|
2019-04-16 13:28:11 +02:00
|
|
|
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
|
2019-04-10 10:31:09 +02:00
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def moveUp(self, game):
|
2019-04-16 13:28:11 +02:00
|
|
|
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
|
2019-04-10 10:31:09 +02:00
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def moveDown(self, game):
|
2019-04-16 13:28:11 +02:00
|
|
|
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
|
2019-04-10 10:31:09 +02:00
|
|
|
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)
|