Added basic methods for collecting garbage

This commit is contained in:
Magdalena Wilczyńska 2019-03-25 17:41:24 +01:00
parent 84d375e5dd
commit d2423de745
6 changed files with 33 additions and 4 deletions

View File

@ -64,5 +64,5 @@ while(1):
hud.get_statistics(all_sprites)
display.flip()
fps_clock.tick(FPS)
fps_clock.tick(FPS)
##################################################################################

View File

@ -15,4 +15,4 @@ class Cell(pygame.sprite.Sprite):
def update(self):
self.rect = pygame.Rect(
self.x*CELL_SIZE, self.y*CELL_SIZE, CELL_SIZE, CELL_SIZE)
self.x*CELL_SIZE, self.y*CELL_SIZE, CELL_SIZE, CELL_SIZE)

View File

@ -1,5 +1,6 @@
import pygame
from sprites.cell import Cell, CELL_SIZE
from
from config import PLAY_HEIGHT, PLAY_WIDTH
class Garbage_collector(Cell):
@ -28,6 +29,29 @@ class Garbage_collector(Cell):
elif(destination is 'y'):
self.y = value
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):
return self.trash_collected

View File

@ -44,6 +44,11 @@ class House(Cell):
self.image = pygame.image.load(House_image.glass.value) #szklo
elif(self.rubbish[METAL] > self.max_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):
print("plastic: " + str(self.rubbish[PLASTIC]) + " glass: " + str(

View File

@ -53,4 +53,4 @@ class Hud():
print("plastic left: "+str(plastic_left)+" | glass left: "+str(glass_left)+" | metal left: "+str(metal_left))
print(" plastic: "+str(gc_taken_space_plastic)+"/"+str(gc_trash_space)+" | glass: "+str(gc_taken_space_glass)+"/"+str(gc_trash_space)+" | metal: "+str(gc_taken_space_metal)+"/"+str(gc_trash_space))
print("### TOTAL COLLECTED: "+str(total_gathered)+" ###")
print("### TOTAL COLLECTED: "+str(total_gathered)+" ###")

View File

@ -8,4 +8,4 @@ class Landfill(Cell):
Cell.__init__(self, x, y)
types = ["plastic", "glass", "metal"]
self.type = types[type]
self.image = pygame.image.load("images/landfill_%s.png" % (self.type))
self.image = pygame.image.load("images/landfill_%s.png" % (self.type))