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
Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t section)
Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section)
{
// Copia las direcciones de los punteros
this->renderer = renderer;
@@ -11,7 +11,6 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
this->asset = asset;
this->options = options;
this->lang = lang;
this->section = section;
// Reserva memoria para los punteros
@@ -95,7 +94,7 @@ Title::~Title()
void Title::init()
{
// Inicializa variables
section.subsection = SUBSECTION_TITLE_1;
section->subsection = SUBSECTION_TITLE_1;
counter = TITLE_COUNTER;
backgroundCounter = 0;
backgroundMode = rand() % 2;
@@ -227,7 +226,7 @@ void Title::update()
// Actualiza las notificaciones
screen->updateNotifier();
switch (section.subsection)
switch (section->subsection)
{
// Sección 1 - Titulo desplazandose
case SUBSECTION_TITLE_1:
@@ -239,7 +238,7 @@ void Title::update()
// Si los objetos han llegado a su destino, cambiamos de Sección
if (coffeeBitmap->hasFinished() && crisisBitmap->hasFinished())
{
section.subsection = SUBSECTION_TITLE_2;
section->subsection = SUBSECTION_TITLE_2;
// Pantallazo blanco
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
@@ -270,7 +269,7 @@ void Title::update()
if (step == 33)
{
section.subsection = SUBSECTION_TITLE_3;
section->subsection = SUBSECTION_TITLE_3;
}
}
break;
@@ -296,19 +295,19 @@ void Title::update()
switch (postFade)
{
case 0: // 1 PLAYER
section.name = SECTION_PROG_GAME;
section.subsection = SUBSECTION_GAME_PLAY_1P;
section->name = SECTION_PROG_GAME;
section->subsection = SUBSECTION_GAME_PLAY_1P;
JA_StopMusic();
break;
case 1: // 2 PLAYERS
section.name = SECTION_PROG_GAME;
section.subsection = SUBSECTION_GAME_PLAY_2P;
section->name = SECTION_PROG_GAME;
section->subsection = SUBSECTION_GAME_PLAY_2P;
JA_StopMusic();
break;
case 2: // QUIT
section.name = SECTION_PROG_QUIT;
section->name = SECTION_PROG_QUIT;
JA_StopMusic();
break;
@@ -318,17 +317,17 @@ void Title::update()
if (demo)
{
runDemoGame();
if (section.name != SECTION_PROG_QUIT)
if (section->name != SECTION_PROG_QUIT)
{
runInstructions(m_auto);
}
if (section.name != SECTION_PROG_QUIT)
if (section->name != SECTION_PROG_QUIT)
{
runHiScoreTable(mhst_auto);
}
}
else
section.name = SECTION_PROG_LOGO;
section->name = SECTION_PROG_LOGO;
break;
default:
@@ -507,11 +506,11 @@ void Title::update()
if (demo)
{
runDemoGame();
if (section.name != SECTION_PROG_QUIT)
if (section->name != SECTION_PROG_QUIT)
{
runInstructions(m_auto);
}
if (section.name != SECTION_PROG_QUIT)
if (section->name != SECTION_PROG_QUIT)
{
runHiScoreTable(mhst_auto);
}
@@ -521,12 +520,12 @@ void Title::update()
}
else
{
section.name = SECTION_PROG_LOGO;
section->name = SECTION_PROG_LOGO;
}
}
// Sección Instrucciones
if (section.subsection == SUBSECTION_TITLE_INSTRUCTIONS)
if (section->subsection == SUBSECTION_TITLE_INSTRUCTIONS)
{
runInstructions(m_auto);
counter = TITLE_COUNTER;
@@ -545,7 +544,7 @@ void Title::update()
// Dibuja el objeto en pantalla
void Title::render()
{
switch (section.subsection)
switch (section->subsection)
{
// Sección 1 - Titulo desplazandose
case SUBSECTION_TITLE_1:
@@ -609,7 +608,7 @@ void Title::render()
screen->blit();
}
section.subsection = SUBSECTION_TITLE_3;
section->subsection = SUBSECTION_TITLE_3;
}
break;
@@ -675,7 +674,7 @@ void Title::checkEvents()
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section.name = SECTION_PROG_QUIT;
section->name = SECTION_PROG_QUIT;
break;
}
@@ -684,7 +683,7 @@ void Title::checkEvents()
reLoadTextures();
}
if (section.subsection == SUBSECTION_TITLE_3)
if (section->subsection == SUBSECTION_TITLE_3)
{ // Si se pulsa alguna tecla durante la tercera sección del titulo
if ((eventHandler->type == SDL_KEYUP) || (eventHandler->type == SDL_JOYBUTTONUP))
{
@@ -703,7 +702,7 @@ void Title::checkInput()
{
if (input->checkInput(input_exit, REPEAT_FALSE))
{
section.name = SECTION_PROG_QUIT;
section->name = SECTION_PROG_QUIT;
}
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
@@ -968,54 +967,46 @@ void Title::applyOptions()
}
// Bucle para el titulo del juego
section_t Title::run()
void Title::run()
{
while (section.name == SECTION_PROG_TITLE)
while (section->name == SECTION_PROG_TITLE)
{
update();
checkEvents();
render();
}
return section;
}
// Ejecuta la parte donde se muestran las instrucciones
section_t Title::runInstructions(mode_e mode)
void Title::runInstructions(mode_e mode)
{
instructions = new Instructions(renderer, screen, asset, input, lang);
section = instructions->run(mode);
instructions->run(mode);
delete instructions;
return section;
}
// Ejecuta la parte donde se muestra la tabla de puntuaciones
section_t Title::runHiScoreTable(mode_hiScoreTable_e mode)
void Title::runHiScoreTable(mode_hiScoreTable_e mode)
{
if (!options->online.enabled)
{
section.name = SECTION_PROG_TITLE;
section.subsection = SUBSECTION_TITLE_1;
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1;
return section;
return;
}
hiScoreTable = new HiScoreTable(renderer, screen, asset, input, lang, options);
section = hiScoreTable->run(mode);
hiScoreTable = new HiScoreTable(renderer, screen, asset, input, lang, options, section);
hiScoreTable->run(mode);
delete hiScoreTable;
return section;
}
// Ejecuta el juego en modo demo
section_t Title::runDemoGame()
void Title::runDemoGame()
{
demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, options);
section = demoGame->run();
demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, options, section);
demoGame->run();
delete demoGame;
return section;
}
// Modifica las opciones para los controles de los jugadores