Eliminat el punter a "section"

This commit is contained in:
2024-09-28 09:28:22 +02:00
parent 0a8d0479a0
commit 8d263931b2
19 changed files with 191 additions and 172 deletions

View File

@@ -10,24 +10,7 @@
#define PLAY_AREA_LEFT 0
#define PLAY_AREA_TOP 0
// Secciones del programa
#define SECTION_PROG_INIT 8
#define SECTION_PROG_LOGO 0
#define SECTION_PROG_INTRO 1
#define SECTION_PROG_TITLE 2
#define SECTION_PROG_GAME 3
#define SECTION_PROG_HI_SCORE_TABLE 4
#define SECTION_PROG_GAME_DEMO 5
#define SECTION_PROG_INSTRUCTIONS 6
#define SECTION_PROG_QUIT 7
// Subsecciones
#define SECTION_OPTIONS_GAME_PLAY_1P 0
#define SECTION_OPTIONS_GAME_PLAY_2P 1
#define SECTION_OPTIONS_TITLE_1 3
#define SECTION_OPTIONS_TITLE_2 4
#define SECTION_OPTIONS_QUIT_NORMAL 5
#define SECTION_OPTIONS_QUIT_SHUTDOWN 6
// Ningun tipo
#define NO_KIND 0

View File

