fix: el cicle de color de credits.cpp

This commit is contained in:
2025-10-20 20:36:33 +02:00
parent 4fb6a9999f
commit 8ddee66304
3 changed files with 27 additions and 13 deletions

View File

@@ -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