From 5ba562178ba7b3e2977c0fa1ce7a65aff89c770d Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 29 May 2026 21:06:29 +0200 Subject: [PATCH] tweak(hud): el bloc d'un jugador inactiu es deixa apagat (sense dibuixar, reservant l'ample) --- source/game/scenes/game_scene.cpp | 2 ++ source/game/systems/init_hud_animator.cpp | 10 ++++++++-- source/game/systems/init_hud_animator.hpp | 10 ++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/source/game/scenes/game_scene.cpp b/source/game/scenes/game_scene.cpp index bd09ba0..b07061f 100644 --- a/source/game/scenes/game_scene.cpp +++ b/source/game/scenes/game_scene.cpp @@ -945,6 +945,8 @@ auto GameScene::buildScoreboardData() const -> Systems::InitHud::ScoreboardData return std::string(6 - std::min(6, static_cast(S.length())), '0') + S; }; + out.p1_active = match_config_.player1_active; + out.p2_active = match_config_.player2_active; out.score_p1 = match_config_.player1_active ? FORMAT_SCORE(score_per_player_[0]) : "000000"; out.lives_p1 = match_config_.player1_active ? lives_per_player_[0] : 0; out.score_p2 = match_config_.player2_active ? FORMAT_SCORE(score_per_player_[1]) : "000000"; diff --git a/source/game/systems/init_hud_animator.cpp b/source/game/systems/init_hud_animator.cpp index 01a56f2..3a9b8c7 100644 --- a/source/game/systems/init_hud_animator.cpp +++ b/source/game/systems/init_hud_animator.cpp @@ -208,12 +208,18 @@ namespace Systems::InitHud { const std::shared_ptr& shape, const std::string& score, int lives, + bool active, SDL_Color bright, SDL_Color dim, float x_left, float center_y, float scale, float spacing) { + // Jugador inactiu → bloc apagat: no es dibuixa res (es reserva l'ample + // igualment a drawScoreboardAt perquè NIVELL i el bloc actiu no es moguin). + if (!active) { + return; + } const float TOP_Y = center_y - (Graphics::VectorText::getTextHeight(scale) / 2.0F); const float W_SCORE = Graphics::VectorText::getTextWidth(score, scale, spacing); @@ -260,12 +266,12 @@ namespace Systems::InitHud { const float TOTAL = BLOCK_W + GAP + W_LEVEL + GAP + BLOCK_W; float x = (Defaults::Game::WIDTH / 2.0F) - (TOTAL / 2.0F); - drawPlayerBlock(renderer, text, data.shape_p1, data.score_p1, data.lives_p1, Defaults::Hud::Colors::P1_BRIGHT, Defaults::Hud::Colors::P1_DIM, x, center_y, scale, spacing); + drawPlayerBlock(renderer, text, data.shape_p1, data.score_p1, data.lives_p1, data.p1_active, Defaults::Hud::Colors::P1_BRIGHT, Defaults::Hud::Colors::P1_DIM, x, center_y, scale, spacing); x += BLOCK_W + GAP; // NIVELL: drawLevel centra a WIDTH/2, que coincideix amb aquest tram. drawLevel(text, data.level_label, data.level_value, TOP_Y, scale, spacing); x += W_LEVEL + GAP; - drawPlayerBlock(renderer, text, data.shape_p2, data.score_p2, data.lives_p2, Defaults::Hud::Colors::P2_BRIGHT, Defaults::Hud::Colors::P2_DIM, x, center_y, scale, spacing); + drawPlayerBlock(renderer, text, data.shape_p2, data.score_p2, data.lives_p2, data.p2_active, Defaults::Hud::Colors::P2_BRIGHT, Defaults::Hud::Colors::P2_DIM, x, center_y, scale, spacing); } void drawScoreboardAnimated(Rendering::Renderer* renderer, diff --git a/source/game/systems/init_hud_animator.hpp b/source/game/systems/init_hud_animator.hpp index 84cb337..4894ccc 100644 --- a/source/game/systems/init_hud_animator.hpp +++ b/source/game/systems/init_hud_animator.hpp @@ -28,10 +28,12 @@ namespace Systems::InitHud { // mirrored), i el nivell centrat. Cada bloc de jugador es pinta amb el seu // color (vegeu Defaults::Hud::Colors); el nivell, en verd de sistema. struct ScoreboardData { - std::string score_p1; // 6 dígits, zeros a l'esquerra - std::string score_p2; // 6 dígits, zeros a l'esquerra - int lives_p1{0}; // vides P1 (icones de nau al render) - int lives_p2{0}; // vides P2 + std::string score_p1; // 6 dígits, zeros a l'esquerra + std::string score_p2; // 6 dígits, zeros a l'esquerra + int lives_p1{0}; // vides P1 (icones de nau al render) + int lives_p2{0}; // vides P2 + bool p1_active{false}; // jugador actiu? (inactiu → bloc apagat, sense dibuixar) + bool p2_active{false}; std::string level_label; // ex: "NIVELL " std::string level_value; // ex: "01" // Shapes de les naus per dibuixar les vides com a icones en miniatura.