Eliminado el menu de pausa

Eliminado el menu de game over
Eliminado el menu de seleccionar jugador
Se puede poner pausa y salir del juego desde ambos mandos
This commit is contained in:
2024-06-30 15:08:25 +02:00
parent 1754cfb93a
commit addc8241ab
11 changed files with 73 additions and 543 deletions

View File

@@ -135,8 +135,6 @@ Game::~Game()
delete textBig;
delete textNokia2;
delete textNokiaBig2;
delete gameOverMenu;
delete pauseMenu;
delete fade;
delete eventHandler;
delete n1000Sprite;
@@ -222,14 +220,11 @@ void Game::init()
break;
}
// Colores
pauseMenu->setSelectorColor(difficultyColor, 255);
gameOverMenu->setSelectorColor(difficultyColor, 255);
// Variables para el marcador
scoreboard->setPos({param->scoreboard.x, param->scoreboard.y, param->scoreboard.w, param->scoreboard.h});
// Resto de variables
paused = false;
gameCompleted = false;
gameCompletedCounter = 0;
section->name = SECTION_PROG_GAME;
@@ -258,8 +253,6 @@ void Game::init()
powerBallEnabled = false;
powerBallCounter = 0;
coffeeMachineEnabled = false;
pauseCounter = 0;
leavingPauseMenu = false;
if (demo.enabled)
{
@@ -502,18 +495,6 @@ void Game::loadMedia()
textNokia2 = new Text(asset->get("nokia2.png"), asset->get("nokia2.txt"), renderer);
textNokiaBig2 = new Text(asset->get("nokia_big2.png"), asset->get("nokia_big2.txt"), renderer);
// Menus
gameOverMenu = new Menu(renderer, asset, input, asset->get("gameover.men"));
gameOverMenu->setItemCaption(0, lang->getText(48));
gameOverMenu->setItemCaption(1, lang->getText(49));
const int w = text->getCharacterSize() * lang->getText(45).length();
gameOverMenu->setRectSize(w, 0);
gameOverMenu->centerMenuOnX(199);
pauseMenu = new Menu(renderer, asset, input, asset->get("pause.men"));
pauseMenu->setItemCaption(0, lang->getText(41));
pauseMenu->setItemCaption(1, lang->getText(46));
pauseMenu->setItemCaption(2, lang->getText(47));
// Sonidos
balloonSound = JA_LoadSound(asset->get("balloon.wav").c_str());
bubble1Sound = JA_LoadSound(asset->get("bubble1.wav").c_str());
@@ -1663,7 +1644,9 @@ void Game::updateDeath()
}
else
{
section->subsection = SUBSECTION_GAME_GAMEOVER;
// section->subsection = SUBSECTION_GAME_GAMEOVER;
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1;
}
}
}
@@ -2555,6 +2538,11 @@ void Game::updateEnemyDeployCounter()
// Actualiza el juego
void Game::update()
{
if (paused)
{
return;
}
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - ticks > ticksSpeed)
{
@@ -2567,9 +2555,6 @@ void Game::update()
// Actualiza el objeto screen
screen->update();
// Comprueba el teclado/mando
checkGameInput();
// Actualiza las variables del jugador
updatePlayers();
@@ -2751,8 +2736,18 @@ void Game::checkGameInput()
demo.keys.fireLeft = 0;
demo.keys.fireRight = 0;
// Comprueba las teclas de cambiar el tamaño de la centana y el modo de video
if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
// Comprueba las teclas que afectan al programa (solo para el primer jugador)
if (input->checkInput(input_exit, REPEAT_FALSE))
{
section->name = SECTION_PROG_QUIT;
}
else if (input->checkInput(input_pause, REPEAT_FALSE))
{
paused = !paused;
}
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
{
screen->switchVideoMode();
}
@@ -2919,12 +2914,6 @@ void Game::checkGameInput()
}
}
// Comprueba el input de pausa
if (input->checkInput(input_cancel, REPEAT_FALSE, options->game.input[i].deviceType, options->game.input[i].id))
{
section->subsection = SUBSECTION_GAME_PAUSE;
}
if (demo.counter < TOTAL_DEMO_DATA)
{
if (demo.recording)
@@ -3047,18 +3036,6 @@ void Game::run()
{
while (section->name == SECTION_PROG_GAME)
{
// Sección juego en pausa
if (section->subsection == SUBSECTION_GAME_PAUSE)
{
runPausedGame();
}
// Sección Game Over
if (section->subsection == SUBSECTION_GAME_GAMEOVER)
{
runGameOverScreen();
}
// Sección juego jugando
if ((section->subsection == SUBSECTION_GAME_PLAY_1P) || (section->subsection == SUBSECTION_GAME_PLAY_2P))
{
@@ -3075,6 +3052,9 @@ void Game::run()
}
}
// Comprueba el teclado/mando
checkGameInput();
// Actualiza la lógica del juego
update();
@@ -3087,302 +3067,6 @@ void Game::run()
}
}
// Actualiza las variables del menu de pausa del juego
void Game::updatePausedGame()
{
// Calcula la lógica de los objetos
if (SDL_GetTicks() - ticks > ticksSpeed)
{
// Actualiza el contador de ticks
ticks = SDL_GetTicks();
if (leavingPauseMenu)
{
if (pauseCounter > 0)
{ // El contador está descendiendo
const bool a = pauseCounter == 90;
const bool b = pauseCounter == 60;
const bool c = pauseCounter == 30;
if (a || b || c)
{
JA_PlaySound(clockSound);
}
pauseCounter--;
}
else
{ // Ha finalizado el contador
section->name = SECTION_PROG_GAME;
section->subsection = numPlayers == 1 ? SUBSECTION_GAME_PLAY_1P : SUBSECTION_GAME_PLAY_2P;
if (JA_GetMusicState() == JA_MUSIC_PAUSED)
{
JA_ResumeMusic();
}
}
}
else
{ // Actualiza la lógica del menu de pausa
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:
leavingPauseMenu = true;
break;
case 2:
fade->setType(FADE_CENTER);
fade->activate();
break;
default:
break;
}
// Actualiza el fade
fade->update();
if (fade->hasEnded())
{
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1;
JA_StopMusic();
}
}
}
}
// Dibuja el menu de pausa del juego
void Game::renderPausedGame()
{
// Prepara para empezar a dibujar en la textura de juego
screen->start();
// Limpia la pantalla
screen->clean(bgColor);
// Pinta el escenario
fillCanvas();
SDL_RenderCopy(renderer, canvas, nullptr, &playArea);
if ((deathCounter <= 150) && !players[0]->isAlive())
{
renderDeathFade(150 - deathCounter);
}
if ((gameCompleted) && (gameCompletedCounter >= GAME_COMPLETED_START_FADE))
{
renderDeathFade(gameCompletedCounter - GAME_COMPLETED_START_FADE);
}
if (leavingPauseMenu)
{
textNokiaBig2->writeCentered(GAMECANVAS_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, std::to_string((pauseCounter / 30) + 1));
}
else
{
pauseMenu->render();
}
fade->render();
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
// Bucle para el menu de pausa del juego
void Game::runPausedGame()
{
// Pone en pausa la música
if (JA_GetMusicState() == JA_MUSIC_PLAYING)
{
JA_PauseMusic();
}
// Reinicia el menu
pauseMenu->reset();
leavingPauseMenu = false;
// Inicializa variables
pauseCounter = 90;
while ((section->subsection == SUBSECTION_GAME_PAUSE) && (section->name == SECTION_PROG_GAME))
{
updatePausedGame();
checkEvents();
renderPausedGame();
}
}
// Actualiza los elementos de la pantalla de game over
void Game::updateGameOverScreen()
{
// Variables
static int postFade = 0;
// Calcula la lógica de los objetos
if (SDL_GetTicks() - ticks > ticksSpeed)
{
// Actualiza el contador de ticks
ticks = SDL_GetTicks();
// Actualiza la lógica del menu
gameOverMenu->update();
// Actualiza el fade
fade->update();
// Si ha terminado el fade, actua segun se haya operado
if (fade->hasEnded())
{
switch (postFade)
{
case 0: // YES
section->name = SECTION_PROG_GAME;
deleteAllVectorObjects();
init();
section->subsection = numPlayers == 1 ? SUBSECTION_GAME_PLAY_1P : SUBSECTION_GAME_PLAY_2P;
break;
case 1: // NO
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1;
break;
default:
break;
}
}
// Comprueba las entradas para el menu solo si no esta el juego completo
if (!gameCompleted)
{
gameOverMenu->checkInput();
// Comprueba si se ha seleccionado algún item del menú
switch (gameOverMenu->getItemSelected())
{
case 0: // YES
postFade = 0;
fade->activate();
break;
case 1: // NO
postFade = 1;
fade->activate();
break;
default:
break;
}
}
}
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(eventHandler) != 0)
{
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section->name = SECTION_PROG_QUIT;
break;
}
else if (eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0)
{
if (gameCompleted)
{
postFade = 1;
fade->activate();
JA_PlaySound(itemPickUpSound);
}
}
}
}
// Dibuja los elementos de la pantalla de game over
void Game::renderGameOverScreen()
{
// Prepara para empezar a dibujar en la textura de juego
screen->start();
// Limpia la pantalla
screen->clean(bgColor);
// Dibujo
if (!gameCompleted)
{ // Dibujo de haber perdido la partida
gameOverSprite->render();
}
else
{ // Dinujo de haber completado la partida
gameOverEndSprite->render();
}
// Dibuja los objetos
if (numPlayers == 1)
{
// Congratulations!!
if (gameCompleted)
{
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 8), lang->getText(50));
}
// Game Over
textBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 6), lang->getText(43));
// Your Score
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 3), lang->getText(44) + std::to_string(players[0]->getScore()));
}
else
{
// Congratulations!!
if (gameCompleted)
{
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 9), lang->getText(50));
}
// Game Over
textBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 7), lang->getText(43));
// Player1 Score
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 4), lang->getText(77) + std::to_string(players[0]->getScore()));
// Player2 Score
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 2), lang->getText(78) + std::to_string(players[1]->getScore()));
}
// Continue?
if (!gameCompleted)
{ // Solo dibuja el menu de continuar en el caso de no haber completado la partida
text->writeCentered(199, PLAY_AREA_CENTER_Y + BLOCK * 3, lang->getText(45));
gameOverMenu->render();
}
// Pinta el fade
fade->render();
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
// Bucle para la pantalla de game over
void Game::runGameOverScreen()
{
// Guarda los puntos
saveScoreFile();
// Reinicia el menu
gameOverMenu->reset();
while ((section->subsection == SUBSECTION_GAME_GAMEOVER) && (section->name == SECTION_PROG_GAME))
{
updateGameOverScreen();
renderGameOverScreen();
}
}
// Indica si se puede crear una powerball
bool Game::canPowerBallBeCreated()
{
@@ -3489,7 +3173,9 @@ void Game::updateGameCompleted()
if (gameCompletedCounter == GAME_COMPLETED_END)
{
section->subsection = SUBSECTION_GAME_GAMEOVER;
// section->subsection = SUBSECTION_GAME_GAMEOVER;
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1;
}
}
@@ -3555,7 +3241,12 @@ void Game::checkEvents()
{
if (eventHandler->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
{
section->subsection = SUBSECTION_GAME_PAUSE;
paused = true;
}
if (eventHandler->window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
{
paused = false;
}
}
}