SZI2019SmieciarzWmi/sprites/garbage_collector.py

24 lines
975 B
Python
Raw Normal View History

2019-03-20 11:20:10 +01:00
import pygame
from sprites.cell import Cell
2019-03-20 11:20:10 +01:00
class Garbage_collector(Cell):
def __init__(self, x, y):
Cell.__init__(self, x, y)
self.image = pygame.image.load("images/garbage_collector.png")
self.move_options = {
"up": lambda forbidden: ('y', self.y - 1) if (self.x, self.y - 1) not in forbidden else ('y', self.y),
"down": lambda forbidden: ('y', self.y + 1) if (self.x, self.y + 1) not in forbidden else ('y', self.y),
"left": lambda forbidden: ('x', self.x - 1) if (self.x - 1, self.y) not in forbidden else ('x', self.x),
"right": lambda forbidden: ('x', self.x + 1) if (self.x + 1, self.y) not in forbidden else ('x', self.x)
}
2019-03-20 11:20:10 +01:00
def move(self, direction, forbidden):
(destination, value) = self.move_options[direction](forbidden)
if(destination is 'x'):
self.x = value
elif(destination is 'y'):
self.y = value
2019-03-20 11:20:10 +01:00
self.update()