2019-03-19 23:36:06 +01:00
|
|
|
import pygame
|
|
|
|
from pygame.math import Vector2
|
|
|
|
|
|
|
|
class Waiter(object):
|
|
|
|
|
2019-03-20 23:46:50 +01:00
|
|
|
def __init__(self, game, x, y):
|
2019-03-19 23:36:06 +01:00
|
|
|
self.game = game
|
2019-03-20 23:46:50 +01:00
|
|
|
game.idItem += 1
|
2019-03-19 23:36:06 +01:00
|
|
|
self.size= self.game.screen.get_size()
|
2019-03-20 23:46:50 +01:00
|
|
|
self.x = x
|
|
|
|
self.y = y
|
2019-03-19 23:36:06 +01:00
|
|
|
self.image = pygame.image.load("./Images/w1.png").convert()
|
|
|
|
self.image.set_colorkey((255, 255, 255))
|
2019-03-20 23:46:50 +01:00
|
|
|
self.type = "waiter"
|
|
|
|
self.numberInGrid = game.idItem
|
2019-03-19 23:36:06 +01:00
|
|
|
|
2019-03-24 19:57:16 +01:00
|
|
|
def moveLeft(self, game):
|
|
|
|
if int(game.waiterNumberInGrid.x) != 0:
|
|
|
|
collisionObject = game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x-1)]
|
|
|
|
if collisionObject.type == "gridElement":
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x - 1)].x += 50
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)].x -= 50
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x - 1)], \
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)] = \
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)], \
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x-1)]
|
|
|
|
game.waiterNumberInGrid.x -= 1
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
def moveRight(self, game):
|
|
|
|
if int(game.waiterNumberInGrid.x) != 19:
|
|
|
|
collisionObject = game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x + 1)]
|
|
|
|
if collisionObject.type == "gridElement":
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x + 1)].x -= 50
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)].x += 50
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x + 1)], \
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)] = \
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)], \
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x + 1)]
|
|
|
|
game.waiterNumberInGrid.x += 1
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def moveUp(self, game):
|
|
|
|
if int(game.waiterNumberInGrid.y) != 0:
|
|
|
|
collisionObject = game.grid[int(game.waiterNumberInGrid.y-1)][int(game.waiterNumberInGrid.x)]
|
|
|
|
if collisionObject.type == "gridElement":
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y-1)][int(game.waiterNumberInGrid.x)].y += 50
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)].y -= 50
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y-1)][int(game.waiterNumberInGrid.x)], \
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)] = \
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)], \
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y-1)][int(game.waiterNumberInGrid.x)]
|
|
|
|
game.waiterNumberInGrid.y -= 1
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def moveDown(self, game):
|
|
|
|
if int(game.waiterNumberInGrid.y) != 17:
|
|
|
|
collisionObject = game.grid[int(game.waiterNumberInGrid.y + 1)][int(game.waiterNumberInGrid.x)]
|
|
|
|
if collisionObject.type == "gridElement":
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y + 1)][int(game.waiterNumberInGrid.x)].y -= 50
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)].y += 50
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y + 1)][int(game.waiterNumberInGrid.x)], \
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)] = \
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y)][int(game.waiterNumberInGrid.x)], \
|
|
|
|
game.grid[int(game.waiterNumberInGrid.y + 1)][int(game.waiterNumberInGrid.x)]
|
|
|
|
game.waiterNumberInGrid.y += 1
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
2019-03-19 23:36:06 +01:00
|
|
|
|
|
|
|
|
2019-03-20 23:46:50 +01:00
|
|
|
def move(self, game):
|
2019-03-19 23:36:06 +01:00
|
|
|
keys = pygame.key.get_pressed()
|
2019-03-20 23:46:50 +01:00
|
|
|
|
2019-03-24 19:57:16 +01:00
|
|
|
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)
|
2019-03-19 23:36:06 +01:00
|
|
|
|
|
|
|
def draw(self):
|
2019-03-20 23:46:50 +01:00
|
|
|
self.rect1 = pygame.Rect(self.x, self.y, 50, 50)
|
2019-03-20 20:42:55 +01:00
|
|
|
pygame.draw.rect(self.game.screen, (0, 150, 255), self.rect1)
|
2019-03-20 23:46:50 +01:00
|
|
|
self.game.screen.blit(self.image, (self.x-50, self.y))
|