2019-03-20 11:20:10 +01:00
|
|
|
import pygame
|
2019-03-25 16:00:01 +01:00
|
|
|
from sprites.cell import Cell, CELL_SIZE
|
2019-03-25 17:41:24 +01:00
|
|
|
from
|
2019-03-25 16:00:01 +01:00
|
|
|
from config import PLAY_HEIGHT, PLAY_WIDTH
|
2019-03-21 01:25:19 +01:00
|
|
|
|
2019-03-20 11:20:10 +01:00
|
|
|
class Garbage_collector(Cell):
|
2019-03-21 01:25:19 +01:00
|
|
|
def __init__(self, x, y):
|
2019-03-25 16:03:25 +01:00
|
|
|
GC_CAPACITY = 10
|
|
|
|
|
2019-03-21 01:25:19 +01:00
|
|
|
Cell.__init__(self, x, y)
|
|
|
|
self.image = pygame.image.load("images/garbage_collector.png")
|
|
|
|
self.move_options = {
|
2019-03-25 16:00:01 +01:00
|
|
|
"up": lambda forbidden: ('y', self.y - 1) if (self.x, self.y - 1) not in forbidden and self.y - 1 >= 0 else ('y', self.y),
|
|
|
|
"down": lambda forbidden: ('y', self.y + 1) if (self.x, self.y + 1) not in forbidden and self.y + 1 < PLAY_HEIGHT // CELL_SIZE else ('y', self.y),
|
|
|
|
"left": lambda forbidden: ('x', self.x - 1) if (self.x - 1, self.y) not in forbidden and self.x - 1 >= 0 else ('x', self.x),
|
|
|
|
"right": lambda forbidden: ('x', self.x + 1) if (self.x + 1, self.y) not in forbidden and self.x + 1 < PLAY_WIDTH // CELL_SIZE else ('x', self.x)
|
2019-03-21 01:25:19 +01:00
|
|
|
}
|
2019-03-25 16:03:25 +01:00
|
|
|
self.trash_space_taken = {
|
|
|
|
"plastic": 0,
|
|
|
|
"glass": 0,
|
|
|
|
"metal": 0
|
|
|
|
}
|
|
|
|
self.trash_collected = 0
|
2019-03-20 11:20:10 +01:00
|
|
|
|
2019-03-21 01:25:19 +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
|
|
|
|
self.update()
|
2019-03-25 17:41:24 +01:00
|
|
|
PLASTIC = 0 # blue
|
|
|
|
GLASS = 1 # green
|
|
|
|
METAL = 2 # yellow
|
|
|
|
def collect_trash(self, house):
|
|
|
|
rubbish = house.get_rubbish_data()
|
|
|
|
to_collect = rubbish
|
|
|
|
|
|
|
|
if(rubbish[0] > GC_CAPACITY - self.trash_space_taken.get("plastic")):
|
|
|
|
to_collect[0] = self.trash_space_taken.get("plastic")
|
|
|
|
self.trash_space_taken['plastic'] += to_collect[0]
|
|
|
|
self.trash_collected += to_collect[0]
|
|
|
|
|
|
|
|
if(rubbish[1] > GC_CAPACITY - self.trash_space_taken.get("glass")):
|
|
|
|
to_collect[1] = self.trash_space_taken.get("glass")
|
|
|
|
self.trash_space_taken['glass'] += to_collect[1]
|
|
|
|
self.trash_collected += to_collect[1]
|
|
|
|
|
|
|
|
if(rubbish[2] > GC_CAPACITY - self.trash_space_taken.get("metal")):
|
|
|
|
to_collect[2] = self.trash_space_taken.get("metal")
|
|
|
|
self.trash_space_taken['metal'] += to_collect[2]
|
|
|
|
self.trash_collected += to_collect[2]
|
|
|
|
|
|
|
|
house.give_away_rubbish(to_collect[0], to_collect[1], to_collect[2])
|
2019-03-25 16:03:25 +01:00
|
|
|
|
|
|
|
def get_collect_data(self):
|
|
|
|
return self.trash_collected
|
|
|
|
|
|
|
|
def get_space_data(self):
|
|
|
|
return self.trash_space_taken
|