@@ -1,14 +1,14 @@
#include "define_buttons.h"
#include "param.h"
#include "options.h"
#include "section.h"
// Constructor
DefineButtons::DefineButtons(Input *input, Text *text, section_t *section)
DefineButtons::DefineButtons(Input *input, Text *text)
{
// Copia punteros a los objetos
this->input = input;
this->text = text;
this->section = section;
// Inicializa variables
enabled = false;
@@ -112,7 +112,8 @@ void DefineButtons::checkInput()
// Evento de salida de la aplicación
if (event.type == SDL_QUIT)
{
section->name = SECTION_PROG_QUIT;
section::name = section::NAME_QUIT;
section::options = section::OPTIONS_QUIT_NORMAL;
break;
}

View File

@@ -22,7 +22,6 @@ private:
Text *text; // Objeto para escribir texto
// Variables
section_t *section; // Indicador para el bucle del titulo
bool enabled; // Indica si el objeto está habilitado
int x; // Posición donde dibujar el texto
int y; // Posición donde dibujar el texto
@@ -45,7 +44,7 @@ private:
public:
// Constructor
DefineButtons(Input *input, Text *text, section_t *section);
DefineButtons(Input *input, Text *text);
// Destructor
~DefineButtons();

View File

@@ -2,6 +2,7 @@
#include "utils.h"
#include "const.h"
#include "options.h"
#include "section.h"
#include <iostream>
#include <fstream>
#include <string>
@@ -16,15 +17,13 @@
// Constructor
Director::Director(int argc, char *argv[])
{
// Inicializa variables
section = new section_t();
#ifdef RECORDING
section->name = SECTION_PROG_GAME;
section->options = SECTION_OPTIONS_GAME_PLAY_1P;
section::name = section::NAME_GAME;
section::options = section::OPTIONS_GAME_PLAY_1P;
#elif DEBUG
section->name = SECTION_PROG_LOGO;
section::name = section::NAME_LOGO;
#else
section->name = SECTION_PROG_LOGO;
section::name = section::NAME_LOGO;
#endif
// Comprueba los parametros del programa
@@ -90,7 +89,6 @@ Director::~Director()
delete asset;
delete input;
delete screen;
delete section;
deleteSounds();
deleteMusics();
@@ -602,7 +600,7 @@ void Director::deleteMusics()
// Ejecuta la sección con el logo
void Director::runLogo()
{
logo = new Logo(screen, asset, input, section);
logo = new Logo(screen, asset, input);
logo->run();
delete logo;
}
@@ -610,7 +608,7 @@ void Director::runLogo()
// Ejecuta la sección con la secuencia de introducción
void Director::runIntro()
{
intro = new Intro(screen, asset, input, section, getMusic(musics, "intro.ogg"));
intro = new Intro(screen, asset, input, getMusic(musics, "intro.ogg"));
intro->run();
delete intro;
}
@@ -618,7 +616,7 @@ void Director::runIntro()
// Ejecuta la sección con el titulo del juego
void Director::runTitle()
{
title = new Title(screen, asset, input, section, getMusic(musics, "title.ogg"));
title = new Title(screen, asset, input, getMusic(musics, "title.ogg"));
title->run();
delete title;
}
@@ -626,9 +624,9 @@ void Director::runTitle()
// Ejecuta la sección donde se juega al juego
void Director::runGame()
{
const int playerID = section->options;
const int playerID = section::options;
const int currentStage = 0;
game = new Game(playerID, currentStage, GAME_MODE_DEMO_OFF, screen, asset, input, section, getMusic(musics, "playing.ogg"));
game = new Game(playerID, currentStage, GAME_MODE_DEMO_OFF, screen, asset, input, getMusic(musics, "playing.ogg"));
game->run();
delete game;
}
@@ -636,7 +634,7 @@ void Director::runGame()
// Ejecuta la sección donde se muestran las instrucciones
void Director::runInstructions()
{
instructions = new Instructions(screen, asset, input, section, getMusic(musics, "title.ogg"));
instructions = new Instructions(screen, asset, input, getMusic(musics, "title.ogg"));
instructions->run();
delete instructions;
}
@@ -644,7 +642,7 @@ void Director::runInstructions()
// Ejecuta la sección donde se muestra la tabla de puntuaciones
void Director::runHiScoreTable()
{
hiScoreTable = new HiScoreTable(screen, asset, input, section, getMusic(musics, "title.ogg"));
hiScoreTable = new HiScoreTable(screen, asset, input, getMusic(musics, "title.ogg"));
hiScoreTable->run();
delete hiScoreTable;
}
@@ -654,7 +652,7 @@ void Director::runDemoGame()
{
const int playerID = (rand() % 2) + 1;
const int currentStage = 0;
demoGame = new Game(playerID, currentStage, GAME_MODE_DEMO_ON, screen, asset, input, section, nullptr);
demoGame = new Game(playerID, currentStage, GAME_MODE_DEMO_ON, screen, asset, input, nullptr);
demoGame->run();
delete demoGame;
}
@@ -662,45 +660,48 @@ void Director::runDemoGame()
int Director::run()
{
// Bucle principal
while (section->name != SECTION_PROG_QUIT)
while (section::name != section::NAME_QUIT)
{
switch (section->name)
switch (section::name)
{
case SECTION_PROG_INIT:
section->name = SECTION_PROG_LOGO;
case section::NAME_INIT:
section::name = section::NAME_LOGO;
break;
case SECTION_PROG_LOGO:
case section::NAME_LOGO:
runLogo();
break;
case SECTION_PROG_INTRO:
case section::NAME_INTRO:
runIntro();
break;
case SECTION_PROG_TITLE:
case section::NAME_TITLE:
runTitle();
break;
case SECTION_PROG_GAME:
case section::NAME_GAME:
runGame();
break;
case SECTION_PROG_HI_SCORE_TABLE:
case section::NAME_HI_SCORE_TABLE:
runHiScoreTable();
break;
case SECTION_PROG_GAME_DEMO:
case section::NAME_GAME_DEMO:
runDemoGame();
break;
case SECTION_PROG_INSTRUCTIONS:
case section::NAME_INSTRUCTIONS:
runInstructions();
break;
default:
break;
}
}
const int returnCode = section->options == SECTION_OPTIONS_QUIT_NORMAL ? 0 : 1;
const int returnCode = section::options == section::OPTIONS_QUIT_NORMAL ? 0 : 1;
return returnCode;
}

View File

@@ -38,7 +38,6 @@ private:
Game *demoGame; // Objeto para lanzar la demo del juego
Input *input; // Objeto Input para gestionar las entradas
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
section_t *section; // Sección y subsección actual del programa;
// Variables
std::string executablePath; // Path del ejecutable

View File

@@ -5,13 +5,12 @@
#define GAME_OVER_COUNTER 350
// Constructor
Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music)
Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, JA_Music_t *music)
{
// Copia los punteros
this->screen = screen;
this->asset = asset;
this->input = input;
this->section = section;
this->music = music;
renderer = screen->getRenderer();
@@ -176,8 +175,8 @@ void Game::init(int playerID)
paused = false;
gameCompleted = false;
gameCompletedCounter = 0;
section->name = SECTION_PROG_GAME;
section->options = SECTION_OPTIONS_GAME_PLAY_1P;
section::name = section::NAME_GAME;
section::options = section::OPTIONS_GAME_PLAY_1P;
currentPower = 0;
menaceCurrent = 0;
menaceThreshold = 0;
@@ -948,7 +947,7 @@ void Game::updateGameOver()
if (fade->hasEnded())
{
section->name = SECTION_PROG_HI_SCORE_TABLE;
section::name = section::NAME_HI_SCORE_TABLE;
}
}
}
@@ -1831,7 +1830,7 @@ void Game::update()
// Si ha terminado el fundido, cambia de sección
if (fade->hasEnded())
{
section->name = SECTION_PROG_HI_SCORE_TABLE;
section::name = section::NAME_HI_SCORE_TABLE;
return;
}
}
@@ -1849,7 +1848,7 @@ void Game::update()
// Si se ha llenado el vector con datos, sale del programa
else
{
section->name = SECTION_PROG_QUIT;
section::name = section::NAME_QUIT;
return;
}
#endif
@@ -2037,7 +2036,7 @@ void Game::checkInput()
// Comprueba si se sale con el teclado
if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
{
quit(SECTION_OPTIONS_QUIT_NORMAL);
quit(section::OPTIONS_QUIT_NORMAL);
return;
}
@@ -2046,14 +2045,14 @@ void Game::checkInput()
// Comprueba si se sale con el mando
if (input->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
quit(SECTION_OPTIONS_QUIT_SHUTDOWN);
quit(section::OPTIONS_QUIT_SHUTDOWN);
return;
}
// Comprueba si se va a resetear el juego
if (input->checkModInput(input_service, input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
section->name = SECTION_PROG_LOGO;
section::name = section::NAME_LOGO;
screen->showNotification("Reset");
return;
}
@@ -2134,7 +2133,7 @@ void Game::checkInput()
// Si se pulsa cualquier tecla, se sale del modo demo
if (input->checkAnyButtonPressed())
{
section->name = SECTION_PROG_TITLE;
section::name = section::NAME_TITLE;
return;
}
}
@@ -2376,7 +2375,7 @@ void Game::checkMusicStatus()
// Bucle para el juego
void Game::run()
{
while (section->name == SECTION_PROG_GAME)
while (section::name == section::NAME_GAME)
{
#ifndef RECORDING
checkInput();
@@ -2503,9 +2502,9 @@ void Game::updateGameCompleted()
if (gameCompletedCounter == GAME_COMPLETED_END)
{
// section->options = SUBSECTION_GAME_GAMEOVER;
section->name = SECTION_PROG_TITLE;
section->options = SECTION_OPTIONS_TITLE_1;
// section::options = SUBSECTION_GAME_GAMEOVER;
section::name = section::NAME_TITLE;
section::options = section::OPTIONS_TITLE_1;
}
}
@@ -2563,7 +2562,7 @@ void Game::checkEvents()
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section->name = SECTION_PROG_QUIT;
section::name = section::NAME_QUIT;
break;
}
@@ -2815,12 +2814,12 @@ int Game::getController(int playerId)
}
// Termina
void Game::quit(int code)
void Game::quit(section::options_e code)
{
if (screen->notificationsAreActive())
{
section->name = SECTION_PROG_QUIT;
section->options = code;
section::name = section::NAME_QUIT;
section::options = code;
}
else
{

View File

@@ -22,6 +22,7 @@
#include "manage_hiscore_table.h"
#include "explosions.h"
#include "enemy_formations.h"
#include "section.h"
#include <iostream>
#define GAME_MODE_DEMO_OFF false
@@ -107,7 +108,6 @@ private:
Screen *screen; // Objeto encargado de dibujar en pantalla
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
Input *input; // Manejador de entrada
section_t *section; // Seccion actual dentro del juego
Scoreboard *scoreboard; // Objeto para dibujar el marcador
Background *background; // Objeto para dibujar el fondo del juego
Explosions *explosions; // Objeto para dibujar explosiones
@@ -444,11 +444,11 @@ private:
int getController(int playerId);
// Termina
void quit(int code);
void quit(section::options_e code);
public:
// Constructor
Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music);
Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, JA_Music_t *music);
// Destructor
~Game();

