corregit: flags estatics en credits.cpp i title.cpp

This commit is contained in:
2025-09-26 23:48:08 +02:00
parent b2afef2226
commit b9e26aa755
4 changed files with 54 additions and 40 deletions

View File

@@ -293,11 +293,10 @@ void Credits::fillCanvas() {
// Actualiza el destino de los rectangulos de las texturas (time-based) // Actualiza el destino de los rectangulos de las texturas (time-based)
void Credits::updateTextureDstRects(float deltaTime) { void Credits::updateTextureDstRects(float deltaTime) {
constexpr float TEXTURE_UPDATE_INTERVAL_S = 10.0f / 60.0f; // ~0.167s (cada 10 frames) constexpr float TEXTURE_UPDATE_INTERVAL_S = 10.0f / 60.0f; // ~0.167s (cada 10 frames)
static float texture_accumulator = 0.0f; credits_state_.texture_accumulator += deltaTime;
texture_accumulator += deltaTime;
if (texture_accumulator >= TEXTURE_UPDATE_INTERVAL_S) { if (credits_state_.texture_accumulator >= TEXTURE_UPDATE_INTERVAL_S) {
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 // Comprueba la posición de la textura con los titulos de credito
if (credits_rect_dst_.y + credits_rect_dst_.h > play_area_.y) { if (credits_rect_dst_.y + credits_rect_dst_.h > play_area_.y) {
@@ -336,20 +335,17 @@ void Credits::throwBalloons(float deltaTime) {
return; return;
} }
static float balloon_accumulator = 0.0f; credits_state_.balloon_accumulator += deltaTime;
static float powerball_accumulator = 0.0f; credits_state_.powerball_accumulator += deltaTime;
balloon_accumulator += deltaTime; if (credits_state_.balloon_accumulator >= BALLOON_INTERVAL_S) {
powerball_accumulator += deltaTime; credits_state_.balloon_accumulator -= BALLOON_INTERVAL_S;
if (balloon_accumulator >= BALLOON_INTERVAL_S) {
balloon_accumulator -= BALLOON_INTERVAL_S;
const int INDEX = (static_cast<int>(counter_ / SPEED)) % SETS.size(); const int INDEX = (static_cast<int>(counter_ / SPEED)) % SETS.size();
balloon_manager_->deployFormation(SETS.at(INDEX), -60); balloon_manager_->deployFormation(SETS.at(INDEX), -60);
} }
if (powerball_accumulator >= POWERBALL_INTERVAL_S && counter_ > 0) { if (credits_state_.powerball_accumulator >= POWERBALL_INTERVAL_S && counter_ > 0) {
powerball_accumulator -= POWERBALL_INTERVAL_S; credits_state_.powerball_accumulator -= POWERBALL_INTERVAL_S;
balloon_manager_->createPowerBall(); balloon_manager_->createPowerBall();
} }
} }
@@ -425,13 +421,11 @@ void Credits::initPlayers() {
void Credits::updateBlackRects(float deltaTime) { void Credits::updateBlackRects(float deltaTime) {
static float current_step_ = static_cast<float>(steps_); static float current_step_ = static_cast<float>(steps_);
constexpr float BLACK_RECT_INTERVAL_S = 4.0f / 60.0f; // ~0.067s (cada 4 frames) 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) { 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 // Si los rectangulos superior e inferior no han llegado al centro
black_rect_accumulator += deltaTime; credits_state_.black_rect_accumulator += deltaTime;
if (black_rect_accumulator >= BLACK_RECT_INTERVAL_S) { if (credits_state_.black_rect_accumulator >= BLACK_RECT_INTERVAL_S) {
black_rect_accumulator -= BLACK_RECT_INTERVAL_S; credits_state_.black_rect_accumulator -= BLACK_RECT_INTERVAL_S;
// Incrementa la altura del rectangulo superior // Incrementa la altura del rectangulo superior
top_black_rect_.h = std::min(top_black_rect_.h + 1, param.game.game_area.center_y - 1); 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 UPPER_LIMIT = 140; // Límite superior
constexpr int LOWER_LIMIT = 30; // Límite inferior constexpr int LOWER_LIMIT = 30; // Límite inferior
static auto r_ = static_cast<float>(UPPER_LIMIT); // Inicializar valores RGB si es la primera vez
static auto g_ = static_cast<float>(LOWER_LIMIT); if (credits_state_.r == 255.0f && credits_state_.g == 0.0f && credits_state_.b == 0.0f && credits_state_.step_r == -0.5f) {
static auto b_ = static_cast<float>(LOWER_LIMIT); credits_state_.r = static_cast<float>(UPPER_LIMIT);
static float step_r_ = -0.5F; // Paso flotante para transiciones suaves credits_state_.g = static_cast<float>(LOWER_LIMIT);
static float step_g_ = 0.3F; credits_state_.b = static_cast<float>(LOWER_LIMIT);
static float step_b_ = 0.1F; }
// Ajustar valores de R // Ajustar valores de R
r_ += step_r_; credits_state_.r += credits_state_.step_r;
if (r_ >= UPPER_LIMIT || r_ <= LOWER_LIMIT) { if (credits_state_.r >= UPPER_LIMIT || credits_state_.r <= LOWER_LIMIT) {
step_r_ = -step_r_; // Cambia de dirección al alcanzar los límites credits_state_.step_r = -credits_state_.step_r; // Cambia de dirección al alcanzar los límites
} }
// Ajustar valores de G // Ajustar valores de G
g_ += step_g_; credits_state_.g += credits_state_.step_g;
if (g_ >= UPPER_LIMIT || g_ <= LOWER_LIMIT) { if (credits_state_.g >= UPPER_LIMIT || credits_state_.g <= LOWER_LIMIT) {
step_g_ = -step_g_; // Cambia de dirección al alcanzar los límites credits_state_.step_g = -credits_state_.step_g; // Cambia de dirección al alcanzar los límites
} }
// Ajustar valores de B // Ajustar valores de B
b_ += step_b_; credits_state_.b += credits_state_.step_b;
if (b_ >= UPPER_LIMIT || b_ <= LOWER_LIMIT) { if (credits_state_.b >= UPPER_LIMIT || credits_state_.b <= LOWER_LIMIT) {
step_b_ = -step_b_; // Cambia de dirección al alcanzar los límites 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 // Aplicar el color, redondeando a enteros antes de usar
color_ = Color(static_cast<int>(r_), static_cast<int>(g_), static_cast<int>(b_)); color_ = Color(static_cast<int>(credits_state_.r), static_cast<int>(credits_state_.g), static_cast<int>(credits_state_.b));
tiled_bg_->setColor(color_); tiled_bg_->setColor(color_);
} }

View File

@@ -65,6 +65,20 @@ class Credits {
int initial_volume_ = Options::audio.music.volume; // Volumen inicial int initial_volume_ = Options::audio.music.volume; // Volumen inicial
int steps_ = 0; // Pasos para reducir audio 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 --- // --- Rectángulos de renderizado ---
// Texto de créditos // Texto de créditos
SDL_FRect credits_rect_src_ = param.game.game_area.rect; SDL_FRect credits_rect_src_ = param.game.game_area.rect;

View File

@@ -43,7 +43,11 @@ Title::Title()
game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)), game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)),
mini_logo_sprite_(std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"))), mini_logo_sprite_(std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"))),
state_(State::LOGO_ANIMATING), 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 // Configura objetos
tiled_bg_->setColor(param.title.bg_color); tiled_bg_->setColor(param.title.bg_color);
tiled_bg_->setSpeed(0.0F); tiled_bg_->setSpeed(0.0F);
@@ -141,13 +145,11 @@ void Title::handleKeyDownEvent(const SDL_Event& event) {
#ifdef _DEBUG #ifdef _DEBUG
void Title::handleDebugColorKeys(SDL_Keycode key) { void Title::handleDebugColorKeys(SDL_Keycode key) {
static Color color_ = param.title.bg_color; adjustColorComponent(key, debug_color_);
adjustColorComponent(key, color_);
counter_time_ = 0.0f; counter_time_ = 0.0f;
tiled_bg_->setColor(color_); tiled_bg_->setColor(debug_color_);
printColorValue(color_); printColorValue(debug_color_);
} }
void Title::adjustColorComponent(SDL_Keycode key, Color& color) { void Title::adjustColorComponent(SDL_Keycode key, Color& color) {

View File

@@ -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 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 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 --- // --- Ciclo de vida del título ---
void update(float deltaTime); // Actualiza las variables del objeto void update(float deltaTime); // Actualiza las variables del objeto
float calculateDeltaTime(); // Calcula el tiempo transcurrido desde el último frame float calculateDeltaTime(); // Calcula el tiempo transcurrido desde el último frame