#include #include #include #include namespace Game::AGame { void HUDText::start() { mZIndex = 1000; Object::UIText::start(); setText("Level 1 | Score 0 | Trash 0 | Polluters 0"); } void HUDText::update(float deltaTime) { (void)deltaTime; // Use logical world dimensions (1280×720) not actual screen size constexpr int windowW = 1280; constexpr int windowH = 720; float camX = 0.f; float camY = 0.f; Object::Camera::getInstance().getPosition(camX, camY); auto anchorTopRight = [&]() { if (!mTex) { return; } const float marginX = 24.f; const float marginY = 24.f; const float textWidth = mTex->getWidth() * mTransform.adjustedScaleX(); mTransform.x = camX + windowW / 2.f - marginX - textWidth; mTransform.y = camY - windowH / 2.f + marginY; }; if (GameManager::getSharedData("gameLost")) { if (getText() != "Umrl si!") { const std::string s = "Umrl si!"; Window::Window::postToMainThread([this, s]() { setText(s); }); } anchorTopRight(); return; } if (GameManager::getSharedData("gameWon")) { if (getText() != "Zmagal si!") { const std::string s = "Zmagal si!"; Window::Window::postToMainThread([this, s]() { setText(s); }); } anchorTopRight(); return; } const std::string playerName = GameManager::getSharedData("playerName"); std::stringstream stream; stream << "Igralec: " << (playerName.empty() ? std::string("Anonimni") : playerName) << " | Level " << GameManager::getSharedData("gameStage") << " | Točke " << GameManager::getSharedData("gameScore") << " | Smeti " << GameManager::getSharedData("trashActiveCount") << " | Sovražniki " << GameManager::getSharedData("enemyActiveCount"); const std::string newHudText = stream.str(); if (getText() != newHudText) { Window::Window::postToMainThread([this, newHudText]() { setText(newHudText); }); } anchorTopRight(); } }