nodes/boss_health_bar.pyΒΆ

Part of Dungeon Explorer.

 1"""Boss HP bar overlay: displayed during boss encounters."""
 2
 3from simvx.core import Node2D
 4
 5
 6class BossHealthBar(Node2D):
 7    """Full-width boss health bar at the bottom of the screen."""
 8
 9    # Transient: created when a boss spawns, destroyed when it dies / on reload.
10    __save_persist__ = False
11
12    def __init__(self, **kwargs):
13        super().__init__(name="BossHealthBar", **kwargs)
14        self._boss = None
15        self._screen_w = 1280
16        self._screen_h = 720
17
18    def setup(self, boss, screen_size=(1280, 720)):
19        self._boss = boss
20        self._screen_w, self._screen_h = screen_size
21
22    def on_draw(self, renderer):
23        if self._boss is None or self._boss.hp <= 0:
24            return
25        if self.tree:
26            self._screen_w, self._screen_h = self.tree.screen_size
27
28        bar_w = self._screen_w * 0.6
29        bar_h = 20
30        bar_x = (self._screen_w - bar_w) / 2
31        bar_y = self._screen_h - 60
32
33        # Background
34        renderer.draw_rect((bar_x, bar_y), (bar_w, bar_h), colour=(0.2, 0.0, 0.0, 0.9), filled=True)
35        # Fill
36        ratio = max(0, self._boss.hp / max(1, self._boss.max_hp))
37        renderer.draw_rect((bar_x, bar_y), (bar_w * ratio, bar_h), colour=(0.9, 0.1, 0.1, 0.9), filled=True)
38        # Name
39        name = getattr(self._boss, "display_name", "Boss")
40        renderer.draw_text(name, (bar_x, bar_y - 20), scale=1.3, colour=(1.0, 0.3, 0.3, 1.0))