nodes/loot_drop.pyΒΆ

Part of Dungeon Explorer.

 1"""Floating loot notification: coloured text that drifts upward and fades."""
 2
 3from simvx.core import Node2D, Vec2
 4
 5
 6class LootDrop(Node2D):
 7    """Floating pickup notification text."""
 8
 9    # Transient effect: spawned and auto-destroyed during play. Never persisted
10    # so a save taken while one is on screen can be re-applied cleanly.
11    __save_persist__ = False
12
13    def __init__(self, text: str, colour: tuple = (1.0, 1.0, 1.0, 1.0), **kwargs):
14        super().__init__(**kwargs)
15        self._text = text
16        self._colour = colour
17        self._timer = 0.0
18        self._duration = 1.2
19
20    def on_update(self, dt: float):
21        self._timer += dt
22        self.position = Vec2(self.position.x, self.position.y - 25 * dt)
23        if self._timer >= self._duration:
24            self.destroy()
25
26    def on_draw(self, renderer):
27        alpha = max(0.0, 1.0 - self._timer / self._duration)
28        c = self._colour
29        renderer.draw_text(self._text, (self.position.x, self.position.y), scale=0.9, colour=(c[0], c[1], c[2], alpha))