From 5ccd7eebcdcc9052574a7539447c5962f7a3d933 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 12 Mar 2025 10:06:38 +0100 Subject: [PATCH] Afegit param.game.speed i retocats els update() de les seccions --- source/credits.cpp | 9 +- source/game.cpp | 4 +- source/hiscore_table.cpp | 78 +++--- source/hiscore_table.h | 6 + source/instructions.cpp | 75 +++--- source/instructions.h | 6 + source/intro.cpp | 508 ++++++++++++++++++++------------------- source/intro.h | 6 + source/logo.cpp | 4 +- source/param.cpp | 1 + source/param.h | 3 +- source/title.cpp | 171 +++++++------ source/title.h | 6 + 13 files changed, 471 insertions(+), 406 deletions(-) diff --git a/source/credits.cpp b/source/credits.cpp index 34823ea..e903cd8 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -87,13 +87,11 @@ void Credits::run() // Actualiza las variables void Credits::update() { - constexpr Uint32 TICKS_SPEED_ = 15; - - if (SDL_GetTicks() - ticks_ > TICKS_SPEED_) + if (SDL_GetTicks() - ticks_ > param.game.speed) { ticks_ = SDL_GetTicks(); - const int repeat = want_to_pass_ ? 4 : 1; - for (int i = 0; i < repeat; ++i) + const int REPEAT = want_to_pass_ ? 4 : 1; + for (int i = 0; i < REPEAT; ++i) { tiled_bg_->update(); balloon_manager_->update(); @@ -106,6 +104,7 @@ void Credits::update() updateAllFades(); ++counter_; } + Screen::get()->update(); globalInputs::update(); diff --git a/source/game.cpp b/source/game.cpp index 4f95a1b..906311d 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -957,9 +957,7 @@ void Game::updateTimeStopped() // Actualiza el juego void Game::update() { - constexpr int TICKS_SPEED = 15; - - if (SDL_GetTicks() - ticks_ > TICKS_SPEED) + if (SDL_GetTicks() - ticks_ > param.game.speed) { ticks_ = SDL_GetTicks(); diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index c7c644f..c40e371 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -15,7 +15,7 @@ #include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state #include "lang.h" // Para getText #include "manage_hiscore_table.h" // Para HiScoreEntry -#include "global_events.h" // Para handleEvent +#include "global_events.h" // Para handleEvent #include "options.h" // Para Options, OptionsGame, options #include "param.h" // Para Param, param, ParamGame, ParamFade #include "path_sprite.h" // Para PathSprite, Path, PathType @@ -58,28 +58,17 @@ HiScoreTable::~HiScoreTable() // Actualiza las variables void HiScoreTable::update() { - constexpr int TICKS_SPEED = 15; - - if (SDL_GetTicks() - ticks_ > TICKS_SPEED) + if (SDL_GetTicks() - ticks_ > param.game.speed) { // Actualiza el contador de ticks ticks_ = SDL_GetTicks(); // Mantiene la música sonando - if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) - { - JA_PlayMusic(Resource::get()->getMusic("title.ogg")); - } + updateMusic(); // Actualiza las posiciones de los sprites de texto updateSprites(); - // Actualiza el objeto screen - Screen::get()->update(); - - // Actualiza las variables de globalInputs - globalInputs::update(); - // Actualiza el fondo background_->update(); @@ -87,21 +76,16 @@ void HiScoreTable::update() updateFade(); // Gestiona el contador y sus eventos - counter_++; - - if (counter_ == 150) - { - background_->setColor(background_fade_color_.darken()); - background_->setAlpha(96); - } - - if (counter_ == COUNTER_END_) - { - fade_->activate(); - } + updateCounter(); // Dibuja los sprites en la textura fillTexture(); + + // Actualiza el objeto screen + Screen::get()->update(); + + // Actualiza las variables de globalInputs + globalInputs::update(); } } @@ -421,12 +405,38 @@ void HiScoreTable::iniEntryColors() // Hace brillar los nombres de la tabla de records void HiScoreTable::glowEntryNames() { - const Color entry_color = getEntryColor(counter_ / 5); - for (const auto& entry_index : options.game.last_hi_score_entry) - { - if (entry_index != -1) - { - entry_names_.at(entry_index)->getTexture()->setColor(entry_color); - } - } + const Color entry_color = getEntryColor(counter_ / 5); + for (const auto &entry_index : options.game.last_hi_score_entry) + { + if (entry_index != -1) + { + entry_names_.at(entry_index)->getTexture()->setColor(entry_color); + } + } } + +// Gestiona la musica +void HiScoreTable::updateMusic() +{ + if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) + { + JA_PlayMusic(Resource::get()->getMusic("title.ogg")); + } +} + +// Gestiona el contador +void HiScoreTable::updateCounter() +{ + counter_++; + + if (counter_ == 150) + { + background_->setColor(background_fade_color_.darken()); + background_->setAlpha(96); + } + + if (counter_ == COUNTER_END_) + { + fade_->activate(); + } +} \ No newline at end of file diff --git a/source/hiscore_table.h b/source/hiscore_table.h index 1b4661b..46d8dac 100644 --- a/source/hiscore_table.h +++ b/source/hiscore_table.h @@ -91,6 +91,12 @@ private: // Hace brillar los nombres de la tabla de records void glowEntryNames(); + // Gestiona la musica + void updateMusic(); + + // Gestiona el contador + void updateCounter(); + public: // Constructor HiScoreTable(); diff --git a/source/instructions.cpp b/source/instructions.cpp index b8a1001..3e23139 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -207,18 +207,13 @@ void Instructions::fillBackbuffer() // Actualiza las variables void Instructions::update() { - constexpr int TICKS_SPEED = 15; - - if (SDL_GetTicks() - ticks_ > TICKS_SPEED) + if (SDL_GetTicks() - ticks_ > param.game.speed) { // Actualiza el contador de ticks ticks_ = SDL_GetTicks(); // Mantiene la música sonando - if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) - { - JA_PlayMusic(Resource::get()->getMusic("title.ogg")); - } + updateMusic(); // Actualiza el objeto screen Screen::get()->update(); @@ -232,24 +227,8 @@ void Instructions::update() // Actualiza los sprites updateSprites(); - // Establece la ventana del backbuffer - view_.y = std::max(0, param.game.height - counter_ + 100); - - // Verifica si view_.y == 0 y gestiona el temporizador - if (view_.y == 0) - { - if (!start_delay_triggered_) - { - // Activa el temporizador si no ha sido activado - start_delay_triggered_ = true; - start_delay_time_ = SDL_GetTicks(); - } - else if (SDL_GetTicks() - start_delay_time_ >= 4000) - { - // Han pasado tres segundos, mover líneas - all_lines_off_screen_ = moveLines(lines_, 320, 1.0f, 5); - } - } + // Gestiona la textura con los graficos + updateBackbuffer(); // Actualiza el mosaico de fondo tiled_bg_->update(); @@ -259,13 +238,6 @@ void Instructions::update() // Rellena el backbuffer fillBackbuffer(); - - // Comprueba si el contador ha llegado al final - if (all_lines_off_screen_) - { - section::name = section::Name::TITLE; - section::options = section::Options::TITLE_1; - } } } @@ -376,4 +348,43 @@ void Instructions::renderLines(SDL_Renderer *renderer, SDL_Texture *texture, con SDL_Rect dstRect = {static_cast(line.x), line.y, 320, 1}; SDL_RenderCopy(renderer, texture, &srcRect, &dstRect); } +} + +// Gestiona la musica +void Instructions::updateMusic() +{ + if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) + { + JA_PlayMusic(Resource::get()->getMusic("title.ogg")); + } +} + +// Gestiona la textura con los graficos +void Instructions::updateBackbuffer() +{ + // Establece la ventana del backbuffer + view_.y = std::max(0, param.game.height - counter_ + 100); + + // Verifica si view_.y == 0 y gestiona el temporizador + if (view_.y == 0) + { + if (!start_delay_triggered_) + { + // Activa el temporizador si no ha sido activado + start_delay_triggered_ = true; + start_delay_time_ = SDL_GetTicks(); + } + else if (SDL_GetTicks() - start_delay_time_ >= 4000) + { + // Han pasado tres segundos, mover líneas + all_lines_off_screen_ = moveLines(lines_, 320, 1.0f, 5); + } + } + + // Comprueba si el contador ha llegado al final + if (all_lines_off_screen_) + { + section::name = section::Name::TITLE; + section::options = section::Options::TITLE_1; + } } \ No newline at end of file diff --git a/source/instructions.h b/source/instructions.h index 452702a..4c6a2f4 100644 --- a/source/instructions.h +++ b/source/instructions.h @@ -96,6 +96,12 @@ private: // Método para renderizar las líneas void renderLines(SDL_Renderer *renderer, SDL_Texture *texture, const std::vector &lines); + // Gestiona la musica + void updateMusic(); + + // Gestiona la textura con los graficos + void updateBackbuffer(); + public: // Constructor Instructions(); diff --git a/source/intro.cpp b/source/intro.cpp index 673a009..9a33fc2 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -26,6 +26,263 @@ Intro::Intro() section::name = section::Name::INTRO; section::options = section::Options::NONE; + // Inicializa las imagens + initSprites(); + + // Inicializa los textos + initTexts(); +} + +// Comprueba los eventos +void Intro::checkEvents() +{ + SDL_Event event; + while (SDL_PollEvent(&event)) + { + globalEvents::check(event); + } +} + +// Comprueba las entradas +void Intro::checkInput() { globalInputs::check(); } + +// Actualiza las escenas de la intro +void Intro::updateScenes() +{ + switch (scene_) + { + case 1: + { + // Primera imagen - UPV + if (!bitmaps_[0]->hasFinished()) + { + bitmaps_[0]->setEnabled(true); + } + + // Primer texto de la primera imagen + if (bitmaps_[0]->hasFinished() && !texts_[0]->hasFinished()) + { + texts_[0]->setEnabled(true); + } + + // Segundo texto de la primera imagen + if (texts_[0]->hasFinished() && !texts_[1]->hasFinished()) + { + texts_[0]->setEnabled(false); + texts_[1]->setEnabled(true); + } + + // Tercer texto de la primera imagen + if (texts_[1]->hasFinished() && !texts_[2]->hasFinished()) + { + texts_[1]->setEnabled(false); + texts_[2]->setEnabled(true); + } + + // Fin de la primera escena + if (texts_[2]->hasFinished()) + { + bitmaps_[0]->setEnabled(false); + texts_[2]->setEnabled(false); + scene_++; + } + + break; + } + + case 2: + { + // Segunda imagen - Máquina + if (!bitmaps_[1]->hasFinished()) + { + bitmaps_[1]->setEnabled(true); + } + + // Primer texto de la segunda imagen + if (bitmaps_[1]->hasFinished() && !texts_[3]->hasFinished()) + { + texts_[3]->setEnabled(true); + } + + // Fin de la segunda escena + if (texts_[3]->hasFinished()) + { + bitmaps_[1]->setEnabled(false); + texts_[3]->setEnabled(false); + scene_++; + } + + break; + } + case 3: + { + // Tercera imagen junto con primer texto - GRITO + if (!bitmaps_[2]->hasFinished() && !texts_[4]->hasFinished()) + { + bitmaps_[2]->setEnabled(true); + texts_[4]->setEnabled(true); + } + + // Fin de la tercera escena + if (bitmaps_[2]->hasFinished() && texts_[4]->hasFinished()) + { + bitmaps_[2]->setEnabled(false); + texts_[4]->setEnabled(false); + scene_++; + } + + break; + } + + case 4: + { + // Cuarta imagen junto con primer texto - Reflexión + if (!bitmaps_[3]->hasFinished() && !texts_[5]->hasFinished()) + { + bitmaps_[3]->setEnabled(true); + texts_[5]->setEnabled(true); + } + + // Segundo texto de la cuarta imagen + if (texts_[5]->hasFinished() && !texts_[6]->hasFinished()) + { + texts_[5]->setEnabled(false); + texts_[6]->setEnabled(true); + } + + // Fin de la cuarta escena + if (bitmaps_[3]->hasFinished() && texts_[6]->hasFinished()) + { + bitmaps_[3]->setEnabled(false); + texts_[6]->setEnabled(false); + scene_++; + } + + break; + } + + case 5: + { + // Quinta imagen - Patada + if (!bitmaps_[4]->hasFinished()) + { + bitmaps_[4]->setEnabled(true); + } + + // Primer texto de la quinta imagen + if (bitmaps_[4]->hasFinished() && !texts_[7]->hasFinished()) + { + texts_[7]->setEnabled(true); + } + + // Fin de la quinta escena + if (bitmaps_[4]->hasFinished() && texts_[7]->hasFinished()) + { + bitmaps_[4]->setEnabled(false); + texts_[7]->setEnabled(false); + scene_++; + } + + break; + } + + case 6: + { + // Sexta imagen junto con texto - Globos de café + if (!bitmaps_[5]->hasFinished() && !texts_[8]->hasFinished()) + { + bitmaps_[5]->setEnabled(true); + texts_[8]->setEnabled(true); + } + + // Acaba el último texto + if (bitmaps_[5]->hasFinished() && texts_[8]->hasFinished()) + { + bitmaps_[5]->setEnabled(false); + texts_[8]->setEnabled(false); + JA_StopMusic(); + section::name = section::Name::TITLE; + section::options = section::Options::TITLE_1; + } + + break; + } + + default: + break; + } +} + +// Actualiza las variables del objeto +void Intro::update() +{ + if (SDL_GetTicks() - ticks_ > param.game.speed) + { + // Actualiza el contador de ticks + ticks_ = SDL_GetTicks(); + + // Actualiza el objeto screen + Screen::get()->update(); + + // Actualiza los objetos + for (auto &bitmap : bitmaps_) + { + bitmap->update(); + } + + for (auto &text : texts_) + { + text->update(); + } + + // Actualiza las escenas de la intro + updateScenes(); + + // Actualiza las variables de globalInputs + globalInputs::update(); + } +} + +// Dibuja el objeto en pantalla +void Intro::render() +{ + // Prepara para empezar a dibujar en la textura de juego + Screen::get()->start(); + + // Limpia la pantalla + Screen::get()->clean(bg_color); + + // Dibuja los objetos + for (const auto &bitmap : bitmaps_) + { + bitmap->render(); + } + + for (const auto &text : texts_) + { + text->render(); + } + + // Vuelca el contenido del renderizador en pantalla + Screen::get()->render(); +} + +// Bucle principal +void Intro::run() +{ + JA_PlayMusic(Resource::get()->getMusic("intro.ogg"), 0); + while (section::name == section::Name::INTRO) + { + checkInput(); + update(); + checkEvents(); // Tiene que ir antes del render + render(); + } +} + +// Inicializa las imagens +void Intro::initSprites() +{ const std::array BITMAP_LIST = { "intro1.png", "intro2.png", @@ -94,8 +351,11 @@ Intro::Intro() bitmaps_.at(5)->setVelY(0.0f); bitmaps_.at(5)->setAccelX(0.0f); bitmaps_.at(5)->setAccelY(0.0f); +} - // Inicializa los textos de la intro +// Inicializa los textos +void Intro::initTexts() +{ constexpr int TOTAL_TEXTS = 9; for (int i = 0; i < TOTAL_TEXTS; ++i) { @@ -148,250 +408,4 @@ Intro::Intro() { text->center(param.game.game_area.center_x); } -} - -// Comprueba los eventos -void Intro::checkEvents() -{ - SDL_Event event; - while (SDL_PollEvent(&event)) - { - globalEvents::check(event); - } -} - -// Comprueba las entradas -void Intro::checkInput() -{ - globalInputs::check(); -} - -// Actualiza las escenas de la intro -void Intro::updateScenes() -{ - switch (scene_) - { - case 1: - { // Primera imagen - UPV - if (!bitmaps_[0]->hasFinished()) - { - bitmaps_[0]->setEnabled(true); - } - - // Primer texto de la primera imagen - if (bitmaps_[0]->hasFinished() && !texts_[0]->hasFinished()) - { - texts_[0]->setEnabled(true); - } - - // Segundo texto de la primera imagen - if (texts_[0]->hasFinished() && !texts_[1]->hasFinished()) - { - texts_[0]->setEnabled(false); - texts_[1]->setEnabled(true); - } - - // Tercer texto de la primera imagen - if (texts_[1]->hasFinished() && !texts_[2]->hasFinished()) - { - texts_[1]->setEnabled(false); - texts_[2]->setEnabled(true); - } - - // Fin de la primera escena - if (texts_[2]->hasFinished()) - { - bitmaps_[0]->setEnabled(false); - texts_[2]->setEnabled(false); - scene_++; - } - - break; - } - - case 2: - { // Segunda imagen - Máquina - if (!bitmaps_[1]->hasFinished()) - { - bitmaps_[1]->setEnabled(true); - } - - // Primer texto de la segunda imagen - if (bitmaps_[1]->hasFinished() && !texts_[3]->hasFinished()) - { - texts_[3]->setEnabled(true); - } - - // Fin de la segunda escena - if (texts_[3]->hasFinished()) - { - bitmaps_[1]->setEnabled(false); - texts_[3]->setEnabled(false); - scene_++; - } - - break; - } - case 3: - { // Tercera imagen junto con primer texto - GRITO - if (!bitmaps_[2]->hasFinished() && !texts_[4]->hasFinished()) - { - bitmaps_[2]->setEnabled(true); - texts_[4]->setEnabled(true); - } - - // Fin de la tercera escena - if (bitmaps_[2]->hasFinished() && texts_[4]->hasFinished()) - { - bitmaps_[2]->setEnabled(false); - texts_[4]->setEnabled(false); - scene_++; - } - - break; - } - - case 4: - { // Cuarta imagen junto con primer texto - Reflexión - if (!bitmaps_[3]->hasFinished() && !texts_[5]->hasFinished()) - { - bitmaps_[3]->setEnabled(true); - texts_[5]->setEnabled(true); - } - - // Segundo texto de la cuarta imagen - if (texts_[5]->hasFinished() && !texts_[6]->hasFinished()) - { - texts_[5]->setEnabled(false); - texts_[6]->setEnabled(true); - } - - // Fin de la cuarta escena - if (bitmaps_[3]->hasFinished() && texts_[6]->hasFinished()) - { - bitmaps_[3]->setEnabled(false); - texts_[6]->setEnabled(false); - scene_++; - } - - break; - } - - case 5: - { // Quinta imagen - Patada - if (!bitmaps_[4]->hasFinished()) - { - bitmaps_[4]->setEnabled(true); - } - - // Primer texto de la quinta imagen - if (bitmaps_[4]->hasFinished() && !texts_[7]->hasFinished()) - { - texts_[7]->setEnabled(true); - } - - // Fin de la quinta escena - if (bitmaps_[4]->hasFinished() && texts_[7]->hasFinished()) - { - bitmaps_[4]->setEnabled(false); - texts_[7]->setEnabled(false); - scene_++; - } - - break; - } - - case 6: - { // Sexta imagen junto con texto - Globos de café - if (!bitmaps_[5]->hasFinished() && !texts_[8]->hasFinished()) - { - bitmaps_[5]->setEnabled(true); - texts_[8]->setEnabled(true); - } - - // Acaba el último texto - if (bitmaps_[5]->hasFinished() && texts_[8]->hasFinished()) - { - bitmaps_[5]->setEnabled(false); - texts_[8]->setEnabled(false); - JA_StopMusic(); - section::name = section::Name::TITLE; - section::options = section::Options::TITLE_1; - } - - break; - } - - default: - break; - } -} - -// Actualiza las variables del objeto -void Intro::update() -{ - constexpr int TICKS_SPEED = 15; - - if (SDL_GetTicks() - ticks_ > TICKS_SPEED) - { - // Actualiza el contador de ticks - ticks_ = SDL_GetTicks(); - - // Actualiza el objeto screen - Screen::get()->update(); - - // Actualiza los objetos - for (auto &bitmap : bitmaps_) - { - bitmap->update(); - } - - for (auto &text : texts_) - { - text->update(); - } - - // Actualiza las escenas de la intro - updateScenes(); - - // Actualiza las variables de globalInputs - globalInputs::update(); - } -} - -// Dibuja el objeto en pantalla -void Intro::render() -{ - // Prepara para empezar a dibujar en la textura de juego - Screen::get()->start(); - - // Limpia la pantalla - Screen::get()->clean(bg_color); - - // Dibuja los objetos - for (const auto &bitmap : bitmaps_) - { - bitmap->render(); - } - - for (const auto &text : texts_) - { - text->render(); - } - - // Vuelca el contenido del renderizador en pantalla - Screen::get()->render(); -} - -// Bucle principal -void Intro::run() -{ - JA_PlayMusic(Resource::get()->getMusic("intro.ogg"), 0); - while (section::name == section::Name::INTRO) - { - checkInput(); - update(); - checkEvents(); // Tiene que ir antes del render - render(); - } } \ No newline at end of file diff --git a/source/intro.h b/source/intro.h index 8454381..ce9cd68 100644 --- a/source/intro.h +++ b/source/intro.h @@ -40,6 +40,12 @@ private: // Actualiza las escenas de la intro void updateScenes(); + // Inicializa las imagens + void initSprites(); + + // Inicializa los textos + void initTexts(); + public: // Constructor Intro(); diff --git a/source/logo.cpp b/source/logo.cpp index 40eeba3..48758a3 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -154,9 +154,7 @@ void Logo::updateTextureColors() // Actualiza las variables void Logo::update() { - constexpr int TICKS_SPEED = 15; - - if (SDL_GetTicks() - ticks_ > TICKS_SPEED) + if (SDL_GetTicks() - ticks_ > param.game.speed) { // Actualiza el contador de ticks ticks_ = SDL_GetTicks(); diff --git a/source/param.cpp b/source/param.cpp index 56cfee9..75b7c33 100644 --- a/source/param.cpp +++ b/source/param.cpp @@ -26,6 +26,7 @@ void initParam() param.game.game_area.rect = {0, 0, param.game.width, param.game.height}; param.game.play_area.rect = {0, 0, param.game.width, 216}; param.game.enter_name_seconds = 30; + param.game.speed = 15; precalculateZones(); // SCOREBOARD diff --git a/source/param.h b/source/param.h index 1e51729..345a81e 100644 --- a/source/param.h +++ b/source/param.h @@ -16,6 +16,7 @@ struct ParamGame Zone play_area; // Rectangulo con la posición de la zona de juego Zone game_area; // Rectangulo con las dimensiones del juego int enter_name_seconds; // Duración en segundos para introducir el nombre al finalizar la partida + Uint32 speed; // Velocidad a la que transcurre el juego }; // param.fade @@ -83,7 +84,5 @@ struct Param extern Param param; -extern Param param; - // Establece valores para los parametros a partir de un fichero de texto void loadParamsFromFile(const std::string &file_path); \ No newline at end of file diff --git a/source/title.cpp b/source/title.cpp index a09d8a6..1093819 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -61,95 +61,22 @@ Title::~Title() // Actualiza las variables del objeto void Title::update() { - constexpr int TICKS_SPEED = 15; - - if (SDL_GetTicks() - ticks_ > TICKS_SPEED) + if (SDL_GetTicks() - ticks_ > param.game.speed) { // Actualiza el contador de ticks_ ticks_ = SDL_GetTicks(); + // Actualiza el fade + updateFade(); + + // Actualiza el estado + updateState(); + // Actualiza el objeto screen Screen::get()->update(); // Actualiza las variables de globalInputs globalInputs::update(); - - // Comprueba el fundido - fade_->update(); - if (fade_->hasEnded()) - { - if (selection_ == section::Options::TITLE_TIME_OUT) - { - // El menu ha hecho time out - section::name = next_section_; - } - else - { - // Se ha pulsado para jugar - section::name = section::Name::GAME; - section::options = selection_; - JA_StopMusic(); - } - } - - // Establece la lógica según el estado - switch (state_) - { - case TitleState::LOGO_ANIMATING: - { - game_logo_->update(); - if (game_logo_->hasFinished()) - { - state_ = TitleState::LOGO_FINISHED; - } - break; - } - case TitleState::LOGO_FINISHED: - { - // El contador solo sube si no estamos definiendo botones - counter_ = define_buttons_->isEnabled() ? 0 : counter_ + 1; - - // Reproduce la música - if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) - { - JA_PlayMusic(Resource::get()->getMusic("title.ogg")); - } - - // Actualiza el logo con el título del juego - game_logo_->update(); - - // Actualiza el mosaico de fondo - tiled_bg_->update(); - - if (counter_ == param.title.title_duration) - { - // El menu ha hecho time out - fade_->setPostDuration(0); - fade_->activate(); - selection_ = section::Options::TITLE_TIME_OUT; - } - - break; - } - case TitleState::START_HAS_BEEN_PRESSED: - { - // Actualiza el logo con el título del juego - game_logo_->update(); - - // Actualiza el mosaico de fondo - tiled_bg_->update(); - - if (counter_ == 100) - { - fade_->activate(); - } - ++counter_; - break; - } - - default: - break; - } } } @@ -379,3 +306,87 @@ void Title::showControllers() // Muestra la notificación Notifier::get()->show({text.at(0), text.at(1)}); } + +// Actualiza el fade +void Title::updateFade() +{ + fade_->update(); + if (fade_->hasEnded()) + { + if (selection_ == section::Options::TITLE_TIME_OUT) + { + // El menu ha hecho time out + section::name = next_section_; + } + else + { + // Se ha pulsado para jugar + section::name = section::Name::GAME; + section::options = selection_; + JA_StopMusic(); + } + } +} + +// Actualiza el estado +void Title::updateState() +{ + // Establece la lógica según el estado + switch (state_) + { + case TitleState::LOGO_ANIMATING: + { + game_logo_->update(); + if (game_logo_->hasFinished()) + { + state_ = TitleState::LOGO_FINISHED; + } + break; + } + case TitleState::LOGO_FINISHED: + { + // El contador solo sube si no estamos definiendo botones + counter_ = define_buttons_->isEnabled() ? 0 : counter_ + 1; + + // Reproduce la música + if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) + { + JA_PlayMusic(Resource::get()->getMusic("title.ogg")); + } + + // Actualiza el logo con el título del juego + game_logo_->update(); + + // Actualiza el mosaico de fondo + tiled_bg_->update(); + + if (counter_ == param.title.title_duration) + { + // El menu ha hecho time out + fade_->setPostDuration(0); + fade_->activate(); + selection_ = section::Options::TITLE_TIME_OUT; + } + + break; + } + case TitleState::START_HAS_BEEN_PRESSED: + { + // Actualiza el logo con el título del juego + game_logo_->update(); + + // Actualiza el mosaico de fondo + tiled_bg_->update(); + + if (counter_ == 100) + { + fade_->activate(); + } + ++counter_; + break; + } + + default: + break; + } +} \ No newline at end of file diff --git a/source/title.h b/source/title.h index f0cf3a5..cee2ec4 100644 --- a/source/title.h +++ b/source/title.h @@ -84,6 +84,12 @@ private: // Muestra información sobre los controles y los jugadores void showControllers(); + // Actualiza el fade + void updateFade(); + + // Actualiza el estado + void updateState(); + public: // Constructor Title();