fix: ja torna a funcionar el cicle de música per les diferents seccions

This commit is contained in:
2024-08-14 08:38:19 +02:00
parent a5a3bb23da
commit 45ed1106cb
7 changed files with 35 additions and 21 deletions

View File

@@ -869,7 +869,7 @@ void Director::runGame()
// Ejecuta la sección donde se muestran las instrucciones // Ejecuta la sección donde se muestran las instrucciones
void Director::runInstructions() 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(); instructions->run();
delete instructions; delete instructions;
} }
@@ -877,7 +877,7 @@ void Director::runInstructions()
// Ejecuta la sección donde se muestra la tabla de puntuaciones // Ejecuta la sección donde se muestra la tabla de puntuaciones
void Director::runHiScoreTable() 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(); hiScoreTable->run();
delete hiScoreTable; delete hiScoreTable;
} }

View File

@@ -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() void Game::updateStage()
{ {
if (currentPower >= enemyFormations->getStage(currentStage).powerToComplete) if (currentPower >= enemyFormations->getStage(currentStage).powerToComplete)
@@ -1957,7 +1957,7 @@ void Game::update()
#endif #endif
// Comprueba si la música ha de estar sonando // Comprueba si la música ha de estar sonando
// checkMusicStatus(); checkMusicStatus();
// Actualiza el objeto screen // Actualiza el objeto screen
screen->update(); screen->update();
@@ -1977,6 +1977,7 @@ void Game::update()
// Mueve los globos // Mueve los globos
updateBalloons(); updateBalloons();
// Actualiza el objeto encargado de las explosiones
explosions->update(); explosions->update();
// Mueve las balas // Mueve las balas
@@ -1985,7 +1986,7 @@ void Game::update()
// Actualiza los items // Actualiza los items
updateItems(); updateItems();
// Actualiza el valor de currentStage // Comprueba si hay cambio de fase y actualiza las variables
updateStage(); updateStage();
// Actualiza el estado de muerte // Actualiza el estado de muerte
@@ -2101,9 +2102,9 @@ void Game::render()
renderSeparator(); renderSeparator();
#ifdef DEBUG #ifdef DEBUG
text->write(0, 0, boolToString(players[0]->isAlive())); //text->write(0, 0, "P1 ALIVE: " + boolToString(players[0]->isAlive()));
text->write(0, 10, boolToString(players[1]->isAlive())); //text->write(0, 10, "P2 ALIVE: " + boolToString(players[1]->isAlive()));
text->write(0, 20, "POLLA"); //text->write(0, 20, "ALL DEAD: " + boolToString(allPlayersAreDead()));
#endif #endif
// Dibuja el fade // Dibuja el fade
@@ -2453,14 +2454,8 @@ void Game::checkMusicStatus()
// Si la música no está sonando // Si la música no está sonando
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{ {
// Reproduce la música // Si se ha completado el juego o los jugadores estan mujertos, detiene la música
if (!gameCompleted) gameCompleted || allPlayersAreDead() ? JA_StopMusic() : JA_PlayMusic(music);
{
if (!allPlayersAreDead())
{
JA_PlayMusic(music);
}
}
} }
} }
@@ -2482,6 +2477,10 @@ void Game::run()
{ {
JA_EnableSound(options->audio.sound.enabled); JA_EnableSound(options->audio.sound.enabled);
} }
else
{
JA_StopMusic();
}
} }
// Indica si se puede crear una powerball // Indica si se puede crear una powerball

View File

@@ -248,7 +248,7 @@ private:
// Dibuja a los jugadores // Dibuja a los jugadores
void renderPlayers(); void renderPlayers();
// Actualiza las variables de la fase // Comprueba si hay cambio de fase y actualiza las variables
void updateStage(); void updateStage();
// Actualiza el estado de muerte // Actualiza el estado de muerte

View File

@@ -2,7 +2,7 @@
#include <iostream> #include <iostream>
// Constructor // 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 // Copia punteros
this->screen = screen; this->screen = screen;
@@ -12,6 +12,7 @@ HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, Lang *lan
this->section = section; this->section = section;
this->options = options; this->options = options;
this->param = param; this->param = param;
this->music = music;
renderer = screen->getRenderer(); renderer = screen->getRenderer();
// Objetos // Objetos
@@ -68,6 +69,10 @@ void HiScoreTable::update()
// Actualiza el contador de ticks // Actualiza el contador de ticks
ticks = SDL_GetTicks(); 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 // Actualiza el objeto screen
screen->update(); screen->update();
@@ -77,6 +82,7 @@ void HiScoreTable::update()
// Gestiona el fade // Gestiona el fade
updateFade(); updateFade();
// Gestiona el contador y sus eventos
counter++; counter++;
if (counter == 150) if (counter == 150)

View File

@@ -38,6 +38,7 @@ private:
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
Fade *fade; // Objeto para renderizar fades Fade *fade; // Objeto para renderizar fades
Text *text; // Objeto para escribir texto Text *text; // Objeto para escribir texto
JA_Music_t *music; // Musica de fondo
options_t *options; // Opciones y parametros del programa options_t *options; // Opciones y parametros del programa
section_t *section; // Estado del bucle principal para saber si continua o se sale section_t *section; // Estado del bucle principal para saber si continua o se sale
param_t *param; // Puntero con todos los parametros del programa param_t *param; // Puntero con todos los parametros del programa
@@ -79,7 +80,7 @@ private:
public: public:
// Constructor // 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 // Destructor
~HiScoreTable(); ~HiScoreTable();

View File

@@ -2,7 +2,7 @@
#include <iostream> #include <iostream>
// Constructor // 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 // Copia los punteros
this->screen = screen; this->screen = screen;
@@ -11,6 +11,7 @@ Instructions::Instructions(Screen *screen, Asset *asset, Input *input, Lang *lan
this->lang = lang; this->lang = lang;
this->param = param; this->param = param;
this->section = section; this->section = section;
this->music = music;
renderer = screen->getRenderer(); renderer = screen->getRenderer();
// Crea objetos // Crea objetos
@@ -229,6 +230,10 @@ void Instructions::update()
// Actualiza el contador de ticks // Actualiza el contador de ticks
ticks = SDL_GetTicks(); 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 // Actualiza el objeto screen
screen->update(); screen->update();
@@ -241,8 +246,10 @@ void Instructions::update()
// Actualiza el mosaico de fondo // Actualiza el mosaico de fondo
tiledbg->update(); tiledbg->update();
// Actualiza el objeto "fade"
fade->update(); fade->update();
// Comprueba si el contador ha llegado al final
if (counter == counterEnd) if (counter == counterEnd)
{ {
section->name = SECTION_PROG_TITLE; section->name = SECTION_PROG_TITLE;

View File

@@ -44,6 +44,7 @@ private:
Text *text; // Objeto para escribir texto Text *text; // Objeto para escribir texto
Tiledbg *tiledbg; // Objeto para dibujar el mosaico animado de fondo Tiledbg *tiledbg; // Objeto para dibujar el mosaico animado de fondo
Fade *fade; // Objeto para renderizar fades 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 section_t *section; // Estado del bucle principal para saber si continua o se sale
param_t *param; // Puntero con todos los parametros del programa param_t *param; // Puntero con todos los parametros del programa
@@ -85,7 +86,7 @@ private:
public: public:
// Constructor // 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 // Destructor
~Instructions(); ~Instructions();