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
This commit is contained in:
+23
@@ -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}"
|
||||||
|
|||||||
+7
-1
@@ -30,7 +30,6 @@ DIRECTION_FRAMES: Mapping[Direction, Tuple[int, int, int]] = {
|
|||||||
# Default drawing size and animation speed.
|
# Default drawing size and animation speed.
|
||||||
DEFAULT_SPRITE_HEIGHT: int = 138
|
DEFAULT_SPRITE_HEIGHT: int = 138
|
||||||
DEFAULT_FRAME_TIME: float = 0.16
|
DEFAULT_FRAME_TIME: float = 0.16
|
||||||
=======
|
|
||||||
|
|
||||||
# --- ECTS ---
|
# --- ECTS ---
|
||||||
START_ECTS_VALUE = 1 # how many ECTS are generated at the beginning
|
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_WIDTH = 100
|
||||||
HUD_BAR_HEIGHT = 15
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user