diff --git a/source/director.cpp b/source/director.cpp index a4a282c..f7a81e2 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -44,7 +44,7 @@ Director::Director(int argc, std::span argv) { Section::name = Section::Name::GAME; Section::options = Section::Options::GAME_PLAY_1P; #elif _DEBUG - Section::name = Section::Name::HI_SCORE_TABLE; + Section::name = Section::Name::CREDITS; Section::options = Section::Options::GAME_PLAY_1P; #else // NORMAL GAME Section::name = Section::Name::LOGO; diff --git a/source/sections/credits.cpp b/source/sections/credits.cpp index 0f848a4..f4465e8 100644 --- a/source/sections/credits.cpp +++ b/source/sections/credits.cpp @@ -82,7 +82,7 @@ void Credits::run() { } } -// Actualiza las variables (time-based) +// Actualiza las variables (time-based puro - sin conversión frame-based) void Credits::update(float delta_time) { const float MULTIPLIER = want_to_pass_ ? FAST_FORWARD_MULTIPLIER : 1.0F; const float ADJUSTED_DELTA_TIME = delta_time * MULTIPLIER; @@ -99,10 +99,6 @@ void Credits::update(float delta_time) { updatePlayers(ADJUSTED_DELTA_TIME); updateAllFades(ADJUSTED_DELTA_TIME); - // Convertir deltaTime a equivalente de frames (60fps) - const float FRAME_FACTOR = ADJUSTED_DELTA_TIME * 60.0F; - counter_ += FRAME_FACTOR; - fillCanvas(); } @@ -270,7 +266,7 @@ void Credits::fillCanvas() { SDL_SetRenderTarget(Screen::get()->getRenderer(), temp); } -// Actualiza el destino de los rectangulos de las texturas (time-based) +// Actualiza el destino de los rectangulos de las texturas (time-based puro) void Credits::updateTextureDstRects(float delta_time) { constexpr float TEXTURE_UPDATE_INTERVAL_S = 10.0F / 60.0F; // ~0.167s (cada 10 frames) credits_state_.texture_accumulator += delta_time; @@ -284,34 +280,45 @@ void Credits::updateTextureDstRects(float delta_time) { } // Comprueba la posición de la textura con el mini_logo - if (mini_logo_rect_dst_.y == mini_logo_final_pos_) { + if (mini_logo_rect_dst_.y <= static_cast(mini_logo_final_pos_)) { + // Forzar posición exacta para evitar problemas de comparación float + mini_logo_rect_dst_.y = static_cast(mini_logo_final_pos_); mini_logo_on_position_ = true; - - // Si el jugador quiere pasar los titulos de credito, el fade se inicia solo - if (want_to_pass_) { - fading_ = true; - } - - // Se activa el contador para evitar que la sección sea infinita - if (counter_prevent_endless_ == 1000) { - fading_ = true; - } else { - ++counter_prevent_endless_; - } } else { --mini_logo_rect_dst_.y; } } + + // Acumular tiempo desde que el logo llegó a su posición (fuera del if para que se ejecute cada frame) + if (mini_logo_on_position_) { + time_since_logo_positioned_ += delta_time; + + // Timeout para evitar que la sección sea infinita + if (time_since_logo_positioned_ >= MAX_TIME_AFTER_LOGO_S) { + fading_ = true; + } + + // Si el jugador quiere pasar los titulos de credito, el fade se inicia solo + if (want_to_pass_) { + fading_ = true; + } + } } -// Tira globos al escenario (time-based) +// Tira globos al escenario (time-based puro) void Credits::throwBalloons(float delta_time) { constexpr int SPEED = 200; + constexpr size_t NUM_SETS = 8; // Tamaño del vector SETS const std::vector SETS = {0, 63, 25, 67, 17, 75, 13, 50}; - constexpr float BALLOON_INTERVAL_S = SPEED / 60.0F; // ~3.33s (cada 200 frames) - constexpr float POWERBALL_INTERVAL_S = (SPEED * 4) / 60.0F; // ~13.33s (cada 800 frames) + constexpr float BALLOON_INTERVAL_S = SPEED / 60.0F; // ~3.33s (cada 200 frames) + constexpr float POWERBALL_INTERVAL_S = (SPEED * 4) / 60.0F; // ~13.33s (cada 800 frames) + constexpr float MAX_BALLOON_TIME_S = ((NUM_SETS - 1) * SPEED * 3) / 60.0F; // Tiempo máximo para lanzar globos - if (counter_ > ((SETS.size() - 1) * SPEED) * 3) { + // Acumular tiempo total de globos + elapsed_time_balloons_ += delta_time; + + // Detener lanzamiento después del tiempo límite + if (elapsed_time_balloons_ > MAX_BALLOON_TIME_S) { return; } @@ -320,11 +327,11 @@ void Credits::throwBalloons(float delta_time) { if (credits_state_.balloon_accumulator >= BALLOON_INTERVAL_S) { credits_state_.balloon_accumulator -= BALLOON_INTERVAL_S; - const int INDEX = (static_cast(counter_ / SPEED)) % SETS.size(); + const int INDEX = (static_cast(elapsed_time_balloons_ * 60.0F / SPEED)) % SETS.size(); balloon_manager_->deployFormation(SETS.at(INDEX), -60); } - if (credits_state_.powerball_accumulator >= POWERBALL_INTERVAL_S && counter_ > 0) { + if (credits_state_.powerball_accumulator >= POWERBALL_INTERVAL_S && elapsed_time_balloons_ > 0.0F) { credits_state_.powerball_accumulator -= POWERBALL_INTERVAL_S; balloon_manager_->createPowerBall(); } @@ -485,11 +492,12 @@ void Credits::updateBlackRects(float delta_time) { // Fase final: ya completado el movimiento de rects Audio::get()->setMusicVolume(0); // Audio::get()->stopMusic(); // opcional, si quieres parar la reproducción - if (counter_pre_fade_ >= 400.0f) { + + // Usar segundos puros en lugar de frames equivalentes + if (counter_pre_fade_ >= PRE_FADE_DELAY_S) { if (fade_out_) fade_out_->activate(); } else { - const float frame_increment = delta_time * FRAMES_PER_SECOND; - counter_pre_fade_ += frame_increment; + counter_pre_fade_ += delta_time; } } diff --git a/source/sections/credits.hpp b/source/sections/credits.hpp index 0343316..34d17b1 100644 --- a/source/sections/credits.hpp +++ b/source/sections/credits.hpp @@ -32,12 +32,14 @@ class Credits { void initVars(); // Inicializa variables void startCredits(); // Inicializa mas variables - // --- Constantes de clase --- + // --- Constantes de clase (time-based) --- static constexpr int PLAY_AREA_HEIGHT = 200; static constexpr float FAST_FORWARD_MULTIPLIER = 6.0F; - static constexpr float BLACK_RECT_INTERVAL_S = 4.0F / 60.0F; // ~0.0667s + static constexpr float BLACK_RECT_INTERVAL_S = 4.0F / 60.0F; // ~0.0667s (cada 4 frames a 60fps) static constexpr float FRAMES_PER_SECOND = 60.0F; static constexpr int HORIZONTAL_SPEED = 2; + static constexpr float MAX_TIME_AFTER_LOGO_S = 1000.0F / 60.0F; // ~16.67s (límite para evitar bucle infinito) + static constexpr float PRE_FADE_DELAY_S = 400.0F / 60.0F; // ~6.67s (retraso antes del fade final) // --- Objetos principales --- std::unique_ptr balloon_manager_; // Gestión de globos @@ -50,11 +52,11 @@ class Credits { SDL_Texture* text_texture_; // Textura con el texto de créditos SDL_Texture* canvas_; // Textura donde se dibuja todo - // --- Temporización y contadores --- - Uint64 last_time_ = 0; // Último tiempo registrado para deltaTime - float counter_ = 0.0F; // Contador principal de lógica - float counter_pre_fade_ = 0.0F; // Activación del fundido final - float counter_prevent_endless_ = 0.0F; // Prevención de bucle infinito + // --- Temporización (time-based puro) --- + Uint64 last_time_ = 0; // Último tiempo registrado para deltaTime + float elapsed_time_balloons_ = 0.0F; // Tiempo acumulado para lanzamiento de globos (segundos) + float counter_pre_fade_ = 0.0F; // Tiempo antes de activar fundido final (segundos) + float time_since_logo_positioned_ = 0.0F; // Tiempo desde que el logo llegó a su posición (segundos) float current_step_ = 0.0F; int total_steps_ = 1; bool initialized_ = false;