feat: HUD
- add HUD class with font initialization - add status bars for doors and zombie hp - add ECTS balance and generation rate display - add game timer
This commit is contained in:
+24
@@ -21,3 +21,27 @@ def _format_time(total_seconds):
|
|||||||
mins = total_seconds // 60
|
mins = total_seconds // 60
|
||||||
secs = total_seconds % 60
|
secs = total_seconds % 60
|
||||||
return f"TIME {mins:02}:{secs:02}"
|
return f"TIME {mins:02}:{secs:02}"
|
||||||
|
|
||||||
|
|
||||||
|
class HUD:
|
||||||
|
def __init__(self):
|
||||||
|
self.font = pygame.font.SysFont(HUD_FONT, HUD_FONT_SIZE, bold=HUD_FONT_BOLD)
|
||||||
|
|
||||||
|
def draw(self, screen, door, zombie, ects, total_time):
|
||||||
|
# --- DOOR HP ---
|
||||||
|
_draw_status_bar(screen, HUD_BAR_X, HUD_Y_DOOR, door.current_hp, COLOR_HP_BAR_GREEN)
|
||||||
|
# -5 px, small off-set to align the text better with hp bar
|
||||||
|
screen.blit(self.font.render("DOOR HP ", True, COLOR_HUD_TEXT), (HUD_X_OFFSET, HUD_Y_DOOR - 5))
|
||||||
|
|
||||||
|
# --- ZOMBIE HP ---
|
||||||
|
if zombie:
|
||||||
|
_draw_status_bar(screen, HUD_BAR_X, HUD_Y_ZOMBIE, zombie.current_hp, zombie.max_hp, COLOR_HP_BAR_RED)
|
||||||
|
screen.blit(self.font.render("Zombie HP:", True, COLOR_HUD_TEXT), (HUD_X_OFFSET, HUD_Y_ZOMBIE - 5))
|
||||||
|
|
||||||
|
# --- ECTS ---
|
||||||
|
ects_info = f"ECTS: {ects.ects_balance} ({ects.ects_per_second}/s)"
|
||||||
|
screen.blit(self.font.render(ects_info, True, COLOR_HUD_TEXT), (HUD_X_OFFSET, HUD_Y_ECTS))
|
||||||
|
|
||||||
|
# --- TIME ---
|
||||||
|
time_str = _format_time(total_time)
|
||||||
|
screen.blit(self.font.render(time_str, True, COLOR_HUD_TEXT), (screen.get_width() - 150, HUD_Y_DOOR - 5))
|
||||||
Reference in New Issue
Block a user