fix(game): HUD lives desde YAML, prompt P1 en single-P2, countdown 9..0 configurable

This commit is contained in:
JailDesigner committed 2026-05-08 21:14:33 +02:00
1 parent 78e164fce4
commit 5e862ceadc
9 files changed
+66 -29

No files matched your search

+10 -4
View File
@@ -36,7 +36,7 @@ namespace GameOverFsm {
cfg.continue_text_enter_ms = readChildInt(n, "continue_text_enter_ms", cfg.continue_text_enter_ms);
cfg.continue_text_hold_ms = readChildInt(n, "continue_text_hold_ms", cfg.continue_text_hold_ms);
cfg.continue_text_exit_ms = readChildInt(n, "continue_text_exit_ms", cfg.continue_text_exit_ms);
cfg.continue_count_steps = readChildInt(n, "continue_count_steps", cfg.continue_count_steps);
cfg.continue_count_start = readChildInt(n, "continue_count_start", cfg.continue_count_start);
cfg.game_over_text_hold_ms = readChildInt(n, "game_over_text_hold_ms", cfg.game_over_text_hold_ms);
cfg.game_over_text_exit_ms = readChildInt(n, "game_over_text_exit_ms", cfg.game_over_text_exit_ms);
cfg.game_over_wait_ms = readChildInt(n, "game_over_wait_ms", cfg.game_over_wait_ms);
@@ -112,10 +112,16 @@ namespace GameOverFsm {
auto countdownSecondsRemaining(State current, const Transition& t, const Config& cfg) -> int {
if (current != State::CONTINUE_PROMPT) { return 0; }
if (t.phase != 1) { return 0; }
const int STEPS = std::max(1, cfg.continue_count_steps);
const int STEP_MS = std::max(1, cfg.continue_text_hold_ms / STEPS);
// La sèrie és [start, start-1, ..., 1, 0]: en total `start+1`
// graons. El primer número visible és `start` i l'últim 0 es
// manté durant el seu graó abans que la fase 1 acabi i la FSM
// salti a GAME_OVER. Si `start == 0` només es mostra "0"
// durant tot el hold.
const int START = std::max(0, cfg.continue_count_start);
const int STEP_COUNT = START + 1;
const int STEP_MS = std::max(1, cfg.continue_text_hold_ms / STEP_COUNT);
const int CONSUMED = t.elapsed_ms / STEP_MS;
return std::clamp(STEPS - CONSUMED, 0, STEPS);
return std::clamp(START - CONSUMED, 0, START);
}
auto stateName(State s) -> const char* {
+9 -5
View File
@@ -51,12 +51,16 @@ namespace GameOverFsm {
struct Config {
// CONTINUE? — animació d'entrada/sortida idèntica al room text.
int continue_text_enter_ms{500};
// Hold = duració total del countdown (es divideix en
// `continue_count_steps` graons d'1 segon visualment).
int continue_text_hold_ms{5000};
// Hold = duració total del countdown. Es divideix en
// (continue_count_start + 1) graons iguals; el cas canònic és
// 10000 ms / 10 graons d'1 s cadascun.
int continue_text_hold_ms{10000};
int continue_text_exit_ms{500};
// Quants "tics" mostra el countdown de CONTINUE?. 5 → "5,4,3,2,1".
int continue_count_steps{5};
// Primer número visible al countdown. La sèrie és
// [continue_count_start, ..., 1, 0] — sempre acaba en 0 i el
// valor 0 es manté visible durant l'últim graó abans del salt
// a GAME_OVER. 9 → "9, 8, ..., 0" (10 graons).
int continue_count_start{9};
// GAME OVER — apareix sense enter anim (el panel ja és amunt
// del CONTINUE?) i s'esvaeix amb la mateixa exit anim que el
+11 -4
View File
@@ -456,10 +456,17 @@ GameScene::GameScene(Config config)
auto hud_font_surface = Resource::Cache::get().getSurface(HUD_FONT_GIF_KEY);
auto hud_font = std::make_shared<Text>(hud_font_surface, UiConfig::get().hudFont().fnt);
hud_font->setDefaultKerning(UiConfig::get().hudFont().kerning);
hud_ = std::make_unique<Hud>(entity_manager_.getBus(), hud_font);
// Si hi ha P2 actiu, activem el seu bloc (per defecte el HUD naix amb
// només P1). Mentre els events del bus no porten `player_id`, els hits
// segueixen aplicant-se a P1 (veure TODO a Hud::onPlayerHit).
// Vides inicials del HUD = `initial_lives` del YAML del jugador
// (`Player::loadFrom` ja ha omplert `death_config` abans d'aquí).
// Sense això, el marcador es queda fixe a 3 i el YAML perd efecte.
hud_ = std::make_unique<Hud>(entity_manager_.getBus(), hud_font, Player::getInitialLives());
// Activem el bloc HUD per als slots que arranquen en partida. Els
// inactius queden mostrant el prompt "POLSA START / PER JUGAR" via
// `refreshJoinPrompt` cada frame. Tots dos s'haurien de poder
// activar (cas BOTH) o un dels dos (cas P1 o P2 sols) — el HUD
// naix amb tots dos slots inactius i és aquesta crida la que dóna
// l'estat real.
if (USE_P1) { hud_->activatePlayer(1); }
if (USE_P2) { hud_->activatePlayer(2); }
// Sincronització inicial dels comptadors de piràmide/sala del HUD amb
// el LevelManager (després de cada `loadRoom` també es refresca; ací