View File

@@ -4,13 +4,12 @@
#include <iostream>
// Constructor
HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music)
HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, JA_Music_t *music)
{
// Copia punteros
this->screen = screen;
this->asset = asset;
this->input = input;
this->section = section;
this->music = music;
renderer = screen->getRenderer();
@@ -25,7 +24,7 @@ HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, section_t
SDL_SetTextureBlendMode(backbuffer, SDL_BLENDMODE_BLEND);
// Inicializa variables
section->name = SECTION_PROG_HI_SCORE_TABLE;
section::name = section::NAME_HI_SCORE_TABLE;
ticks = 0;
ticksSpeed = 15;
counter = 0;
@@ -175,7 +174,7 @@ void HiScoreTable::checkEvents()
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section->name = SECTION_PROG_QUIT;
section::name = section::NAME_QUIT;
break;
}
@@ -196,7 +195,7 @@ void HiScoreTable::checkInput()
// Comprueba si se sale con el teclado
if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
{
quit(SECTION_OPTIONS_QUIT_NORMAL);
quit(section::OPTIONS_QUIT_NORMAL);
return;
}
@@ -204,8 +203,8 @@ void HiScoreTable::checkInput()
if (input->checkAnyButtonPressed())
{
JA_StopMusic();
section->name = SECTION_PROG_TITLE;
section->options = SECTION_OPTIONS_TITLE_1;
section::name = section::NAME_TITLE;
section::options = section::OPTIONS_TITLE_1;
return;
}
@@ -214,14 +213,14 @@ void HiScoreTable::checkInput()
// Comprueba si se sale con el mando
if (input->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
quit(SECTION_OPTIONS_QUIT_SHUTDOWN);
quit(section::OPTIONS_QUIT_SHUTDOWN);
return;
}
// Comprueba si se va a resetear el juego
if (input->checkModInput(input_service, input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
section->name = SECTION_PROG_LOGO;
section::name = section::NAME_LOGO;
screen->showNotification("Reset");
return;
}
@@ -244,7 +243,7 @@ void HiScoreTable::checkInput()
// Bucle para la pantalla de instrucciones
void HiScoreTable::run()
{
while (section->name == SECTION_PROG_HI_SCORE_TABLE)
while (section::name == section::NAME_HI_SCORE_TABLE)
{
checkInput();
update();
@@ -308,7 +307,7 @@ void HiScoreTable::updateFade()
if (fade->hasEnded() && fadeMode == FADE_OUT)
{
section->name = SECTION_PROG_INSTRUCTIONS;
section::name = section::NAME_INSTRUCTIONS;
}
}
@@ -337,12 +336,12 @@ std::string HiScoreTable::format(int number)
}
// Termina
void HiScoreTable::quit(int code)
void HiScoreTable::quit(section::options_e code)
{
if (screen->notificationsAreActive())
{
section->name = SECTION_PROG_QUIT;
section->options = code;
section::name = section::NAME_QUIT;
section::options = code;
}
else
{

View File

@@ -12,6 +12,7 @@
#include "lang.h"
#include "fade.h"
#include "background.h"
#include "section.h"
/*
Esta clase gestiona un estado del programa. Se encarga de mostrar la tabla con las puntuaciones
@@ -38,7 +39,6 @@ private:
Fade *fade; // Objeto para renderizar fades
Text *text; // Objeto para escribir texto
JA_Music_t *music; // Musica de fondo
section_t *section; // Estado del bucle principal para saber si continua o se sale
// Variables
Uint16 counter; // Contador
@@ -76,11 +76,11 @@ private:
void updateFade();
// Termina
void quit(int code);
void quit(section::options_e code);
public:
// Constructor
HiScoreTable(Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music);
HiScoreTable(Screen *screen, Asset *asset, Input *input, JA_Music_t *music);
// Destructor
~HiScoreTable();

View File

@@ -4,13 +4,12 @@
#include <iostream>
// Constructor
Instructions::Instructions(Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music)
Instructions::Instructions(Screen *screen, Asset *asset, Input *input, JA_Music_t *music)
{
// Copia los punteros
this->screen = screen;
this->asset = asset;
this->input = input;
this->section = section;
this->music = music;
renderer = screen->getRenderer();
@@ -29,7 +28,7 @@ Instructions::Instructions(Screen *screen, Asset *asset, Input *input, section_t
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
// Inicializa variables
section->name = SECTION_PROG_INSTRUCTIONS;
section::name = section::NAME_INSTRUCTIONS;
ticks = 0;
ticksSpeed = 15;
counter = 0;
@@ -252,8 +251,8 @@ void Instructions::update()
// Comprueba si el contador ha llegado al final
if (counter == counterEnd)
{
section->name = SECTION_PROG_TITLE;
section->options = SECTION_OPTIONS_TITLE_1;
section::name = section::NAME_TITLE;
section::options = section::OPTIONS_TITLE_1;
}
}
}
@@ -305,7 +304,7 @@ void Instructions::checkEvents()
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section->name = SECTION_PROG_QUIT;
section::name = section::NAME_QUIT;
break;
}
@@ -326,7 +325,7 @@ void Instructions::checkInput()
// Comprueba si se sale con el teclado
if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
{
quit(SECTION_OPTIONS_QUIT_NORMAL);
quit(section::OPTIONS_QUIT_NORMAL);
return;
}
@@ -334,8 +333,8 @@ void Instructions::checkInput()
if (input->checkAnyButtonPressed())
{
JA_StopMusic();
section->name = SECTION_PROG_TITLE;
section->options = SECTION_OPTIONS_TITLE_1;
section::name = section::NAME_TITLE;
section::options = section::OPTIONS_TITLE_1;
return;
}
@@ -344,14 +343,14 @@ void Instructions::checkInput()
// Comprueba si se sale con el mando
if (input->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
quit(SECTION_OPTIONS_QUIT_SHUTDOWN);
quit(section::OPTIONS_QUIT_SHUTDOWN);
return;
}
// Comprueba si se va a resetear el juego
if (input->checkModInput(input_service, input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
section->name = SECTION_PROG_LOGO;
section::name = section::NAME_LOGO;
screen->showNotification("Reset");
return;
}
@@ -374,7 +373,7 @@ void Instructions::checkInput()
// Bucle para la pantalla de instrucciones
void Instructions::run()
{
while (section->name == SECTION_PROG_INSTRUCTIONS)
while (section::name == section::NAME_INSTRUCTIONS)
{
checkInput();
update();
@@ -384,12 +383,12 @@ void Instructions::run()
}
// Termina
void Instructions::quit(int code)
void Instructions::quit(section::options_e code)
{
if (screen->notificationsAreActive())
{
section->name = SECTION_PROG_QUIT;
section->options = code;
section::name = section::NAME_QUIT;
section::options = code;
}
else
{

View File

@@ -12,6 +12,7 @@
#include "lang.h"
#include "tiledbg.h"
#include "fade.h"
#include "section.h"
/*
Esta clase gestiona un estado del programa. Se encarga de poner en pantalla
@@ -44,7 +45,6 @@ private:
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
// Variables
int counter; // Contador
@@ -83,11 +83,11 @@ private:
void reloadTextures();
// Termina
void quit(int code);
void quit(section::options_e code);
public:
// Constructor
Instructions(Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music);
Instructions(Screen *screen, Asset *asset, Input *input, JA_Music_t *music);
// Destructor
~Instructions();

View File

@@ -3,13 +3,12 @@
#include "options.h"
// Constructor
Intro::Intro(Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music)
Intro::Intro(Screen *screen, Asset *asset, Input *input, JA_Music_t *music)
{
// Copia los punteros
this->screen = screen;
this->asset = asset;
this->input = input;
this->section = section;
this->music = music;
SDL_Renderer *renderer = screen->getRenderer();
@@ -19,8 +18,8 @@ Intro::Intro(Screen *screen, Asset *asset, Input *input, section_t *section, JA_
text = new Text(asset->get("nokia.png"), asset->get("nokia.txt"), renderer);
// Inicializa variables
section->name = SECTION_PROG_INTRO;
section->options = 0;
section::name = section::NAME_INTRO;
section::options = section::OPTIONS_NULL;
ticks = 0;
ticksSpeed = 15;
scene = 1;
@@ -175,7 +174,7 @@ void Intro::checkEvents()
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section->name = SECTION_PROG_QUIT;
section::name = section::NAME_QUIT;
break;
}
@@ -196,7 +195,7 @@ void Intro::checkInput()
// Comprueba si se sale con el teclado
if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
{
quit(SECTION_OPTIONS_QUIT_NORMAL);
quit(section::OPTIONS_QUIT_NORMAL);
return;
}
@@ -204,8 +203,8 @@ void Intro::checkInput()
if (input->checkAnyButtonPressed())
{
JA_StopMusic();
section->name = SECTION_PROG_TITLE;
section->options = SECTION_OPTIONS_TITLE_1;
section::name = section::NAME_TITLE;
section::options = section::OPTIONS_TITLE_1;
return;
}
@@ -214,14 +213,14 @@ void Intro::checkInput()
// Comprueba si se sale con el mando
if (input->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
quit(SECTION_OPTIONS_QUIT_SHUTDOWN);
quit(section::OPTIONS_QUIT_SHUTDOWN);
return;
}
// Comprueba si se va a resetear el juego
if (input->checkModInput(input_service, input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
section->name = SECTION_PROG_INIT;
section::name = section::NAME_INIT;
screen->showNotification("Reset");
return;
}
@@ -386,8 +385,8 @@ void Intro::updateScenes()
bitmaps[5]->setEnabled(false);
texts[8]->setEnabled(false);
JA_StopMusic();
section->name = SECTION_PROG_TITLE;
section->options = SECTION_OPTIONS_TITLE_1;
section::name = section::NAME_TITLE;
section::options = section::OPTIONS_TITLE_1;
}
break;
@@ -453,7 +452,7 @@ void Intro::run()
{
JA_PlayMusic(music, 0);
while (section->name == SECTION_PROG_INTRO)
while (section::name == section::NAME_INTRO)
{
checkInput();
update();
@@ -463,12 +462,12 @@ void Intro::run()
}
// Termina
void Intro::quit(int code)
void Intro::quit(section::options_e code)
{
if (screen->notificationsAreActive())
{
section->name = SECTION_PROG_QUIT;
section->options = code;
section::name = section::NAME_QUIT;
section::options = code;
}
else
{

View File

@@ -11,6 +11,7 @@
#include "const.h"
#include "lang.h"
#include <vector>
#include "section.h"
/*
Esta clase gestiona un estado del programa. Se encarga de mostrar la secuencia
@@ -30,7 +31,6 @@ private:
std::vector<SmartSprite *> bitmaps; // Vector con los sprites inteligentes para los dibujos de la intro
std::vector<Writer *> texts; // Textos de la intro
Text *text; // Textos de la intro
section_t *section; // Estado del bucle principal para saber si continua o se sale
// Variables
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
@@ -57,11 +57,11 @@ private:
void reloadTextures();
// Termina
void quit(int code);
void quit(section::options_e code);
public:
// Constructor
Intro(Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music);
Intro(Screen *screen, Asset *asset, Input *input, JA_Music_t *music);
// Destructor
~Intro();

View File

@@ -4,13 +4,12 @@
#include <iostream>
// Constructor
Logo::Logo(Screen *screen, Asset *asset, Input *input, section_t *section)
Logo::Logo(Screen *screen, Asset *asset, Input *input)
{
// Copia la dirección de los objetos
this->screen = screen;
this->asset = asset;
this->input = input;
this->section = section;
SDL_Renderer *renderer = screen->getRenderer();
// Reserva memoria para los punteros
@@ -21,7 +20,7 @@ Logo::Logo(Screen *screen, Asset *asset, Input *input, section_t *section)
// Inicializa variables
counter = 0;
section->name = SECTION_PROG_LOGO;
section::name = section::NAME_LOGO;
ticks = 0;
ticksSpeed = 15;
showSinceSprite_cm = 70;
@@ -86,7 +85,7 @@ void Logo::checkEvents()
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section->name = SECTION_PROG_QUIT;
section::name = section::NAME_QUIT;
break;
}
@@ -107,14 +106,14 @@ void Logo::checkInput()
// Comprueba si se sale con el teclado
if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
{
quit(SECTION_OPTIONS_QUIT_NORMAL);
quit(section::OPTIONS_QUIT_NORMAL);
return;
}
// Comprueba si se va a resetear el juego
if (input->checkInput(input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
{
section->name = SECTION_PROG_INIT;
section::name = section::NAME_INIT;
screen->showNotification("Reset");
return;
}
@@ -123,8 +122,8 @@ void Logo::checkInput()
if (input->checkAnyButtonPressed())
{
JA_StopMusic();
section->name = SECTION_PROG_TITLE;
section->options = SECTION_OPTIONS_TITLE_1;
section::name = section::NAME_TITLE;
section::options = section::OPTIONS_TITLE_1;
return;
}
@@ -133,14 +132,14 @@ void Logo::checkInput()
// Comprueba si se sale con el mando
if (input->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
quit(SECTION_OPTIONS_QUIT_SHUTDOWN);
quit(section::OPTIONS_QUIT_SHUTDOWN);
return;
}
// Comprueba si se va a resetear el juego
if (input->checkModInput(input_service, input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
section->name = SECTION_PROG_INIT;
section::name = section::NAME_INIT;
screen->showNotification("Reset");
return;
}
@@ -305,7 +304,7 @@ void Logo::update()
// Comprueba si ha terminado el logo
if (counter == endLogo_cm + postLogoDuration)
{
section->name = SECTION_PROG_INTRO;
section::name = section::NAME_INTRO;
}
// Comprueba si se ha de mostrar el sprite
@@ -342,7 +341,7 @@ void Logo::run()
// Detiene la música
JA_StopMusic();
while (section->name == SECTION_PROG_LOGO)
while (section::name == section::NAME_LOGO)
{
checkInput();
update();
@@ -352,12 +351,12 @@ void Logo::run()
}
// Termina
void Logo::quit(int code)
void Logo::quit(section::options_e code)
{
if (screen->notificationsAreActive())
{
section->name = SECTION_PROG_QUIT;
section->options = code;
section::name = section::NAME_QUIT;
section::options = code;
}
else
{

View File

@@ -1,15 +1,16 @@
#pragma once
#include <SDL2/SDL.h>
#include <vector>
#include "asset.h"
#include "const.h"
#include "input.h"
#include "jail_audio.h"
#include "lang.h"
#include "screen.h"
#include "section.h"
#include "sprite.h"
#include "utils.h"
#include "const.h"
#include "lang.h"
#include <vector>
/*
Esta clase gestiona un estado del programa. Se encarga de dibujar por pantalla el
@@ -32,7 +33,6 @@ private:
SDL_Event *eventHandler; // Manejador de eventos
std::vector<Sprite *> jailSprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
Sprite *sinceSprite; // Sprite para manejar la sinceTexture
section_t *section; // Estado del bucle principal para saber si continua o se sale
// Variables
std::vector<color_t> color; // Vector con los colores para el fade
@@ -68,11 +68,11 @@ private:
void reloadTextures();
// Termina
void quit(int code);
void quit(section::options_e code);
public:
// Constructor
Logo(Screen *screen, Asset *asset, Input *input, section_t *section);
Logo(Screen *screen, Asset *asset, Input *input);
// Destructor
~Logo();

7
source/section.cpp Normal file
View File

@@ -0,0 +1,7 @@
#include "section.h"
namespace section
{
name_e name;
options_e options;
}

35
source/section.h Normal file
View File

@@ -0,0 +1,35 @@
#pragma once
#include <SDL2/SDL.h>
namespace section
{
// Secciones del programa
enum name_e
{
NAME_INIT = 0,
NAME_LOGO = 1,
NAME_INTRO = 2,
NAME_TITLE = 3,
NAME_GAME = 4,
NAME_HI_SCORE_TABLE = 5,
NAME_GAME_DEMO = 6,
NAME_INSTRUCTIONS = 7,
NAME_QUIT = 8,
};
// Opciones para la sección
enum options_e
{
OPTIONS_GAME_PLAY_1P = 0,
OPTIONS_GAME_PLAY_2P = 1,
OPTIONS_TITLE_1 = 2,
OPTIONS_TITLE_2 = 3,
OPTIONS_QUIT_NORMAL = 4,
OPTIONS_QUIT_SHUTDOWN = 5,
OPTIONS_NULL = 6,
};
extern name_e name;
extern options_e options;
}

View File

@@ -3,13 +3,12 @@
#include "options.h"
// Constructor
Title::Title(Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music)
Title::Title(Screen *screen, Asset *asset, Input *input, JA_Music_t *music)
{
// Copia las direcciones de los punteros y objetos
this->screen = screen;
this->input = input;
this->asset = asset;
this->section = section;
this->music = music;
SDL_Renderer *renderer = screen->getRenderer();
@@ -30,7 +29,7 @@ Title::Title(Screen *screen, Asset *asset, Input *input, section_t *section, JA_
gameLogo = new GameLogo(renderer, screen, asset, param.game.gameArea.centerX, param.title.titleCCPosition);
gameLogo->enable();
defineButtons = new DefineButtons(input, text2, section);
defineButtons = new DefineButtons(input, text2);
// Inicializa los valores
init();
@@ -58,9 +57,9 @@ Title::~Title()
void Title::init()
{
// Inicializa variables
section->options = SECTION_OPTIONS_TITLE_1;
section::options = section::OPTIONS_TITLE_1;
counter = 0;
nextSection.name = SECTION_PROG_GAME;
nextSection.name = section::NAME_GAME;
postFade = 0;
ticks = 0;
ticksSpeed = 15;
@@ -92,28 +91,28 @@ void Title::update()
{
if (postFade == -1)
{
section->name = SECTION_PROG_GAME_DEMO;
section::name = section::NAME_GAME_DEMO;
}
else
{
section->name = SECTION_PROG_GAME;
section->options = postFade;
section::name = section::NAME_GAME;
section::options = postFade == 1 ? section::OPTIONS_GAME_PLAY_1P : section::OPTIONS_GAME_PLAY_2P;
JA_StopMusic();
}
}
// Sección 1 - Titulo animandose
if (section->options == SECTION_OPTIONS_TITLE_1)
if (section::options == section::OPTIONS_TITLE_1)
{
gameLogo->update();
if (gameLogo->hasFinished())
{
section->options = SECTION_OPTIONS_TITLE_2;
section::options = section::OPTIONS_TITLE_2;
}
}
// Sección 2 - La pantalla con el titulo, el fondo animado y la música
else if (section->options == SECTION_OPTIONS_TITLE_2)
else if (section::options == section::OPTIONS_TITLE_2)
{
// El contador solo sube si no estamos definiendo botones
if (!defineButtons->isEnabled())
@@ -161,7 +160,7 @@ void Title::render()
// Dibuja el logo con el título del juego
gameLogo->render();
if (section->options == SECTION_OPTIONS_TITLE_2)
if (section::options == section::OPTIONS_TITLE_2)
{
const color_t shadow = {0x14, 0x87, 0xc4};
// 'PULSA 1P o 2P PARA JUGAR'
@@ -202,7 +201,7 @@ void Title::checkEvents()
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section->name = SECTION_PROG_QUIT;
section::name = section::NAME_QUIT;
break;
}
@@ -251,14 +250,14 @@ void Title::checkInput()
// Comprueba si se sale con el teclado
if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
{
quit(SECTION_OPTIONS_QUIT_NORMAL);
quit(section::OPTIONS_QUIT_NORMAL);
return;
}
// Comprueba el teclado para empezar a jugar
if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
{
if (section->options == SECTION_OPTIONS_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
if (section::options == section::OPTIONS_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
{
fade->activate();
postFade = options.controller[0].playerId;
@@ -275,14 +274,14 @@ void Title::checkInput()
// Comprueba si se sale con el mando
if (input->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
quit(SECTION_OPTIONS_QUIT_SHUTDOWN);
quit(section::OPTIONS_QUIT_SHUTDOWN);
return;
}
// Comprueba si se va a resetear el juego
if (input->checkModInput(input_service, input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
section->name = SECTION_PROG_LOGO;
section::name = section::NAME_LOGO;
screen->showNotification("Reset");
return;
}
@@ -314,7 +313,7 @@ void Title::checkInput()
// Comprueba el botón de START de los mandos
if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
if (section->options == SECTION_OPTIONS_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
if (section::options == section::OPTIONS_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
{
fade->activate();
postFade = options.controller[i].playerId;
@@ -332,7 +331,7 @@ void Title::checkInput()
// Bucle para el titulo del juego
void Title::run()
{
while (section->name == SECTION_PROG_TITLE)
while (section::name == section::NAME_TITLE)
{
checkInput();
update();
@@ -398,12 +397,12 @@ void Title::swapControllers()
}
// Termina
void Title::quit(int code)
void Title::quit(section::options_e code)
{
if (screen->notificationsAreActive())
{
section->name = SECTION_PROG_QUIT;
section->options = code;
section::name = section::NAME_QUIT;
section::options = code;
}
else
{

View File

@@ -20,6 +20,7 @@
#include "tiledbg.h"
#include "game_logo.h"
#include "define_buttons.h"
#include "section.h"
// Textos
#define TEXT_COPYRIGHT "@2020,2024 JailDesigner"
@@ -51,7 +52,6 @@ private:
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
Input *input; // Objeto para leer las entradas de teclado o mando
SDL_Event *eventHandler; // Manejador de eventos
section_t *section; // Indicador para el bucle del titulo
Tiledbg *tiledbg; // Objeto para dibujar el mosaico animado de fondo
GameLogo *gameLogo; // Objeto para dibujar el logo con el título del juego
DefineButtons *defineButtons; // Objeto para definir los botones del joystic
@@ -98,11 +98,11 @@ private:
void swapControllers();
// Termina
void quit(int code);
void quit(section::options_e code);
public:
// Constructor
Title(Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music);
Title(Screen *screen, Asset *asset, Input *input, JA_Music_t *music);
// Destructor
~Title();