From d2423de7450e189750b92e17766d3fbe880e9154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Wilczy=C5=84ska?= Date: Mon, 25 Mar 2019 17:41:24 +0100 Subject: [PATCH] Added basic methods for collecting garbage --- game.py | 2 +- sprites/cell.py | 2 +- sprites/garbage_collector.py | 24 ++++++++++++++++++++++++ sprites/house.py | 5 +++++ sprites/hud.py | 2 +- sprites/landfill.py | 2 +- 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/game.py b/game.py index f692ce0..4760b50 100644 --- a/game.py +++ b/game.py @@ -64,5 +64,5 @@ while(1): hud.get_statistics(all_sprites) display.flip() - fps_clock.tick(FPS) + fps_clock.tick(FPS) ################################################################################## diff --git a/sprites/cell.py b/sprites/cell.py index fe232f0..31f73f2 100644 --- a/sprites/cell.py +++ b/sprites/cell.py @@ -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) diff --git a/sprites/garbage_collector.py b/sprites/garbage_collector.py index 229b16c..579202d 100644 --- a/sprites/garbage_collector.py +++ b/sprites/garbage_collector.py @@ -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 diff --git a/sprites/house.py b/sprites/house.py index a101078..699a579 100644 --- a/sprites/house.py +++ b/sprites/house.py @@ -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( diff --git a/sprites/hud.py b/sprites/hud.py index 1d552bc..ca2b94a 100644 --- a/sprites/hud.py +++ b/sprites/hud.py @@ -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)+" ###") diff --git a/sprites/landfill.py b/sprites/landfill.py index eb99679..e4d2262 100644 --- a/sprites/landfill.py +++ b/sprites/landfill.py @@ -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))