From 45ed1106cb67439d3edae70519952f3ec1a81c94 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 14 Aug 2024 08:38:19 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20ja=20torna=20a=20funcionar=20el=20cicle?= =?UTF-8?q?=20de=20m=C3=BAsica=20per=20les=20diferents=20seccions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/director.cpp | 4 ++-- source/game.cpp | 27 +++++++++++++-------------- source/game.h | 2 +- source/hiscore_table.cpp | 8 +++++++- source/hiscore_table.h | 3 ++- source/instructions.cpp | 9 ++++++++- source/instructions.h | 3 ++- 7 files changed, 35 insertions(+), 21 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index 2e168b3..efd069a 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -869,7 +869,7 @@ void Director::runGame() // Ejecuta la sección donde se muestran las instrucciones void Director::runInstructions() { - instructions = new Instructions(screen, asset, input, lang, param, section); + instructions = new Instructions(screen, asset, input, lang, param, section, getMusic(musics, "title.ogg")); instructions->run(); delete instructions; } @@ -877,7 +877,7 @@ void Director::runInstructions() // Ejecuta la sección donde se muestra la tabla de puntuaciones void Director::runHiScoreTable() { - hiScoreTable = new HiScoreTable(screen, asset, input, lang, param, options, section); + hiScoreTable = new HiScoreTable(screen, asset, input, lang, param, options, section, getMusic(musics, "title.ogg")); hiScoreTable->run(); delete hiScoreTable; } diff --git a/source/game.cpp b/source/game.cpp index f3ca0dc..7353f82 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -973,7 +973,7 @@ void Game::renderPlayers() } } -// Actualiza las variables de la fase +// Comprueba si hay cambio de fase y actualiza las variables void Game::updateStage() { if (currentPower >= enemyFormations->getStage(currentStage).powerToComplete) @@ -1957,7 +1957,7 @@ void Game::update() #endif // Comprueba si la música ha de estar sonando - // checkMusicStatus(); + checkMusicStatus(); // Actualiza el objeto screen screen->update(); @@ -1977,6 +1977,7 @@ void Game::update() // Mueve los globos updateBalloons(); + // Actualiza el objeto encargado de las explosiones explosions->update(); // Mueve las balas @@ -1985,7 +1986,7 @@ void Game::update() // Actualiza los items updateItems(); - // Actualiza el valor de currentStage + // Comprueba si hay cambio de fase y actualiza las variables updateStage(); // Actualiza el estado de muerte @@ -2101,9 +2102,9 @@ void Game::render() renderSeparator(); #ifdef DEBUG - text->write(0, 0, boolToString(players[0]->isAlive())); - text->write(0, 10, boolToString(players[1]->isAlive())); - text->write(0, 20, "POLLA"); + //text->write(0, 0, "P1 ALIVE: " + boolToString(players[0]->isAlive())); + //text->write(0, 10, "P2 ALIVE: " + boolToString(players[1]->isAlive())); + //text->write(0, 20, "ALL DEAD: " + boolToString(allPlayersAreDead())); #endif // Dibuja el fade @@ -2453,14 +2454,8 @@ void Game::checkMusicStatus() // Si la música no está sonando if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) { - // Reproduce la música - if (!gameCompleted) - { - if (!allPlayersAreDead()) - { - JA_PlayMusic(music); - } - } + // Si se ha completado el juego o los jugadores estan mujertos, detiene la música + gameCompleted || allPlayersAreDead() ? JA_StopMusic() : JA_PlayMusic(music); } } @@ -2482,6 +2477,10 @@ void Game::run() { JA_EnableSound(options->audio.sound.enabled); } + else + { + JA_StopMusic(); + } } // Indica si se puede crear una powerball diff --git a/source/game.h b/source/game.h index 9fd60d4..a5ff6a2 100644 --- a/source/game.h +++ b/source/game.h @@ -248,7 +248,7 @@ private: // Dibuja a los jugadores void renderPlayers(); - // Actualiza las variables de la fase + // Comprueba si hay cambio de fase y actualiza las variables void updateStage(); // Actualiza el estado de muerte diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index 4cf8ad1..074234a 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -2,7 +2,7 @@ #include // Constructor -HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section) +HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section, JA_Music_t *music) { // Copia punteros this->screen = screen; @@ -12,6 +12,7 @@ HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, Lang *lan this->section = section; this->options = options; this->param = param; + this->music = music; renderer = screen->getRenderer(); // Objetos @@ -68,6 +69,10 @@ void HiScoreTable::update() // 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(music); + // Actualiza el objeto screen screen->update(); @@ -77,6 +82,7 @@ void HiScoreTable::update() // Gestiona el fade updateFade(); + // Gestiona el contador y sus eventos counter++; if (counter == 150) diff --git a/source/hiscore_table.h b/source/hiscore_table.h index da271a5..1a9c327 100644 --- a/source/hiscore_table.h +++ b/source/hiscore_table.h @@ -38,6 +38,7 @@ private: Lang *lang; // Objeto para gestionar los textos en diferentes idiomas Fade *fade; // Objeto para renderizar fades Text *text; // Objeto para escribir texto + JA_Music_t *music; // Musica de fondo options_t *options; // Opciones y parametros del programa section_t *section; // Estado del bucle principal para saber si continua o se sale param_t *param; // Puntero con todos los parametros del programa @@ -79,7 +80,7 @@ private: public: // Constructor - HiScoreTable(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section); + HiScoreTable(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section, JA_Music_t *music); // Destructor ~HiScoreTable(); diff --git a/source/instructions.cpp b/source/instructions.cpp index 579ed20..c2865d7 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -2,7 +2,7 @@ #include // Constructor -Instructions::Instructions(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section) +Instructions::Instructions(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section, JA_Music_t *music) { // Copia los punteros this->screen = screen; @@ -11,6 +11,7 @@ Instructions::Instructions(Screen *screen, Asset *asset, Input *input, Lang *lan this->lang = lang; this->param = param; this->section = section; + this->music = music; renderer = screen->getRenderer(); // Crea objetos @@ -229,6 +230,10 @@ void Instructions::update() // 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(music); + // Actualiza el objeto screen screen->update(); @@ -241,8 +246,10 @@ void Instructions::update() // Actualiza el mosaico de fondo tiledbg->update(); + // Actualiza el objeto "fade" fade->update(); + // Comprueba si el contador ha llegado al final if (counter == counterEnd) { section->name = SECTION_PROG_TITLE; diff --git a/source/instructions.h b/source/instructions.h index f58ceb3..ed7d8c3 100644 --- a/source/instructions.h +++ b/source/instructions.h @@ -44,6 +44,7 @@ private: Text *text; // Objeto para escribir texto Tiledbg *tiledbg; // Objeto para dibujar el mosaico animado de fondo Fade *fade; // Objeto para renderizar fades + JA_Music_t *music; // Musica de fondo section_t *section; // Estado del bucle principal para saber si continua o se sale param_t *param; // Puntero con todos los parametros del programa @@ -85,7 +86,7 @@ private: public: // Constructor - Instructions(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section); + Instructions(Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section, JA_Music_t *music); // Destructor ~Instructions();