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 self._screen_w, self._screen_h = self.viewport_size
26
27 bar_w = self._screen_w * 0.6
28 bar_h = 20
29 bar_x = (self._screen_w - bar_w) / 2
30 bar_y = self._screen_h - 60
31
32 # Background
33 renderer.rect((bar_x, bar_y), (bar_w, bar_h), fill=(0.2, 0.0, 0.0, 0.9))
34 # Fill
35 ratio = max(0, self._boss.hp / max(1, self._boss.max_hp))
36 renderer.rect((bar_x, bar_y), (bar_w * ratio, bar_h), fill=(0.9, 0.1, 0.1, 0.9))
37 # Name
38 name = getattr(self._boss, "display_name", "Boss")
39 renderer.text(name, (bar_x, bar_y - 20), fill=(1.0, 0.3, 0.3, 1.0), scale=1.3)