From 96571641a27e2b109f2f8151e892389024eef584 Mon Sep 17 00:00:00 2001 From: Berger Lena Date: Fri, 8 May 2026 14:34:44 +0200 Subject: [PATCH 1/3] feat: HUD - add tower constants including cost, projectile stats, and duration - add item buying timer for shop items - add _draw_status_bar to handle dynamic HP rendering - add _format_time for MM:SS display --- src/hud.py | 23 +++++++++++++++++++++++ src/settings.py | 8 +++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/hud.py b/src/hud.py index e69de29..09e9d74 100644 --- a/src/hud.py +++ b/src/hud.py @@ -0,0 +1,23 @@ +import pygame +from src.settings import ( + HUD_FONT, HUD_FONT_SIZE, HUD_FONT_BOLD, + COLOR_HUD_TEXT, COLOR_HP_BAR_GREEN, COLOR_HP_BAR_RED, COLOR_HP_BAR_BG, + HUD_BAR_WIDTH, HUD_BAR_HEIGHT, + HUD_X_OFFSET, HUD_BAR_X, HUD_Y_DOOR, HUD_Y_ZOMBIE, HUD_Y_ECTS +) + +# draw status bar (background bar and the colored hp bar) +def _draw_status_bar(screen, x, y, current, max_val, color): + # bg bar is always the same + pygame.draw.rect(screen, COLOR_HP_BAR_BG, (x, y, HUD_BAR_WIDTH, HUD_BAR_HEIGHT)) + + # hp bar + if max_val > 0: + hp_width = (current / max_val) * HUD_BAR_WIDTH + pygame.draw.rect((screen, color), (x, y, hp_width, HUD_BAR_HEIGHT)) + +# time formatter for MM:SS +def _format_time(total_seconds): + mins = total_seconds // 60 + secs = total_seconds % 60 + return f"TIME {mins:02}:{secs:02}" diff --git a/src/settings.py b/src/settings.py index e19f541..7cf9232 100644 --- a/src/settings.py +++ b/src/settings.py @@ -30,7 +30,6 @@ DIRECTION_FRAMES: Mapping[Direction, Tuple[int, int, int]] = { # Default drawing size and animation speed. DEFAULT_SPRITE_HEIGHT: int = 138 DEFAULT_FRAME_TIME: float = 0.16 -======= # --- ECTS --- START_ECTS_VALUE = 1 # how many ECTS are generated at the beginning @@ -91,3 +90,10 @@ COLOR_HP_BAR_YELLOW = (255, 255, 0) HUD_BAR_WIDTH = 100 HUD_BAR_HEIGHT = 15 + +HUD_X_OFFSET = 20 # left startpoint for texts +HUD_BAR_X = 150 # left startpoint for hp bars + +HUD_Y_DOOR = 20 +HUD_Y_ZOMBIE = 50 +HUD_Y_ECTS = 85 From f6beb533d6a4609d3c1904cb5dcf19b11906a418 Mon Sep 17 00:00:00 2001 From: Berger Lena Date: Fri, 8 May 2026 14:48:44 +0200 Subject: [PATCH 2/3] 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 --- src/hud.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/hud.py b/src/hud.py index 09e9d74..eba708c 100644 --- a/src/hud.py +++ b/src/hud.py @@ -21,3 +21,27 @@ def _format_time(total_seconds): mins = total_seconds // 60 secs = total_seconds % 60 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)) \ No newline at end of file From bd2152ac3be62ed67211fe00a06cb0e1cdfed074 Mon Sep 17 00:00:00 2001 From: Berger Lena Date: Fri, 8 May 2026 14:34:44 +0200 Subject: [PATCH 3/3] feat: HUD - add tower constants including cost, projectile stats, and duration - add item buying timer for shop items - add _draw_status_bar to handle dynamic HP rendering - add _format_time for MM:SS display --- src/hud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hud.py b/src/hud.py index eba708c..e9c4e11 100644 --- a/src/hud.py +++ b/src/hud.py @@ -44,4 +44,4 @@ class HUD: # --- 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)) \ No newline at end of file + screen.blit(self.font.render(time_str, True, COLOR_HUD_TEXT), (screen.get_width() - 150, HUD_Y_DOOR - 5))