Added basic methods for collecting garbage
This commit is contained in:
parent
84d375e5dd
commit
d2423de745
2
game.py
2
game.py
@ -64,5 +64,5 @@ while(1):
|
|||||||
|
|
||||||
hud.get_statistics(all_sprites)
|
hud.get_statistics(all_sprites)
|
||||||
display.flip()
|
display.flip()
|
||||||
fps_clock.tick(FPS)
|
fps_clock.tick(FPS)
|
||||||
##################################################################################
|
##################################################################################
|
||||||
|
@ -15,4 +15,4 @@ class Cell(pygame.sprite.Sprite):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.rect = pygame.Rect(
|
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)
|
||||||
|
@ -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
|
||||||
|
@ -44,6 +44,11 @@ class House(Cell):
|
|||||||
self.image = pygame.image.load(House_image.glass.value) #szklo
|
self.image = pygame.image.load(House_image.glass.value) #szklo
|
||||||
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(
|
||||||
|
@ -53,4 +53,4 @@ class Hud():
|
|||||||
|
|
||||||
print("plastic left: "+str(plastic_left)+" | glass left: "+str(glass_left)+" | metal left: "+str(metal_left))
|
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(" 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)+" ###")
|
||||||
|
@ -8,4 +8,4 @@ class Landfill(Cell):
|
|||||||
Cell.__init__(self, x, y)
|
Cell.__init__(self, x, y)
|
||||||
types = ["plastic", "glass", "metal"]
|
types = ["plastic", "glass", "metal"]
|
||||||
self.type = types[type]
|
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))
|
||||||
|
Loading…
Reference in New Issue
Block a user