SZI2019SmieciarzWmi/sprites/hud.py

57 lines
2.4 KiB
Python
Raw Normal View History

2019-03-25 16:10:51 +01:00
import pygame
2019-03-25 16:19:24 +01:00
from sprites.house import House
from sprites.garbage_collector import Garbage_collector
2019-03-25 16:10:51 +01:00
from config import HUD_HEIGHT
HUD_COLOR = (51,21,4)
WHITE = (255,255,255)
class Hud():
texts = []
def __init__(self,house_amount,WINDOW_WIDTH, WINDOW_HEIGHT,GAMEWINDOW):
pygame.init()
hud_upper = WINDOW_WIDTH - HUD_HEIGHT
hud_lower = WINDOW_WIDTH
height = hud_upper - hud_lower
font_type = 'fonts/Bazgroly.ttf'
font_size = house_amount * 2
GAMEWINDOW.fill(HUD_COLOR)
font = pygame.font.Font(font_type, font_size)
gc_plastic_text = font.render("Plastic: 0/0",True,WHITE)
gc_metal_text = font.render("Metal: 0/0",True,WHITE)
gc_glass_text = font.render("Glass: 0/0",True,WHITE)
map_plastic_text = font.render("Plastic: 0",True,WHITE)
map_metal_text = font.render("Metal: 0",True,WHITE)
map_glass_text = font.render("Glass: 0",True,WHITE)
overall_text = font.render("Garbage thrown away: 0",True,WHITE)
GAMEWINDOW.blit(overall_text,(20, 20))
2019-03-25 16:19:24 +01:00
def get_statistics(self, all_sprites):
###Garbage collector stats###
gc_taken_space_plastic = 0
gc_taken_space_metal = 0
gc_taken_space_glass = 0
gc_trash_space = 10
###Board stats###############
plastic_left = 0
metal_left = 0
glass_left = 0
total_gathered = 0
for item in all_sprites:
if(type(item) == House):
rubbish = item.get_rubbish_data()
plastic_left += rubbish[0]
glass_left += rubbish[1]
metal_left += rubbish[2]
if(type(item) == Garbage_collector):
space_taken = item.get_space_data()
gc_taken_space_plastic += space_taken.get("plastic")
gc_taken_space_glass += space_taken.get("glass")
gc_taken_space_metal += space_taken.get("metal")
total_gathered += item.get_collect_data()
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)+" ###")