nodes/npc.pyΒΆ
Part of GDQuest Open RPG.
1"""NPC: stationary or patrolling sprite with a dialogue id."""
2
3from __future__ import annotations
4
5import math
6
7from simvx.core import Sprite2D
8from simvx.core.math.types import Vec2
9
10from . import sprites as art
11from .gameboard import cell_to_pixel
12from .settings import TILE
13
14
15def _sprite_for_kind(kind: str):
16 if kind == "monk":
17 return art.wizard_sprite()
18 if kind == "smith":
19 return art.knight_sprite()
20 if kind == "wizard_npc":
21 return art.wizard_sprite()
22 return art.knight_sprite()
23
24
25class NPC(Sprite2D):
26 def __init__(self, cell: tuple[int, int], kind: str, dialogue_id: str) -> None:
27 super().__init__(texture=_sprite_for_kind(kind))
28 self.filter = "nearest"
29 self.width = TILE
30 self.height = TILE
31 self.cell = tuple(cell)
32 x, y = cell_to_pixel(*cell)
33 self.position = Vec2(x, y)
34 self.kind = kind
35 self.dialogue_id = dialogue_id
36 # Subtle bob
37 self._bob_t = 0.0
38
39 def on_update(self, dt: float) -> None:
40 # Tiny vertical bob for visual life
41 self._bob_t += dt
42 bob = math.sin(self._bob_t * 2.0) * 1.2
43 x, y = cell_to_pixel(*self.cell)
44 self.position = Vec2(x, y + bob)