Added basic methods for collecting garbage
This commit is contained in:
parent
84d375e5dd
commit
d2423de745
@ -1,5 +1,6 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from sprites.cell import Cell, CELL_SIZE
|
from sprites.cell import Cell, CELL_SIZE
|
||||||
|
from
|
||||||
from config import PLAY_HEIGHT, PLAY_WIDTH
|
from config import PLAY_HEIGHT, PLAY_WIDTH
|
||||||
|
|
||||||
class Garbage_collector(Cell):
|
class Garbage_collector(Cell):
|
||||||
@ -28,6 +29,29 @@ class Garbage_collector(Cell):
|
|||||||
elif(destination is 'y'):
|
elif(destination is 'y'):
|
||||||
self.y = value
|
self.y = value
|
||||||
self.update()
|
self.update()
|
||||||
|
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])
|
||||||
|
|
||||||
def get_collect_data(self):
|
def get_collect_data(self):
|
||||||
return self.trash_collected
|
return self.trash_collected
|
||||||
|
@ -45,6 +45,11 @@ class House(Cell):
|
|||||||
elif(self.rubbish[METAL] > self.max_metal):
|
elif(self.rubbish[METAL] > self.max_metal):
|
||||||
self.image = pygame.image.load(House_image.metal.value) #metal
|
self.image = pygame.image.load(House_image.metal.value) #metal
|
||||||
|
|
||||||
|
def give_away_rubbish(self, plastic, glass, metal):
|
||||||
|
self.rubbish[PLASTIC] -= plastic
|
||||||
|
self.rubbish[GLASS] -= glass
|
||||||
|
self.rubbish[METAL] -= metal
|
||||||
|
|
||||||
def check_rubbish_status(self):
|
def check_rubbish_status(self):
|
||||||
print("plastic: " + str(self.rubbish[PLASTIC]) + " glass: " + str(
|
print("plastic: " + str(self.rubbish[PLASTIC]) + " glass: " + str(
|
||||||
self.rubbish[GLASS]) + " metal: " + str(self.rubbish[METAL]))
|
self.rubbish[GLASS]) + " metal: " + str(self.rubbish[METAL]))
|
||||||
|
Loading…
Reference in New Issue
Block a user