From 720d286dcf1765c1d65e100878f4af78c835d243 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 23 Sep 2025 09:11:29 +0200 Subject: [PATCH] revisat logo.cpp --- source/director.cpp | 2 +- source/sections/game.cpp | 2 +- source/sections/logo.cpp | 22 +++++++++++----------- source/sections/logo.h | 20 ++++++++++---------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index 525f3cf..3dc6a53 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::TITLE; + Section::name = Section::Name::LOGO; Section::options = Section::Options::GAME_PLAY_1P; #else // NORMAL GAME Section::name = Section::Name::LOGO; diff --git a/source/sections/game.cpp b/source/sections/game.cpp index 40ca07f..1d1e574 100644 --- a/source/sections/game.cpp +++ b/source/sections/game.cpp @@ -790,7 +790,7 @@ void Game::throwCoffee(int x, int y) { smart_sprites_.back()->setDestX(x + (smart_sprites_.back()->getVelX() * 50)); smart_sprites_.back()->setDestY(param.game.height + 1); smart_sprites_.back()->setEnabled(true); - smart_sprites_.back()->setFinishedCounter(1); + smart_sprites_.back()->setFinishedDelay(0.0F); smart_sprites_.back()->setSpriteClip(0, param.game.item_size, param.game.item_size, param.game.item_size); smart_sprites_.back()->setRotatingCenter({param.game.item_size / 2, param.game.item_size / 2}); smart_sprites_.back()->setRotate(true); diff --git a/source/sections/logo.cpp b/source/sections/logo.cpp index 73947c2..988651e 100644 --- a/source/sections/logo.cpp +++ b/source/sections/logo.cpp @@ -82,7 +82,7 @@ void Logo::checkInput() { void Logo::handleSound() { static bool sound_triggered = false; - if (!sound_triggered && elapsed_time_ms_ >= SOUND_TRIGGER_TIME_MS) { + if (!sound_triggered && elapsed_time_s_ >= SOUND_TRIGGER_TIME_S) { Audio::get()->playSound("logo.wav"); sound_triggered = true; } @@ -90,8 +90,8 @@ void Logo::handleSound() { // Gestiona el logo de JAILGAMES void Logo::updateJAILGAMES(float delta_time) { - if (elapsed_time_ms_ > SOUND_TRIGGER_TIME_MS) { - const float PIXELS_TO_MOVE = LOGO_SPEED_PX_PER_MS * delta_time; + if (elapsed_time_s_ > SOUND_TRIGGER_TIME_S) { + const float PIXELS_TO_MOVE = LOGO_SPEED_PX_PER_S * delta_time; for (size_t i = 0; i < jail_sprite_.size(); ++i) { if (jail_sprite_[i]->getX() != dest_.x) { @@ -111,7 +111,7 @@ void Logo::updateJAILGAMES(float delta_time) { } // Comprueba si ha terminado el logo - if (elapsed_time_ms_ >= END_LOGO_TIME_MS + POST_LOGO_DURATION_MS) { + if (elapsed_time_s_ >= END_LOGO_TIME_S + POST_LOGO_DURATION_S) { Section::name = Section::Name::INTRO; } } @@ -120,16 +120,16 @@ void Logo::updateJAILGAMES(float delta_time) { void Logo::updateTextureColors(float delta_time) { // Manejo de 'sinceTexture' for (int i = 0; i <= MAX_SINCE_COLOR_INDEX; ++i) { - const float target_time = SHOW_SINCE_SPRITE_TIME_MS + COLOR_CHANGE_INTERVAL_MS * i; - if (elapsed_time_ms_ >= target_time && elapsed_time_ms_ - delta_time < target_time) { + const float target_time = SHOW_SINCE_SPRITE_TIME_S + COLOR_CHANGE_INTERVAL_S * i; + if (elapsed_time_s_ >= target_time && elapsed_time_s_ - delta_time < target_time) { since_texture_->setColor(color_[i].r, color_[i].g, color_[i].b); } } // Manejo de 'jailTexture' y 'sinceTexture' en el fade for (int i = 0; i <= MAX_FADE_COLOR_INDEX; ++i) { - const float target_time = INIT_FADE_TIME_MS + COLOR_CHANGE_INTERVAL_MS * i; - if (elapsed_time_ms_ >= target_time && elapsed_time_ms_ - delta_time < target_time) { + const float target_time = INIT_FADE_TIME_S + COLOR_CHANGE_INTERVAL_S * i; + if (elapsed_time_s_ >= target_time && elapsed_time_s_ - delta_time < target_time) { jail_texture_->setColor(color_[MAX_FADE_COLOR_INDEX - i].r, color_[MAX_FADE_COLOR_INDEX - i].g, color_[MAX_FADE_COLOR_INDEX - i].b); since_texture_->setColor(color_[MAX_FADE_COLOR_INDEX - i].r, color_[MAX_FADE_COLOR_INDEX - i].g, color_[MAX_FADE_COLOR_INDEX - i].b); } @@ -138,7 +138,7 @@ void Logo::updateTextureColors(float delta_time) { // Actualiza las variables void Logo::update(float delta_time) { - elapsed_time_ms_ += delta_time; // Acumula el tiempo transcurrido + elapsed_time_s_ += delta_time; // Acumula el tiempo transcurrido Screen::get()->update(); // Actualiza el objeto screen Audio::update(); // Actualiza el objeto audio @@ -163,7 +163,7 @@ void Logo::render() { // Calcula el tiempo transcurrido desde el último frame float Logo::calculateDeltaTime() { const Uint64 current_time = SDL_GetTicks(); - const float delta_time = static_cast(current_time - last_time_); + const float delta_time = static_cast(current_time - last_time_) / 1000.0f; // Convertir ms a segundos last_time_ = current_time; return delta_time; } @@ -189,7 +189,7 @@ void Logo::renderJAILGAMES() { sprite->render(); } - if (elapsed_time_ms_ >= SHOW_SINCE_SPRITE_TIME_MS) { + if (elapsed_time_s_ >= SHOW_SINCE_SPRITE_TIME_S) { since_sprite_->render(); } } \ No newline at end of file diff --git a/source/sections/logo.h b/source/sections/logo.h index bb088ca..8632d5a 100644 --- a/source/sections/logo.h +++ b/source/sections/logo.h @@ -22,7 +22,7 @@ class Texture; // • Transición temporal: duración controlada con paso automático al siguiente estado // • Sistema delta-time: animaciones suaves independientes del framerate // -// La clase utiliza un sistema de tiempo basado en milisegundos para garantizar +// La clase utiliza un sistema de tiempo basado en segundos para garantizar // consistencia visual en diferentes velocidades de procesamiento. class Logo { @@ -35,14 +35,14 @@ class Logo { void run(); private: - // --- Constantes de tiempo (en milisegundos) --- - static constexpr float SOUND_TRIGGER_TIME_MS = 500.0f; // Tiempo para activar el sonido del logo - static constexpr float SHOW_SINCE_SPRITE_TIME_MS = 1167.0f; // Tiempo para mostrar el sprite "SINCE 1998" - static constexpr float INIT_FADE_TIME_MS = 5000.0f; // Tiempo de inicio del fade a negro - static constexpr float END_LOGO_TIME_MS = 6668.0f; // Tiempo de finalización del logo - static constexpr float POST_LOGO_DURATION_MS = 333.0f; // Duración adicional después del fade - static constexpr float LOGO_SPEED_PX_PER_MS = 8.0f / 16.67f; // Velocidad de desplazamiento (píxeles por ms) - static constexpr float COLOR_CHANGE_INTERVAL_MS = 66.7f; // Intervalo entre cambios de color (~4 frames a 60fps) + // --- Constantes de tiempo (en segundos) --- + static constexpr float SOUND_TRIGGER_TIME_S = 0.5f; // Tiempo para activar el sonido del logo + static constexpr float SHOW_SINCE_SPRITE_TIME_S = 1.167f; // Tiempo para mostrar el sprite "SINCE 1998" + static constexpr float INIT_FADE_TIME_S = 5.0f; // Tiempo de inicio del fade a negro + static constexpr float END_LOGO_TIME_S = 6.668f; // Tiempo de finalización del logo + static constexpr float POST_LOGO_DURATION_S = 0.333f; // Duración adicional después del fade + static constexpr float LOGO_SPEED_PX_PER_S = 480.0f; // Velocidad de desplazamiento (píxeles por segundo) - 8.0f/16.67f*1000 + static constexpr float COLOR_CHANGE_INTERVAL_S = 0.0667f; // Intervalo entre cambios de color (~4 frames a 60fps) // --- Constantes de layout --- static constexpr int SINCE_SPRITE_Y_OFFSET = 83; // Posición Y base del sprite "Since 1998" @@ -73,7 +73,7 @@ class Logo { // --- Variables --- std::vector color_; // Vector con los colores para el fade - float elapsed_time_ms_ = 0.0f; // Tiempo transcurrido en milisegundos + float elapsed_time_s_ = 0.0f; // Tiempo transcurrido en segundos Uint64 last_time_ = 0; // Último timestamp para calcular delta-time SDL_FPoint dest_; // Posición donde dibujar el logo