Compare commits

...

5 Commits

21 changed files with 123 additions and 55 deletions

View File

@@ -39,22 +39,22 @@ void DefineButtons::render() {
}
}
void DefineButtons::update() {
void DefineButtons::update(float delta_time) {
if (!enabled_) {
return;
}
// Actualizar la ventana siempre
if (window_message_) {
window_message_->update();
window_message_->update(delta_time);
}
// Manejar la secuencia de cierre si ya terminamos
if (finished_ && message_shown_) {
message_timer_++;
message_timer_ += delta_time;
// Después del delay, iniciar animación de cierre (solo una vez)
if (message_timer_ > MESSAGE_DISPLAY_FRAMES && !closing_) {
if (message_timer_ >= MESSAGE_DISPLAY_DURATION_S && !closing_) {
if (window_message_) {
window_message_->hide(); // Iniciar animación de cierre
}
@@ -234,7 +234,7 @@ void DefineButtons::checkEnd() {
// Solo marcar que ya mostramos el mensaje
message_shown_ = true;
message_timer_ = 0;
message_timer_ = 0.0f;
}
}

View File

@@ -36,7 +36,7 @@ class DefineButtons {
// --- Métodos principales ---
void render();
void update();
void update(float delta_time);
void handleEvents(const SDL_Event &event);
auto enable(Options::Gamepad *options_gamepad) -> bool;
void disable();
@@ -48,7 +48,7 @@ class DefineButtons {
private:
// --- Constantes ---
static constexpr size_t MESSAGE_DISPLAY_FRAMES = 120; // Cuánto tiempo mostrar el mensaje (en frames) ~2 segundos a 60fps
static constexpr float MESSAGE_DISPLAY_DURATION_S = 2.0f; // Cuánto tiempo mostrar el mensaje en segundos
// --- Objetos y punteros ---
Input *input_ = nullptr; // Entrada del usuario
@@ -59,7 +59,7 @@ class DefineButtons {
std::vector<Button> buttons_; // Lista de botones
std::vector<std::string> controller_names_; // Nombres de los controladores
size_t index_button_ = 0; // Índice del botón seleccionado
size_t message_timer_ = 0; // Contador de frames para el mensaje
float message_timer_ = 0.0f; // Timer en segundos para el mensaje
bool enabled_ = false; // Flag para indicar si está activo
bool finished_ = false; // Flag para indicar si ha terminado
bool closing_ = false; // Flag para indicar que está cerrando

View File

@@ -42,7 +42,7 @@ Director::Director(int argc, std::span<char *> argv) {
Section::name = Section::Name::GAME;
Section::options = Section::Options::GAME_PLAY_1P;
#elif _DEBUG
Section::name = Section::Name::GAME;
Section::name = Section::Name::TITLE;
Section::options = Section::Options::GAME_PLAY_1P;
#else // NORMAL GAME
Section::name = Section::Name::LOGO;

View File

@@ -161,7 +161,7 @@ void Screen::update(float delta_time) {
shake_effect_.update(src_rect_, dst_rect_, delta_time);
flash_effect_.update(delta_time);
if (service_menu_ != nullptr) {
service_menu_->update();
service_menu_->update(delta_time);
}
if (notifier_ != nullptr) {
notifier_->update(delta_time);

View File

@@ -105,8 +105,8 @@ void Credits::update(float deltaTime) {
const float multiplier = want_to_pass_ ? 4.0f : 1.0f;
const float adjusted_delta_time = deltaTime * multiplier;
static auto *screen = Screen::get();
screen->update(deltaTime); // Actualiza el objeto screen
static auto *const SCREEN = Screen::get();
SCREEN->update(deltaTime); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
tiled_bg_->update(adjusted_delta_time);

View File

@@ -869,15 +869,27 @@ void Game::updateTimeStopped(float deltaTime) {
// Fase de advertencia (últimos 2 segundos)
if (time_stopped_timer_ <= WARNING_THRESHOLD_S) {
static float last_sound_time = 0.0f;
static bool color_flash_sound_played = false;
static bool warning_phase_started = false;
// CLAC al entrar en fase de advertencia
if (!warning_phase_started) {
playSound("clock.wav");
warning_phase_started = true;
last_sound_time = 0.0f; // Reset para empezar el ciclo rápido
}
last_sound_time += deltaTime;
if (last_sound_time >= CLOCK_SOUND_INTERVAL_S) {
balloon_manager_->normalColorsToAllBalloons();
playSound("clock.wav");
last_sound_time = 0.0f;
} else if (last_sound_time >= COLOR_FLASH_INTERVAL_S) {
color_flash_sound_played = false; // Reset flag para el próximo intervalo
} else if (last_sound_time >= COLOR_FLASH_INTERVAL_S && !color_flash_sound_played) {
balloon_manager_->reverseColorsToAllBalloons();
playSound("clock.wav");
color_flash_sound_played = true; // Evita que suene múltiples veces
}
} else {
// Fase normal - solo sonido ocasional
@@ -888,8 +900,12 @@ void Game::updateTimeStopped(float deltaTime) {
sound_timer = 0.0f;
}
}
} else {
disableTimeStopItem();
// Si el timer llega a 0 o menos, desactivar
if (time_stopped_timer_ <= 0) {
playSound("clock.wav"); // CLAC final
disableTimeStopItem();
}
}
}

View File

@@ -56,8 +56,8 @@ HiScoreTable::~HiScoreTable() {
void HiScoreTable::update(float delta_time) {
elapsed_time_ += delta_time; // Incrementa el tiempo transcurrido
static auto *screen = Screen::get();
screen->update(delta_time); // Actualiza el objeto screen
static auto *const SCREEN = Screen::get();
SCREEN->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
updateSprites(delta_time); // Actualiza las posiciones de los sprites de texto

View File

@@ -207,8 +207,8 @@ void Instructions::fillBackbuffer() {
void Instructions::update(float delta_time) {
elapsed_time_ += delta_time; // Incrementa el tiempo transcurrido
static auto *screen = Screen::get();
screen->update(delta_time); // Actualiza el objeto screen
static auto *const SCREEN = Screen::get();
SCREEN->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
updateSprites(); // Actualiza los sprites

View File

@@ -208,9 +208,9 @@ void Intro::switchText(int from_index, int to_index) {
// Actualiza las variables del objeto
void Intro::update(float delta_time) {
static auto *screen = Screen::get();
screen->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto Aud
static auto *const SCREEN = Screen::get();
SCREEN->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto Audio
tiled_bg_->update(delta_time); // Actualiza el fondo

View File

@@ -140,8 +140,8 @@ void Logo::updateTextureColors(float delta_time) {
void Logo::update(float delta_time) {
elapsed_time_s_ += delta_time; // Acumula el tiempo transcurrido
static auto *screen = Screen::get();
screen->update(delta_time); // Actualiza el objeto screen
static auto *const SCREEN = Screen::get();
SCREEN->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
handleSound(); // Maneja la reproducción del sonido

View File

@@ -46,7 +46,7 @@ Title::Title()
num_controllers_(Input::get()->getNumGamepads()) {
// Configura objetos
tiled_bg_->setColor(param.title.bg_color);
tiled_bg_->setSpeed(60.0F); // Set appropriate speed for seconds-based deltaTime
tiled_bg_->setSpeed(0.0F);
game_logo_->enable();
mini_logo_sprite_->setX(param.game.game_area.center_x - (mini_logo_sprite_->getWidth() / 2));
fade_->setColor(param.fade.color);
@@ -80,8 +80,8 @@ Title::~Title() {
// Actualiza las variables del objeto
void Title::update(float deltaTime) {
static auto* screen = Screen::get();
screen->update(deltaTime); // Actualiza el objeto screen
static auto *const SCREEN = Screen::get();
SCREEN->update(deltaTime); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
updateFade();
@@ -493,9 +493,12 @@ void Title::setState(State state) {
break;
case State::LOGO_FINISHED:
Audio::get()->playMusic("title.ogg");
tiled_bg_->changeSpeedTo(60.0F, 0.5F);
blink_accumulator_ = 0.0f; // Resetea el timer para empezar el parpadeo desde el inicio
break;
case State::START_HAS_BEEN_PRESSED:
Audio::get()->fadeOutMusic(MUSIC_FADE_OUT_LONG_MS);
blink_accumulator_ = 0.0f; // Resetea el timer para empezar el parpadeo desde el inicio
break;
}
}

View File

@@ -83,6 +83,7 @@ void TiledBG::render() {
// Actualiza la lógica de la clase (time-based)
void TiledBG::update(float delta_time) {
updateSpeedChange(delta_time);
updateDesp(delta_time);
updateStop(delta_time);
@@ -129,4 +130,40 @@ void TiledBG::updateStop(float delta_time) {
stopping_ = false; // Desactivamos el estado de "stopping"
}
}
}
// Cambia la velocidad gradualmente en X segundos
void TiledBG::changeSpeedTo(float target_speed, float duration_s) {
if (duration_s <= 0.0f) {
// Si la duración es 0 o negativa, cambia inmediatamente
speed_ = target_speed;
changing_speed_ = false;
return;
}
// Configurar el cambio gradual
changing_speed_ = true;
initial_speed_ = speed_;
target_speed_ = target_speed;
change_duration_s_ = duration_s;
change_timer_s_ = 0.0f;
}
// Actualiza el cambio gradual de velocidad (time-based)
void TiledBG::updateSpeedChange(float delta_time) {
if (!changing_speed_) {
return;
}
change_timer_s_ += delta_time;
if (change_timer_s_ >= change_duration_s_) {
// Cambio completado
speed_ = target_speed_;
changing_speed_ = false;
} else {
// Interpolación lineal entre velocidad inicial y objetivo
float progress = change_timer_s_ / change_duration_s_;
speed_ = initial_speed_ + (target_speed_ - initial_speed_) * progress;
}
}

View File

@@ -29,11 +29,13 @@ class TiledBG {
// --- Configuración ---
void setSpeed(float speed) { speed_ = speed; } // Establece la velocidad
void changeSpeedTo(float target_speed, float duration_s); // Cambia la velocidad gradualmente en X segundos
void stopGracefully() { stopping_ = true; } // Detiene el desplazamiento de forma ordenada
void setColor(Color color) { SDL_SetTextureColorMod(canvas_, color.r, color.g, color.b); } // Cambia el color de la textura
// --- Getters ---
[[nodiscard]] auto isStopped() const -> bool { return speed_ == 0.0F; } // Indica si está parado
[[nodiscard]] auto isChangingSpeed() const -> bool { return changing_speed_; } // Indica si está cambiando velocidad gradualmente
private:
// --- Constantes ---
@@ -56,8 +58,16 @@ class TiledBG {
float speed_ = 1.0F; // Incremento que se añade al desplazamiento a cada bucle
bool stopping_ = false; // Indica si se está deteniendo
// --- Variables para cambio gradual de velocidad ---
bool changing_speed_ = false; // Indica si está cambiando velocidad gradualmente
float initial_speed_ = 0.0F; // Velocidad inicial del cambio
float target_speed_ = 0.0F; // Velocidad objetivo del cambio
float change_duration_s_ = 0.0F; // Duración total del cambio en segundos
float change_timer_s_ = 0.0F; // Tiempo transcurrido del cambio
// --- Métodos internos ---
void fillTexture(); // Rellena la textura con el contenido
void updateDesp(float delta_time) { desp_ += speed_ * delta_time; } // Actualiza el desplazamiento (time-based)
void updateStop(float delta_time); // Detiene el desplazamiento de forma ordenada (time-based)
void updateSpeedChange(float delta_time); // Actualiza el cambio gradual de velocidad (time-based)
};

View File

@@ -107,8 +107,7 @@ void MenuRenderer::render(const ServiceMenu *menu_state) {
}
}
void MenuRenderer::update(const ServiceMenu *menu_state) {
float delta_time = 1.0F / 60.0F; // Asumiendo 60 FPS
void MenuRenderer::update(const ServiceMenu *menu_state, float delta_time) {
updateAnimations(delta_time);
if (visible_) {

View File

@@ -26,7 +26,7 @@ class MenuRenderer {
// --- Métodos principales de la vista ---
void render(const ServiceMenu *menu_state);
void update(const ServiceMenu *menu_state);
void update(const ServiceMenu *menu_state, float delta_time);
// --- Nuevos: Métodos de control de visibilidad y animación ---
void show(const ServiceMenu *menu_state);

View File

@@ -84,9 +84,9 @@ void ServiceMenu::render() {
}
}
void ServiceMenu::update() {
void ServiceMenu::update(float delta_time) {
// El renderer siempre se actualiza para manejar sus animaciones
renderer_->update(this);
renderer_->update(this, delta_time);
if (!enabled_) {
return;
@@ -98,10 +98,10 @@ void ServiceMenu::update() {
now_pending ? restart_message_ui_->show() : restart_message_ui_->hide();
last_pending_changes_ = now_pending;
}
restart_message_ui_->update();
restart_message_ui_->update(delta_time);
if (define_buttons_) {
define_buttons_->update();
define_buttons_->update(delta_time);
if (define_buttons_->isEnabled() && define_buttons_->isReadyToClose()) {
define_buttons_->disable();
}

View File

@@ -47,7 +47,7 @@ class ServiceMenu {
// --- Métodos principales ---
void toggle();
void render();
void update();
void update(float delta_time);
void reset();
// --- Lógica de navegación ---

View File

@@ -20,7 +20,7 @@ void UIMessage::show() {
start_y_ = DESP; // Empieza 8 píxeles arriba de la posición base
target_y_ = 0.0F; // La posición final es la base
y_offset_ = start_y_;
anim_step_ = 0;
animation_timer_ = 0.0f;
animating_ = true;
visible_ = true;
}
@@ -33,21 +33,26 @@ void UIMessage::hide() {
start_y_ = y_offset_; // Comienza desde la posición actual
target_y_ = DESP; // Termina 8 píxeles arriba de la base
anim_step_ = 0;
animation_timer_ = 0.0f;
animating_ = true;
}
// Actualiza el estado de la animación (debe llamarse cada frame)
void UIMessage::update() {
void UIMessage::update(float delta_time) {
if (animating_) {
updateAnimation();
updateAnimation(delta_time);
}
}
// Interpola la posición vertical del mensaje usando ease out cubic
void UIMessage::updateAnimation() {
anim_step_++;
float t = static_cast<float>(anim_step_) / ANIMATION_STEPS;
void UIMessage::updateAnimation(float delta_time) {
animation_timer_ += delta_time;
float t = animation_timer_ / ANIMATION_DURATION_S;
// Clamp t entre 0 y 1
if (t > 1.0f) {
t = 1.0f;
}
if (target_y_ > start_y_) {
// Animación de entrada (ease out cubic)
@@ -59,9 +64,10 @@ void UIMessage::updateAnimation() {
y_offset_ = start_y_ + (target_y_ - start_y_) * t;
if (anim_step_ >= ANIMATION_STEPS) {
if (animation_timer_ >= ANIMATION_DURATION_S) {
y_offset_ = target_y_;
animating_ = false;
animation_timer_ = 0.0f; // Reset timer
if (target_y_ < 0.0F) {
visible_ = false;
}

View File

@@ -20,7 +20,7 @@ class UIMessage {
void hide();
// Actualiza el estado de la animación (debe llamarse cada frame)
void update();
void update(float delta_time);
// Dibuja el mensaje en pantalla si está visible
void render();
@@ -45,12 +45,12 @@ class UIMessage {
float y_offset_ = 0.0F; // Desplazamiento vertical actual del mensaje (para animación)
// --- Animación ---
float start_y_ = 0.0F; // Posición Y inicial de la animación
float target_y_ = 0.0F; // Posición Y objetivo de la animación
int anim_step_ = 0; // Paso actual de la animación
static constexpr int ANIMATION_STEPS = 8; // Número total de pasos de la animación
static constexpr float DESP = -8.0F; // Distancia a desplazarse
float start_y_ = 0.0F; // Posición Y inicial de la animación
float target_y_ = 0.0F; // Posición Y objetivo de la animación
float animation_timer_ = 0.0F; // Timer actual de la animación en segundos
static constexpr float ANIMATION_DURATION_S = 0.133f; // Duración total de la animación (8 frames @ 60fps)
static constexpr float DESP = -8.0F; // Distancia a desplazarse
// Actualiza la interpolación de la animación (ease out/in cubic)
void updateAnimation();
void updateAnimation(float delta_time);
};

View File

@@ -76,12 +76,9 @@ void WindowMessage::render() {
}
}
void WindowMessage::update() {
void WindowMessage::update(float delta_time) {
// Actualizar animaciones
if (show_hide_animation_.active || resize_animation_.active) {
// Aquí necesitarías el delta_time del game loop
// Por ahora usamos un valor fijo, pero idealmente se pasaría como parámetro
float delta_time = 1.0F / 60.0F; // Asumiendo 60 FPS
updateAnimation(delta_time);
}
}

View File

@@ -73,7 +73,7 @@ class WindowMessage {
// Métodos principales
void render();
void update();
void update(float delta_time);
// Control de visibilidad
void show();