From 8ddee663042ff727fb426a57d2c1a5cfffef96a8 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 20 Oct 2025 20:36:33 +0200 Subject: [PATCH] fix: el cicle de color de credits.cpp --- source/director.cpp | 2 +- source/sections/credits.cpp | 34 +++++++++++++++++++++++++--------- source/sections/credits.hpp | 4 +--- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index be37d65..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::LOGO; + 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 b590c7f..8ff4830 100644 --- a/source/sections/credits.cpp +++ b/source/sections/credits.cpp @@ -111,7 +111,7 @@ void Credits::update(float delta_time) { Audio::update(); // Actualiza el objeto audio tiled_bg_->update(ADJUSTED_DELTA_TIME); - cycleColors(); + cycleColors(ADJUSTED_DELTA_TIME); balloon_manager_->update(ADJUSTED_DELTA_TIME); updateTextureDstRects(ADJUSTED_DELTA_TIME); throwBalloons(ADJUSTED_DELTA_TIME); @@ -505,10 +505,14 @@ void Credits::resetVolume() const { Audio::get()->setMusicVolume(Options::audio.music.volume); } -// Cambia el color del fondo -void Credits::cycleColors() { +// Cambia el color del fondo (time-based) +void Credits::cycleColors(float delta_time) { constexpr int UPPER_LIMIT = 140; // Límite superior constexpr int LOWER_LIMIT = 30; // Límite inferior + + // Factor para escalar los valores de incremento. + // Asumimos que los valores originales estaban balanceados para 60 FPS. + const float FRAME_ADJUSTMENT = delta_time * 60.0F; // Inicializar valores RGB si es la primera vez if (credits_state_.r == 255.0F && credits_state_.g == 0.0F && credits_state_.b == 0.0F && credits_state_.step_r == -0.5F) { @@ -518,21 +522,33 @@ void Credits::cycleColors() { } // Ajustar valores de R - credits_state_.r += credits_state_.step_r; - if (credits_state_.r >= UPPER_LIMIT || credits_state_.r <= LOWER_LIMIT) { + credits_state_.r += credits_state_.step_r * FRAME_ADJUSTMENT; + if (credits_state_.r >= UPPER_LIMIT) { + credits_state_.r = UPPER_LIMIT; // Clamp para evitar que se pase credits_state_.step_r = -credits_state_.step_r; // Cambia de dirección al alcanzar los límites + } else if (credits_state_.r <= LOWER_LIMIT) { + credits_state_.r = LOWER_LIMIT; // Clamp para evitar que se pase + credits_state_.step_r = -credits_state_.step_r; } // Ajustar valores de G - credits_state_.g += credits_state_.step_g; - if (credits_state_.g >= UPPER_LIMIT || credits_state_.g <= LOWER_LIMIT) { + credits_state_.g += credits_state_.step_g * FRAME_ADJUSTMENT; + if (credits_state_.g >= UPPER_LIMIT) { + credits_state_.g = UPPER_LIMIT; credits_state_.step_g = -credits_state_.step_g; // Cambia de dirección al alcanzar los límites + } else if (credits_state_.g <= LOWER_LIMIT) { + credits_state_.g = LOWER_LIMIT; + credits_state_.step_g = -credits_state_.step_g; } // Ajustar valores de B - credits_state_.b += credits_state_.step_b; - if (credits_state_.b >= UPPER_LIMIT || credits_state_.b <= LOWER_LIMIT) { + credits_state_.b += credits_state_.step_b * FRAME_ADJUSTMENT; + if (credits_state_.b >= UPPER_LIMIT) { + credits_state_.b = UPPER_LIMIT; credits_state_.step_b = -credits_state_.step_b; // Cambia de dirección al alcanzar los límites + } else if (credits_state_.b <= LOWER_LIMIT) { + credits_state_.b = LOWER_LIMIT; + credits_state_.step_b = -credits_state_.step_b; } // Aplicar el color, redondeando a enteros antes de usar diff --git a/source/sections/credits.hpp b/source/sections/credits.hpp index 47d0946..607b5c1 100644 --- a/source/sections/credits.hpp +++ b/source/sections/credits.hpp @@ -129,12 +129,10 @@ class Credits { void renderPlayers(); // Renderiza los jugadores // --- Métodos de lógica del juego --- - void throwBalloons(); // Lanzar globos al escenario (frame-based) void throwBalloons(float delta_time); // Lanzar globos al escenario (time-based) void initPlayers(); // Inicializar jugadores - void updateAllFades(); // Actualizar estados de fade (frame-based) void updateAllFades(float delta_time); // Actualizar estados de fade (time-based) - void cycleColors(); // Cambiar colores de fondo + void cycleColors(float delta_time); // Cambiar colores de fondo void updatePlayers(float delta_time); // Actualza los jugadores (time-based) // --- Métodos de interfaz ---