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
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;
}

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()
{
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

View File

@@ -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

View File

@@ -2,7 +2,7 @@
#include <iostream>
// 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)

View File

@@ -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();

View File

@@ -2,7 +2,7 @@
#include <iostream>
// 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;

View File

@@ -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();