tweak(hud): el bloc d'un jugador inactiu es deixa apagat (sense dibuixar, reservant l'ample)

This commit is contained in:
2026-05-29 21:06:29 +02:00
parent 55b37ba594
commit 5ba562178b
3 changed files with 16 additions and 6 deletions
+2
View File
@@ -945,6 +945,8 @@ auto GameScene::buildScoreboardData() const -> Systems::InitHud::ScoreboardData
return std::string(6 - std::min(6, static_cast<int>(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";
+8 -2
View File
@@ -208,12 +208,18 @@ namespace Systems::InitHud {
const std::shared_ptr<Graphics::Shape>& 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,
+6 -4
View File
@@ -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.