nodes/hud.pyΒΆ
Part of Clumsy Bird.
1"""Score HUD: anchored Label that displays the current score."""
2
3from simvx.core import Vec2
4from simvx.core.ui import AnchorPreset, Control, Label
5
6
7class ScoreHUD(Control):
8 """Big centred score readout, anchored to the top-centre of the viewport."""
9
10 def __init__(self, **kwargs):
11 super().__init__(**kwargs)
12 self.set_anchor_preset(AnchorPreset.TOP_WIDE)
13 self.size = Vec2(0, 100) # width is anchored full-width
14
15 self.label = self.add_child(Label("0", name="ScoreLabel"))
16 self.label.set_anchor_preset(AnchorPreset.FULL_RECT)
17 self.label.font_size = 64
18 self.label.alignment = "center"
19 self.label.text_colour = (1.0, 1.0, 1.0, 1.0)
20 self.label.margin_top = 18
21
22 def set_score(self, score: int):
23 self.label.text = str(score)