La sección del programa se controla ahora mediante un puntero a una variable

This commit is contained in:
2023-09-23 00:02:49 +02:00
parent 337e6ed6cc
commit 9513a6c57e
16 changed files with 179 additions and 201 deletions

View File

@@ -2,7 +2,7 @@
#include "common/jscore.h"
// Constructor
Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options)
Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options, section_t *section)
{
// Copia los punteros
this->renderer = renderer;
@@ -11,6 +11,7 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
this->lang = lang;
this->input = input;
this->options = options;
this->section = section;
// Pasa variables
this->demo.enabled = demo;
@@ -246,8 +247,8 @@ void Game::init()
gameCompleted = false;
gameCompletedCounter = 0;
section.name = SECTION_PROG_GAME;
section.subsection = SUBSECTION_GAME_PLAY_1P;
section->name = SECTION_PROG_GAME;
section->subsection = SUBSECTION_GAME_PLAY_1P;
menaceCurrent = 0;
menaceThreshold = 0;
hiScoreAchieved = false;
@@ -1767,7 +1768,8 @@ void Game::updatePlayers()
{
if (demo.enabled)
{
section = {SECTION_PROG_TITLE, SUBSECTION_TITLE_INSTRUCTIONS};
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_INSTRUCTIONS;
}
else
{
@@ -1866,7 +1868,7 @@ void Game::updateDeath()
}
else
{
section.subsection = SUBSECTION_GAME_GAMEOVER;
section->subsection = SUBSECTION_GAME_GAMEOVER;
}
}
}
@@ -3089,7 +3091,7 @@ void Game::checkGameInput()
// Comprueba el input de pausa
if (input->checkInput(input_pause, REPEAT_FALSE))
{
section.name = SECTION_PROG_TITLE;
section->name = SECTION_PROG_TITLE;
}
// Incrementa el contador de la demo
@@ -3099,7 +3101,8 @@ void Game::checkGameInput()
}
else
{
section = {SECTION_PROG_TITLE, SUBSECTION_TITLE_INSTRUCTIONS};
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_INSTRUCTIONS;
}
}
// Modo Demo no activo
@@ -3182,7 +3185,7 @@ void Game::checkGameInput()
// Comprueba el input de pausa
if (input->checkInput(input_cancel, REPEAT_FALSE, options->input[i].deviceType, options->input[i].id))
{
section.subsection = SUBSECTION_GAME_PAUSE;
section->subsection = SUBSECTION_GAME_PAUSE;
}
if (demo.counter < TOTAL_DEMO_DATA)
@@ -3195,7 +3198,7 @@ void Game::checkGameInput()
}
else if (demo.recording)
{
section.name = SECTION_PROG_QUIT;
section->name = SECTION_PROG_QUIT;
}
i++;
@@ -3339,24 +3342,24 @@ void Game::shakeScreen()
}
// Bucle para el juego
section_t Game::run()
void Game::run()
{
while (section.name == SECTION_PROG_GAME)
while (section->name == SECTION_PROG_GAME)
{
// Sección juego en pausa
if (section.subsection == SUBSECTION_GAME_PAUSE)
if (section->subsection == SUBSECTION_GAME_PAUSE)
{
runPausedGame();
}
// Sección Game Over
if (section.subsection == SUBSECTION_GAME_GAMEOVER)
if (section->subsection == SUBSECTION_GAME_GAMEOVER)
{
runGameOverScreen();
}
// Sección juego jugando
if ((section.subsection == SUBSECTION_GAME_PLAY_1P) || (section.subsection == SUBSECTION_GAME_PLAY_2P))
if ((section->subsection == SUBSECTION_GAME_PLAY_1P) || (section->subsection == SUBSECTION_GAME_PLAY_2P))
{
// Si la música no está sonando
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
@@ -3381,8 +3384,6 @@ section_t Game::run()
render();
}
}
return section;
}
// Actualiza las variables del menu de pausa del juego
@@ -3412,8 +3413,8 @@ void Game::updatePausedGame()
}
else
{ // Ha finalizado el contador
section.name = SECTION_PROG_GAME;
section.subsection = numPlayers == 1 ? SUBSECTION_GAME_PLAY_1P : SUBSECTION_GAME_PLAY_2P;
section->name = SECTION_PROG_GAME;
section->subsection = numPlayers == 1 ? SUBSECTION_GAME_PLAY_1P : SUBSECTION_GAME_PLAY_2P;
if (JA_GetMusicState() == JA_MUSIC_PAUSED)
{
@@ -3448,8 +3449,8 @@ void Game::updatePausedGame()
fade->update();
if (fade->hasEnded())
{
section.name = SECTION_PROG_TITLE;
section.subsection = SUBSECTION_TITLE_1;
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1;
JA_StopMusic();
}
}
@@ -3519,7 +3520,7 @@ void Game::runPausedGame()
// Inicializa variables
pauseCounter = 90;
while ((section.subsection == SUBSECTION_GAME_PAUSE) && (section.name == SECTION_PROG_GAME))
while ((section->subsection == SUBSECTION_GAME_PAUSE) && (section->name == SECTION_PROG_GAME))
{
updatePausedGame();
checkEvents();
@@ -3554,15 +3555,15 @@ void Game::updateGameOverScreen()
switch (postFade)
{
case 0: // YES
section.name = SECTION_PROG_GAME;
section->name = SECTION_PROG_GAME;
deleteAllVectorObjects();
init();
section.subsection = numPlayers == 1 ? SUBSECTION_GAME_PLAY_1P : SUBSECTION_GAME_PLAY_2P;
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;
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1;
break;
default:
@@ -3600,7 +3601,7 @@ void Game::updateGameOverScreen()
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section.name = SECTION_PROG_QUIT;
section->name = SECTION_PROG_QUIT;
break;
}
else if (eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0)
@@ -3693,7 +3694,7 @@ void Game::runGameOverScreen()
// Reinicia el menu
gameOverMenu->reset();
while ((section.subsection == SUBSECTION_GAME_GAMEOVER) && (section.name == SECTION_PROG_GAME))
while ((section->subsection == SUBSECTION_GAME_GAMEOVER) && (section->name == SECTION_PROG_GAME))
{
updateGameOverScreen();
renderGameOverScreen();
@@ -3806,7 +3807,7 @@ void Game::updateGameCompleted()
if (gameCompletedCounter == GAME_COMPLETED_END)
{
section.subsection = SUBSECTION_GAME_GAMEOVER;
section->subsection = SUBSECTION_GAME_GAMEOVER;
}
}
@@ -3864,7 +3865,7 @@ void Game::checkEvents()
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section.name = SECTION_PROG_QUIT;
section->name = SECTION_PROG_QUIT;
break;
}
@@ -3872,7 +3873,7 @@ void Game::checkEvents()
{
if (eventHandler->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
{
section.subsection = SUBSECTION_GAME_PAUSE;
section->subsection = SUBSECTION_GAME_PAUSE;
}
}
}