Add velocity HUD display (Velocity: 0) in top-left corner

This commit is contained in:
vottozi 2026-02-06 18:04:33 +06:00
parent a1d54b01b0
commit aa9590e2f4
3 changed files with 20 additions and 4 deletions

View File

@ -163,7 +163,19 @@
"hover": "resources/shoot_hover.png",
"pressed": "resources/shoot_pressed.png"
}
}
},
{
"type": "TextView",
"name": "velocityText",
"x": 10,
"y": 10,
"width": 200,
"height": 40,
"text": "Velocity: 0",
"fontSize": 24,
"color": [1.0, 1.0, 1.0, 1.0],
"centered": false
}
]
}
}

View File

@ -1216,8 +1216,13 @@ namespace ZL
}
// update velocity text
std::string velocityStr = "Velocity: " + std::to_string(static_cast<int>(Environment::shipState.velocity));
uiManager.setText("velocityText", velocityStr);
if (shipAlive && !gameOver) {
auto velocityTv = uiManager.findTextView("velocityText");
if (velocityTv) {
std::string velocityStr = "Velocity: " + std::to_string(static_cast<int>(Environment::shipState.velocity));
uiManager.setText("velocityText", velocityStr);
}
}
uiManager.update(static_cast<float>(delta));
lastTickCount = newTickCount;

View File

@ -903,7 +903,6 @@ namespace ZL {
bool UiManager::setText(const std::string& name, const std::string& newText) {
auto tv = findTextView(name);
if (!tv) {
std::cerr << "TextView not found: " << name << std::endl;
return false;
}
tv->text = newText;