Añadido contador al quitar el menu de pausa del juego

This commit is contained in:
2022-10-14 10:44:50 +02:00
parent fa53c1b01a
commit 8041595976
2 changed files with 84 additions and 40 deletions

View File

@@ -273,6 +273,8 @@ void Game::init()
powerBallEnabled = false; powerBallEnabled = false;
powerBallCounter = 0; powerBallCounter = 0;
coffeeMachineEnabled = false; coffeeMachineEnabled = false;
pauseCounter = 0;
leavingPauseMenu = false;
if (demo.enabled) if (demo.enabled)
{ {
@@ -3073,11 +3075,6 @@ void Game::checkGameInput()
if (input->checkInput(INPUT_CANCEL, REPEAT_FALSE, options->input[i].deviceType, options->input[i].id)) if (input->checkInput(INPUT_CANCEL, REPEAT_FALSE, options->input[i].deviceType, options->input[i].id))
{ {
section.subsection = GAME_SECTION_PAUSE; section.subsection = GAME_SECTION_PAUSE;
if (JA_GetMusicState() == JA_MUSIC_PLAYING)
{
JA_PauseMusic();
}
} }
if (demo.counter < TOTAL_DEMO_DATA) if (demo.counter < TOTAL_DEMO_DATA)
@@ -3289,41 +3286,61 @@ void Game::updatePausedGame()
// Actualiza el contador de ticks // Actualiza el contador de ticks
ticks = SDL_GetTicks(); ticks = SDL_GetTicks();
// Actualiza la lógica del menu de pausa if (leavingPauseMenu)
pauseMenu->update();
// Comprueba las entradas para el menu
pauseMenu->checkInput();
// Comprueba si se ha seleccionado algún item del menú
switch (pauseMenu->getItemSelected())
{ {
case 1: if (pauseCounter > 0)
section.name = PROG_SECTION_GAME; { // El contador está descendiendo
section.subsection = numPlayers == 1 ? GAME_SECTION_PLAY_1P : GAME_SECTION_PLAY_2P; const bool a = pauseCounter == 90;
const bool b = pauseCounter == 60;
if (JA_GetMusicState() == JA_MUSIC_PAUSED) const bool c = pauseCounter == 30;
{ if (a || b || c)
JA_ResumeMusic(); {
JA_PlaySound(clockSound);
}
pauseCounter--;
} }
break; else
{ // Ha finalizado el contador
section.name = PROG_SECTION_GAME;
section.subsection = numPlayers == 1 ? GAME_SECTION_PLAY_1P : GAME_SECTION_PLAY_2P;
case 2: if (JA_GetMusicState() == JA_MUSIC_PAUSED)
fade->setFadeType(FADE_CENTER); {
fade->activateFade(); JA_ResumeMusic();
break; }
}
default:
break;
} }
else
{ // Actualiza la lógica del menu de pausa
pauseMenu->update();
// Actualiza el fade // Comprueba las entradas para el menu
fade->update(); pauseMenu->checkInput();
if (fade->hasEnded())
{ // Comprueba si se ha seleccionado algún item del menú
section.name = PROG_SECTION_TITLE; switch (pauseMenu->getItemSelected())
section.subsection = TITLE_SECTION_1; {
JA_StopMusic(); case 1:
leavingPauseMenu = true;
break;
case 2:
fade->setFadeType(FADE_CENTER);
fade->activateFade();
break;
default:
break;
}
// Actualiza el fade
fade->update();
if (fade->hasEnded())
{
section.name = PROG_SECTION_TITLE;
section.subsection = TITLE_SECTION_1;
JA_StopMusic();
}
} }
} }
} }
@@ -3361,7 +3378,14 @@ void Game::renderPausedGame()
renderFlashEffect(); renderFlashEffect();
} }
pauseMenu->render(); if (leavingPauseMenu)
{
textNokiaBig2->writeCentered(SCREEN_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, std::to_string((pauseCounter / 30) + 1));
}
else
{
pauseMenu->render();
}
fade->render(); fade->render();
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
@@ -3371,8 +3395,18 @@ void Game::renderPausedGame()
// Bucle para el menu de pausa del juego // Bucle para el menu de pausa del juego
void Game::runPausedGame() void Game::runPausedGame()
{ {
// Pone en pausa la música
if (JA_GetMusicState() == JA_MUSIC_PLAYING)
{
JA_PauseMusic();
}
// Reinicia el menu // Reinicia el menu
pauseMenu->reset(); pauseMenu->reset();
leavingPauseMenu = false;
// Inicializa variables
pauseCounter = 90;
while ((section.subsection == GAME_SECTION_PAUSE) && (section.name == PROG_SECTION_GAME)) while ((section.subsection == GAME_SECTION_PAUSE) && (section.name == PROG_SECTION_GAME))
{ {
@@ -3715,6 +3749,15 @@ void Game::checkEventHandler()
section.name = PROG_SECTION_QUIT; section.name = PROG_SECTION_QUIT;
break; break;
} }
else if (eventHandler->type == SDL_WINDOWEVENT)
{
if (eventHandler->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
{
section.subsection = GAME_SECTION_PAUSE;
}
}
else if (eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) else if (eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0)
{ {
switch (eventHandler->key.keysym.scancode) switch (eventHandler->key.keysym.scancode)

View File

@@ -193,10 +193,9 @@ private:
JA_Music gameMusic; // Musica de fondo JA_Music gameMusic; // Musica de fondo
// Variables // Variables
int numPlayers; // Numero de jugadores int numPlayers; // Numero de jugadores
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
Uint32 hiScore; // Puntuación máxima Uint32 hiScore; // Puntuación máxima
bool hiScoreAchieved; // Indica si se ha superado la puntuación máxima bool hiScoreAchieved; // Indica si se ha superado la puntuación máxima
section_t section; // Seccion actual dentro del juego section_t section; // Seccion actual dentro del juego
@@ -236,6 +235,8 @@ private:
demo_t demo; // Variable con todas las variables relacionadas con el modo demo demo_t demo; // Variable con todas las variables relacionadas con el modo demo
int totalPowerToCompleteGame; // La suma del poder necesario para completar todas las fases int totalPowerToCompleteGame; // La suma del poder necesario para completar todas las fases
int cloudsSpeed; // Velocidad a la que se desplazan las nubes int cloudsSpeed; // Velocidad a la que se desplazan las nubes
int pauseCounter; // Contador para salir del menu de pausa y volver al juego
bool leavingPauseMenu; // Indica si esta saliendo del menu de pausa para volver al juego
// Actualiza el juego // Actualiza el juego
void update(); void update();