import pygame from pygame.math import Vector2 class Waiter(object): def __init__(self, game, x, y): self.game = game game.idItem += 1 self.size= self.game.screen.get_size() self.x = x self.y = y self.image = pygame.image.load("./Images/w1.png").convert() self.image.set_colorkey((255, 255, 255)) self.type = "waiter" # System kolizji bazujÄ…cy a obiektach # Zwracanie grida po wykonaniu ruchu 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) != 11: 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) != 11: 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 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) def draw(self): self.rect1 = pygame.Rect(self.x, self.y, 50, 50) pygame.draw.rect(self.game.screen, (0, 150, 255), self.rect1) self.game.screen.blit(self.image, (self.x-50, self.y))