diff --git a/source/director.cpp b/source/director.cpp index 31055e2..525f3cf 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -42,7 +42,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::GAME; + Section::name = Section::Name::TITLE; Section::options = Section::Options::GAME_PLAY_1P; #else // NORMAL GAME Section::name = Section::Name::LOGO; diff --git a/source/sections/title.cpp b/source/sections/title.cpp index f04f784..26878e1 100644 --- a/source/sections/title.cpp +++ b/source/sections/title.cpp @@ -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); @@ -493,6 +493,7 @@ void Title::setState(State state) { break; case State::LOGO_FINISHED: Audio::get()->playMusic("title.ogg"); + tiled_bg_->changeSpeedTo(60.0F, 1.0F); break; case State::START_HAS_BEEN_PRESSED: Audio::get()->fadeOutMusic(MUSIC_FADE_OUT_LONG_MS); diff --git a/source/tiled_bg.cpp b/source/tiled_bg.cpp index 1935c8e..13bf19b 100644 --- a/source/tiled_bg.cpp +++ b/source/tiled_bg.cpp @@ -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; + } } \ No newline at end of file diff --git a/source/tiled_bg.h b/source/tiled_bg.h index 99cd876..fe4e230 100644 --- a/source/tiled_bg.h +++ b/source/tiled_bg.h @@ -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) }; \ No newline at end of file