diff --git a/source/game/escenes/escena_joc.cpp b/source/game/escenes/escena_joc.cpp index 88db8ef..1741fa2 100644 --- a/source/game/escenes/escena_joc.cpp +++ b/source/game/escenes/escena_joc.cpp @@ -245,9 +245,15 @@ void EscenaJoc::actualitzar(float delta_time) { switch (estat) { case StageSystem::EstatStage::INIT_HUD: { - // Update stage manager timer + // Update stage manager timer (pot canviar l'estat!) stage_manager_->actualitzar(delta_time); + // [FIX] Si l'estat ha canviat durant actualitzar(), sortir immediatament + // per evitar recalcular la posició de la nau amb el nou timer + if (stage_manager_->get_estat() != StageSystem::EstatStage::INIT_HUD) { + break; + } + // Calcular progrés de l'animació de la nau float ship_progress = 1.0f - (stage_manager_->get_timer_transicio() / Defaults::Game::INIT_HUD_DURATION); @@ -258,10 +264,24 @@ void EscenaJoc::actualitzar(float delta_time) { (Defaults::Game::INIT_HUD_SHIP_DURATION / Defaults::Game::INIT_HUD_DURATION); ship_anim_progress = std::min(1.0f, ship_anim_progress); + // [DEBUG] Imprimir progrés i posició cada 10 frames + static int debug_frame_count = 0; + if (++debug_frame_count % 10 == 0) { + std::cout << "[INIT_HUD] timer=" << stage_manager_->get_timer_transicio() + << " ship_progress=" << ship_progress + << " ship_anim_progress=" << ship_anim_progress + << " condition=" << (ship_anim_progress < 1.0f ? "TRUE" : "FALSE") + << " pos.y=" << nau_.get_centre().y + << std::endl; + } + // Actualitzar posició de la nau segons animació if (ship_anim_progress < 1.0f) { Punt pos_animada = calcular_posicio_nau_init_hud(ship_anim_progress); + std::cout << "[INIT_HUD] SETTING pos.y=" << pos_animada.y << std::endl; // [DEBUG] nau_.set_centre(pos_animada); + } else { + std::cout << "[INIT_HUD] SKIPPING update (progress >= 1.0)" << std::endl; // [DEBUG] } // Una vegada l'animació acaba, permetre control normal @@ -270,7 +290,14 @@ void EscenaJoc::actualitzar(float delta_time) { break; } - case StageSystem::EstatStage::LEVEL_START: + case StageSystem::EstatStage::LEVEL_START: { + // [DEBUG] Log entrada a LEVEL_START + static bool first_entry = true; + if (first_entry) { + std::cout << "[LEVEL_START] ENTERED with pos.y=" << nau_.get_centre().y << std::endl; + first_entry = false; + } + // Update countdown timer stage_manager_->actualitzar(delta_time); @@ -286,6 +313,7 @@ void EscenaJoc::actualitzar(float delta_time) { // [NEW] Update debris debris_manager_.actualitzar(delta_time); break; + } case StageSystem::EstatStage::PLAYING: { // [NEW] Update stage manager (spawns enemies, pass pause flag) diff --git a/source/game/stage_system/stage_manager.cpp b/source/game/stage_system/stage_manager.cpp index 800f744..76ba60b 100644 --- a/source/game/stage_system/stage_manager.cpp +++ b/source/game/stage_system/stage_manager.cpp @@ -110,7 +110,14 @@ void StageManager::canviar_estat(EstatStage nou_estat) { void StageManager::processar_init_hud(float delta_time) { timer_transicio_ -= delta_time; + // [DEBUG] Imprimir timer cada 10 frames + static int debug_frame_count = 0; + if (++debug_frame_count % 10 == 0) { + std::cout << "[processar_init_hud] timer=" << timer_transicio_ << std::endl; + } + if (timer_transicio_ <= 0.0f) { + std::cout << "[processar_init_hud] TRANSICIÓ a LEVEL_START!" << std::endl; // [DEBUG] canviar_estat(EstatStage::LEVEL_START); } }