From b9e26aa7554cba6128ac4f2a645ccd7c8e0c6fa2 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 26 Sep 2025 23:48:08 +0200 Subject: [PATCH] corregit: flags estatics en credits.cpp i title.cpp --- source/sections/credits.cpp | 62 +++++++++++++++++-------------------- source/sections/credits.h | 14 +++++++++ source/sections/title.cpp | 14 +++++---- source/sections/title.h | 4 +++ 4 files changed, 54 insertions(+), 40 deletions(-) diff --git a/source/sections/credits.cpp b/source/sections/credits.cpp index e9b0c3a..b83a78b 100644 --- a/source/sections/credits.cpp +++ b/source/sections/credits.cpp @@ -293,11 +293,10 @@ void Credits::fillCanvas() { // Actualiza el destino de los rectangulos de las texturas (time-based) void Credits::updateTextureDstRects(float deltaTime) { constexpr float TEXTURE_UPDATE_INTERVAL_S = 10.0f / 60.0f; // ~0.167s (cada 10 frames) - static float texture_accumulator = 0.0f; - texture_accumulator += deltaTime; + credits_state_.texture_accumulator += deltaTime; - if (texture_accumulator >= TEXTURE_UPDATE_INTERVAL_S) { - texture_accumulator -= TEXTURE_UPDATE_INTERVAL_S; + if (credits_state_.texture_accumulator >= TEXTURE_UPDATE_INTERVAL_S) { + credits_state_.texture_accumulator -= TEXTURE_UPDATE_INTERVAL_S; // Comprueba la posición de la textura con los titulos de credito if (credits_rect_dst_.y + credits_rect_dst_.h > play_area_.y) { @@ -336,20 +335,17 @@ void Credits::throwBalloons(float deltaTime) { return; } - static float balloon_accumulator = 0.0f; - static float powerball_accumulator = 0.0f; + credits_state_.balloon_accumulator += deltaTime; + credits_state_.powerball_accumulator += deltaTime; - balloon_accumulator += deltaTime; - powerball_accumulator += deltaTime; - - if (balloon_accumulator >= BALLOON_INTERVAL_S) { - balloon_accumulator -= BALLOON_INTERVAL_S; + if (credits_state_.balloon_accumulator >= BALLOON_INTERVAL_S) { + credits_state_.balloon_accumulator -= BALLOON_INTERVAL_S; const int INDEX = (static_cast(counter_ / SPEED)) % SETS.size(); balloon_manager_->deployFormation(SETS.at(INDEX), -60); } - if (powerball_accumulator >= POWERBALL_INTERVAL_S && counter_ > 0) { - powerball_accumulator -= POWERBALL_INTERVAL_S; + if (credits_state_.powerball_accumulator >= POWERBALL_INTERVAL_S && counter_ > 0) { + credits_state_.powerball_accumulator -= POWERBALL_INTERVAL_S; balloon_manager_->createPowerBall(); } } @@ -425,13 +421,11 @@ void Credits::initPlayers() { void Credits::updateBlackRects(float deltaTime) { static float current_step_ = static_cast(steps_); constexpr float BLACK_RECT_INTERVAL_S = 4.0f / 60.0f; // ~0.067s (cada 4 frames) - static float black_rect_accumulator = 0.0f; - if (top_black_rect_.h != param.game.game_area.center_y - 1 && bottom_black_rect_.y != param.game.game_area.center_y + 1) { // Si los rectangulos superior e inferior no han llegado al centro - black_rect_accumulator += deltaTime; - if (black_rect_accumulator >= BLACK_RECT_INTERVAL_S) { - black_rect_accumulator -= BLACK_RECT_INTERVAL_S; + credits_state_.black_rect_accumulator += deltaTime; + if (credits_state_.black_rect_accumulator >= BLACK_RECT_INTERVAL_S) { + credits_state_.black_rect_accumulator -= BLACK_RECT_INTERVAL_S; // Incrementa la altura del rectangulo superior top_black_rect_.h = std::min(top_black_rect_.h + 1, param.game.game_area.center_y - 1); @@ -515,33 +509,33 @@ void Credits::cycleColors() { constexpr int UPPER_LIMIT = 140; // Límite superior constexpr int LOWER_LIMIT = 30; // Límite inferior - static auto r_ = static_cast(UPPER_LIMIT); - static auto g_ = static_cast(LOWER_LIMIT); - static auto b_ = static_cast(LOWER_LIMIT); - static float step_r_ = -0.5F; // Paso flotante para transiciones suaves - static float step_g_ = 0.3F; - static float step_b_ = 0.1F; + // 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) { + credits_state_.r = static_cast(UPPER_LIMIT); + credits_state_.g = static_cast(LOWER_LIMIT); + credits_state_.b = static_cast(LOWER_LIMIT); + } // Ajustar valores de R - r_ += step_r_; - if (r_ >= UPPER_LIMIT || r_ <= LOWER_LIMIT) { - step_r_ = -step_r_; // Cambia de dirección al alcanzar los límites + credits_state_.r += credits_state_.step_r; + if (credits_state_.r >= UPPER_LIMIT || credits_state_.r <= LOWER_LIMIT) { + credits_state_.step_r = -credits_state_.step_r; // Cambia de dirección al alcanzar los límites } // Ajustar valores de G - g_ += step_g_; - if (g_ >= UPPER_LIMIT || g_ <= LOWER_LIMIT) { - step_g_ = -step_g_; // Cambia de dirección al alcanzar los límites + credits_state_.g += credits_state_.step_g; + if (credits_state_.g >= UPPER_LIMIT || credits_state_.g <= LOWER_LIMIT) { + credits_state_.step_g = -credits_state_.step_g; // Cambia de dirección al alcanzar los límites } // Ajustar valores de B - b_ += step_b_; - if (b_ >= UPPER_LIMIT || b_ <= LOWER_LIMIT) { - step_b_ = -step_b_; // Cambia de dirección al alcanzar los límites + credits_state_.b += credits_state_.step_b; + if (credits_state_.b >= UPPER_LIMIT || credits_state_.b <= LOWER_LIMIT) { + credits_state_.step_b = -credits_state_.step_b; // Cambia de dirección al alcanzar los límites } // Aplicar el color, redondeando a enteros antes de usar - color_ = Color(static_cast(r_), static_cast(g_), static_cast(b_)); + color_ = Color(static_cast(credits_state_.r), static_cast(credits_state_.g), static_cast(credits_state_.b)); tiled_bg_->setColor(color_); } diff --git a/source/sections/credits.h b/source/sections/credits.h index ac3a6dd..7be39e8 100644 --- a/source/sections/credits.h +++ b/source/sections/credits.h @@ -65,6 +65,20 @@ class Credits { int initial_volume_ = Options::audio.music.volume; // Volumen inicial int steps_ = 0; // Pasos para reducir audio + // --- Estado de acumuladores para animaciones --- + struct CreditsState { + float texture_accumulator = 0.0f; + float balloon_accumulator = 0.0f; + float powerball_accumulator = 0.0f; + float black_rect_accumulator = 0.0f; + float r = 255.0f; // UPPER_LIMIT + float g = 0.0f; // LOWER_LIMIT + float b = 0.0f; // LOWER_LIMIT + float step_r = -0.5f; + float step_g = 0.3f; + float step_b = 0.1f; + } credits_state_; + // --- Rectángulos de renderizado --- // Texto de créditos SDL_FRect credits_rect_src_ = param.game.game_area.rect; diff --git a/source/sections/title.cpp b/source/sections/title.cpp index 8ffcdba..75a3de2 100644 --- a/source/sections/title.cpp +++ b/source/sections/title.cpp @@ -43,7 +43,11 @@ Title::Title() game_logo_(std::make_unique(param.game.game_area.center_x, param.title.title_c_c_position)), mini_logo_sprite_(std::make_unique(Resource::get()->getTexture("logo_jailgames_mini.png"))), state_(State::LOGO_ANIMATING), - num_controllers_(Input::get()->getNumGamepads()) { + num_controllers_(Input::get()->getNumGamepads()) +#ifdef _DEBUG + , debug_color_(param.title.bg_color) +#endif +{ // Configura objetos tiled_bg_->setColor(param.title.bg_color); tiled_bg_->setSpeed(0.0F); @@ -141,13 +145,11 @@ void Title::handleKeyDownEvent(const SDL_Event& event) { #ifdef _DEBUG void Title::handleDebugColorKeys(SDL_Keycode key) { - static Color color_ = param.title.bg_color; - - adjustColorComponent(key, color_); + adjustColorComponent(key, debug_color_); counter_time_ = 0.0f; - tiled_bg_->setColor(color_); - printColorValue(color_); + tiled_bg_->setColor(debug_color_); + printColorValue(debug_color_); } void Title::adjustColorComponent(SDL_Keycode key, Color& color) { diff --git a/source/sections/title.h b/source/sections/title.h index 45235ff..a1d5d2b 100644 --- a/source/sections/title.h +++ b/source/sections/title.h @@ -99,6 +99,10 @@ class Title { bool player1_start_pressed_ = false; // Indica si se ha pulsado el botón de empezar para el jugador 1 bool player2_start_pressed_ = false; // Indica si se ha pulsado el botón de empezar para el jugador 2 +#ifdef _DEBUG + Color debug_color_; // Color para depuración en modo debug +#endif + // --- Ciclo de vida del título --- void update(float deltaTime); // Actualiza las variables del objeto float calculateDeltaTime(); // Calcula el tiempo transcurrido desde el último frame