From 9513a6c57e735be99c8fed80c74acd2182db9154 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 23 Sep 2023 00:02:49 +0200 Subject: [PATCH] =?UTF-8?q?La=20secci=C3=B3n=20del=20programa=20se=20contr?= =?UTF-8?q?ola=20ahora=20mediante=20un=20puntero=20a=20una=20variable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/director.cpp | 30 +++++++-------- source/director.h | 2 +- source/enter_id.cpp | 8 +--- source/enter_id.h | 3 +- source/game.cpp | 61 ++++++++++++++++--------------- source/game.h | 62 +++++++++++++++---------------- source/hiscore_table.cpp | 27 +++++++------- source/hiscore_table.h | 6 +-- source/instructions.cpp | 24 ++++++------ source/instructions.h | 4 +- source/intro.cpp | 25 ++++++------- source/intro.h | 6 +-- source/logo.cpp | 25 ++++++------- source/logo.h | 6 +-- source/title.cpp | 79 ++++++++++++++++++---------------------- source/title.h | 12 +++--- 16 files changed, 179 insertions(+), 201 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index 2de7244..d630df7 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -16,7 +16,8 @@ Director::Director(int argc, char *argv[]) { // Inicializa variables - section.name = SECTION_PROG_LOGO; + section = new section_t(); + section->name = SECTION_PROG_LOGO; // Inicializa las opciones del programa initOptions(); @@ -73,6 +74,7 @@ Director::~Director() delete screen; delete lang; delete options; + delete section; SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); @@ -662,47 +664,41 @@ bool Director::saveConfigFile() return success; } -// Establece el valor de la variable -void Director::setSection(section_t section) -{ - this->section = section; -} - void Director::runLogo() { - logo = new Logo(renderer, screen, asset, input); - setSection(logo->run()); + logo = new Logo(renderer, screen, asset, input, section); + logo->run(); delete logo; } void Director::runIntro() { - intro = new Intro(renderer, screen, asset, input, lang); - setSection(intro->run()); + intro = new Intro(renderer, screen, asset, input, lang, section); + intro->run(); delete intro; } void Director::runTitle() { title = new Title(renderer, screen, input, asset, options, lang, section); - setSection(title->run()); + title->run(); delete title; } void Director::runGame() { - const int numPlayers = section.subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2; - game = new Game(numPlayers, 0, renderer, screen, asset, lang, input, false, options); - setSection(game->run()); + const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2; + game = new Game(numPlayers, 0, renderer, screen, asset, lang, input, false, options, section); + game->run(); delete game; } void Director::run() { // Bucle principal - while (section.name != SECTION_PROG_QUIT) + while (section->name != SECTION_PROG_QUIT) { - switch (section.name) + switch (section->name) { case SECTION_PROG_LOGO: runLogo(); diff --git a/source/director.h b/source/director.h index fa89f8f..a9594ed 100644 --- a/source/director.h +++ b/source/director.h @@ -43,10 +43,10 @@ private: Input *input; // Objeto Input para gestionar las entradas Lang *lang; // Objeto para gestionar los textos en diferentes idiomas Asset *asset; // Objeto que gestiona todos los ficheros de recursos + section_t *section; // Sección y subsección actual del programa; // Variables struct options_t *options; // Variable con todas las opciones del programa - section_t section; // Sección y subsección actual del programa; std::string executablePath; // Path del ejecutable std::string systemFolder; // Carpeta del sistema donde guardar datos diff --git a/source/enter_id.cpp b/source/enter_id.cpp index 42a3753..63be05b 100644 --- a/source/enter_id.cpp +++ b/source/enter_id.cpp @@ -5,7 +5,7 @@ #include // Constructor -EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options) +EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t *section) { // Copia la dirección de los objetos this->renderer = renderer; @@ -165,12 +165,6 @@ void EnterID::checkEvents() screen->setWindowSize(4); break; } - - else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F5) - { - switchPalette(); - break; - } } } } diff --git a/source/enter_id.h b/source/enter_id.h index 602e6ba..5fb3240 100644 --- a/source/enter_id.h +++ b/source/enter_id.h @@ -30,6 +30,7 @@ private: SDL_Texture *textTexture; // Textura para dibujar el texto Text *text; // Objeto para escribir texto en pantalla Texture *texture; // Textura para la fuente para el texto + section_t *section; // Estado del bucle principal para saber si continua o se sale // Variables bool loopRunning; // Indica si ha de terminar el bucle principal @@ -66,7 +67,7 @@ private: public: // Constructor - EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options); + EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t *section); // Destructor ~EnterID(); diff --git a/source/game.cpp b/source/game.cpp index 3626b61..72c0f27 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -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; } } } diff --git a/source/game.h b/source/game.h index 8da70e1..d5ef460 100644 --- a/source/game.h +++ b/source/game.h @@ -120,6 +120,7 @@ private: Asset *asset; // Objeto que gestiona todos los ficheros de recursos Lang *lang; // Objeto para gestionar los textos en diferentes idiomas Input *input; // Manejador de entrada + section_t *section; // Seccion actual dentro del juego std::vector players; // Vector con los jugadores std::vector balloons; // Vector con los globos @@ -127,21 +128,21 @@ private: std::vector items; // Vector con los items std::vector smartSprites; // Vector con los smartsprites - Texture *bulletTexture; // Textura para las balas - std::vector itemTextures; // Vector con las texturas de los items - std::vector balloonTextures; // Vector con las texturas de los globos - std::vector player1Textures; // Vector con las texturas del jugador - std::vector player2Textures; // Vector con las texturas del jugador + Texture *bulletTexture; // Textura para las balas + std::vector itemTextures; // Vector con las texturas de los items + std::vector balloonTextures; // Vector con las texturas de los globos + std::vector player1Textures; // Vector con las texturas del jugador + std::vector player2Textures; // Vector con las texturas del jugador std::vector> playerTextures; // Vector con todas las texturas de los jugadores; - Texture *gameBuildingsTexture; // Textura con los edificios de fondo - Texture *gameCloudsTexture; // Textura con las nubes de fondo - Texture *gameGrassTexture; // Textura con la hierba del suelo + Texture *gameBuildingsTexture; // Textura con los edificios de fondo + Texture *gameCloudsTexture; // Textura con las nubes de fondo + Texture *gameGrassTexture; // Textura con la hierba del suelo Texture *gamePowerMeterTexture; // Textura con el marcador de poder de la fase - Texture *gameSkyColorsTexture; // Textura con los diferentes colores de fondo del juego - Texture *gameTextTexture; // Textura para los sprites con textos - Texture *gameOverTexture; // Textura para la pantalla de game over - Texture *gameOverEndTexture; // Textura para la pantalla de game over de acabar el juego + Texture *gameSkyColorsTexture; // Textura con los diferentes colores de fondo del juego + Texture *gameTextTexture; // Textura para los sprites con textos + Texture *gameOverTexture; // Textura para la pantalla de game over + Texture *gameOverEndTexture; // Textura para la pantalla de game over de acabar el juego std::vector *> itemAnimations; // Vector con las animaciones de los items std::vector *> playerAnimations; // Vector con las animaciones del jugador @@ -174,23 +175,23 @@ private: Sprite *gameOverSprite; // Sprite para dibujar los graficos del game over Sprite *gameOverEndSprite; // Sprite para dibujar los graficos del game over de acabar el juego - JA_Sound_t* balloonSound; // Sonido para la explosión del globo - JA_Sound_t* bulletSound; // Sonido para los disparos - JA_Sound_t* playerCollisionSound; // Sonido para la colisión del jugador con un enemigo - JA_Sound_t* hiScoreSound; // Sonido para cuando se alcanza la máxima puntuación - JA_Sound_t* itemDropSound; // Sonido para cuando se genera un item - JA_Sound_t* itemPickUpSound; // Sonido para cuando se recoge un item - JA_Sound_t* coffeeOutSound; // Sonido para cuando el jugador pierde el café al recibir un impacto - JA_Sound_t* stageChangeSound; // Sonido para cuando se cambia de fase - JA_Sound_t* bubble1Sound; // Sonido para cuando el jugador muere - JA_Sound_t* bubble2Sound; // Sonido para cuando el jugador muere - JA_Sound_t* bubble3Sound; // Sonido para cuando el jugador muere - JA_Sound_t* bubble4Sound; // Sonido para cuando el jugador muere - JA_Sound_t* clockSound; // Sonido para cuando se detiene el tiempo con el item reloj - JA_Sound_t* powerBallSound; // Sonido para cuando se explota una Power Ball - JA_Sound_t* coffeeMachineSound; // Sonido para cuando la máquina de café toca el suelo + JA_Sound_t *balloonSound; // Sonido para la explosión del globo + JA_Sound_t *bulletSound; // Sonido para los disparos + JA_Sound_t *playerCollisionSound; // Sonido para la colisión del jugador con un enemigo + JA_Sound_t *hiScoreSound; // Sonido para cuando se alcanza la máxima puntuación + JA_Sound_t *itemDropSound; // Sonido para cuando se genera un item + JA_Sound_t *itemPickUpSound; // Sonido para cuando se recoge un item + JA_Sound_t *coffeeOutSound; // Sonido para cuando el jugador pierde el café al recibir un impacto + JA_Sound_t *stageChangeSound; // Sonido para cuando se cambia de fase + JA_Sound_t *bubble1Sound; // Sonido para cuando el jugador muere + JA_Sound_t *bubble2Sound; // Sonido para cuando el jugador muere + JA_Sound_t *bubble3Sound; // Sonido para cuando el jugador muere + JA_Sound_t *bubble4Sound; // Sonido para cuando el jugador muere + JA_Sound_t *clockSound; // Sonido para cuando se detiene el tiempo con el item reloj + JA_Sound_t *powerBallSound; // Sonido para cuando se explota una Power Ball + JA_Sound_t *coffeeMachineSound; // Sonido para cuando la máquina de café toca el suelo - JA_Music_t* gameMusic; // Musica de fondo + JA_Music_t *gameMusic; // Musica de fondo // Variables int numPlayers; // Numero de jugadores @@ -198,7 +199,6 @@ private: Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 hiScore; // Puntuación máxima bool hiScoreAchieved; // Indica si se ha superado la puntuación máxima - section_t section; // Seccion actual dentro del juego stage_t stage[10]; // Variable con los datos de cada pantalla Uint8 currentStage; // Indica la fase actual Uint8 stageBitmapCounter; // Contador para el tiempo visible del texto de Stage @@ -513,13 +513,13 @@ private: public: // Constructor - Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options); + Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options, section_t *section); // Destructor ~Game(); // Bucle para el juego - section_t run(); + void run(); }; #endif diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index af2e3ac..4194a24 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -5,7 +5,7 @@ const Uint8 SELF = 0; // Constructor -HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options) +HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, section_t *section) { // Copia los punteros this->renderer = renderer; @@ -13,6 +13,7 @@ HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, this->asset = asset; this->input = input; this->lang = lang; + this->section = section; // Reserva memoria para los punteros eventHandler = new SDL_Event(); @@ -30,7 +31,7 @@ HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, } // Inicializa variables - section.name = SELF; + section->name = SELF; ticks = 0; ticksSpeed = 15; manualQuit = false; @@ -68,8 +69,8 @@ void HiScoreTable::update() if (counter == counterEnd) { - section.name = SECTION_PROG_TITLE; - section.subsection = SUBSECTION_TITLE_1; + section->name = SECTION_PROG_TITLE; + section->subsection = SUBSECTION_TITLE_1; } } else @@ -78,8 +79,8 @@ void HiScoreTable::update() if (manualQuit) { - section.name = SECTION_PROG_TITLE; - section.subsection = SUBSECTION_TITLE_3; + section->name = SECTION_PROG_TITLE; + section->subsection = SUBSECTION_TITLE_3; } } } @@ -180,7 +181,7 @@ void HiScoreTable::checkEventHandler() // Evento de salida de la aplicación if (eventHandler->type == SDL_QUIT) { - section.name = SECTION_PROG_QUIT; + section->name = SECTION_PROG_QUIT; break; } } @@ -191,7 +192,7 @@ void HiScoreTable::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)) @@ -214,8 +215,8 @@ void HiScoreTable::checkInput() if (mode == mhst_auto) { JA_StopMusic(); - section.name = SECTION_PROG_TITLE; - section.subsection = SUBSECTION_TITLE_1; + section->name = SECTION_PROG_TITLE; + section->subsection = SUBSECTION_TITLE_1; } else { @@ -228,17 +229,15 @@ void HiScoreTable::checkInput() } // Bucle para la pantalla de instrucciones -section_t HiScoreTable::run(mode_hiScoreTable_e mode) +void HiScoreTable::run(mode_hiScoreTable_e mode) { this->mode = mode; - while (section.name == SELF) + while (section->name == SELF) { update(); render(); } - - return section; } // Transforma un valor numérico en una cadena de 6 cifras diff --git a/source/hiscore_table.h b/source/hiscore_table.h index fbc2ad3..ff201bb 100644 --- a/source/hiscore_table.h +++ b/source/hiscore_table.h @@ -32,11 +32,11 @@ private: Lang *lang; // Objeto para gestionar los textos en diferentes idiomas Text *text; // Objeto para escribir texto options_t *options; // Opciones y parametyros del programa + section_t *section; // Estado del bucle principal para saber si continua o se sale // Variables Uint16 counter; // Contador Uint16 counterEnd; // Valor final para el contador - section_t section; // Estado del bucle principal para saber si continua o se sale Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa bool manualQuit; // Indica si se quiere salir del modo manual @@ -59,13 +59,13 @@ private: public: // Constructor - HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options); + HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, options_t *options, section_t *section); // Destructor ~HiScoreTable(); // Bucle principal - section_t run(mode_hiScoreTable_e mode); + void run(mode_hiScoreTable_e mode); }; #endif diff --git a/source/instructions.cpp b/source/instructions.cpp index c0e1af0..be4a004 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -45,7 +45,7 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, } // Inicializa variables - section.name = SELF; + section->name = SELF; ticks = 0; ticksSpeed = 15; manualQuit = false; @@ -88,8 +88,8 @@ void Instructions::update() if (counter == counterEnd) { - section.name = SECTION_PROG_TITLE; - section.subsection = SUBSECTION_TITLE_1; + section->name = SECTION_PROG_TITLE; + section->subsection = SUBSECTION_TITLE_1; } } else @@ -98,8 +98,8 @@ void Instructions::update() if (manualQuit) { - section.name = SECTION_PROG_TITLE; - section.subsection = SUBSECTION_TITLE_3; + section->name = SECTION_PROG_TITLE; + section->subsection = SUBSECTION_TITLE_3; } } } @@ -214,7 +214,7 @@ void Instructions::checkEvents() // Evento de salida de la aplicación if (eventHandler->type == SDL_QUIT) { - section.name = SECTION_PROG_QUIT; + section->name = SECTION_PROG_QUIT; break; } } @@ -225,7 +225,7 @@ void Instructions::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)) @@ -248,8 +248,8 @@ void Instructions::checkInput() if (mode == m_auto) { JA_StopMusic(); - section.name = SECTION_PROG_TITLE; - section.subsection = SUBSECTION_TITLE_1; + section->name = SECTION_PROG_TITLE; + section->subsection = SUBSECTION_TITLE_1; } else { @@ -262,16 +262,14 @@ void Instructions::checkInput() } // Bucle para la pantalla de instrucciones -section_t Instructions::run(mode_e mode) +void Instructions::run(mode_e mode) { this->mode = mode; - while (section.name == SELF) + while (section->name == SELF) { update(); checkEvents(); render(); } - - return section; } diff --git a/source/instructions.h b/source/instructions.h index ae4b95a..1d5af42 100644 --- a/source/instructions.h +++ b/source/instructions.h @@ -34,11 +34,11 @@ private: Input *input; // Objeto pata gestionar la entrada Lang *lang; // Objeto para gestionar los textos en diferentes idiomas Text *text; // Objeto para escribir texto + section_t *section; // Estado del bucle principal para saber si continua o se sale // Variables Uint16 counter; // Contador Uint16 counterEnd; // Valor final para el contador - section_t section; // Estado del bucle principal para saber si continua o se sale Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa bool manualQuit; // Indica si se quiere salir del modo manual @@ -64,7 +64,7 @@ public: ~Instructions(); // Bucle principal - section_t run(mode_e mode); + void run(mode_e mode); }; #endif diff --git a/source/intro.cpp b/source/intro.cpp index c2e7019..02ba969 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -1,7 +1,7 @@ #include "intro.h" // Constructor -Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang) +Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section) { // Copia los punteros this->renderer = renderer; @@ -9,6 +9,7 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, this->lang = lang; this->asset = asset; this->input = input; + this->section = section; // Reserva memoria para los objetos eventHandler = new SDL_Event(); @@ -19,8 +20,8 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, loadMedia(); // Inicializa variables - section.name = SECTION_PROG_INTRO; - section.subsection = 0; + section->name = SECTION_PROG_INTRO; + section->subsection = 0; ticks = 0; ticksSpeed = 15; scene = 1; @@ -181,7 +182,7 @@ void Intro::checkEvents() // Evento de salida de la aplicación if (eventHandler->type == SDL_QUIT) { - section.name = SECTION_PROG_QUIT; + section->name = SECTION_PROG_QUIT; break; } } @@ -192,7 +193,7 @@ void Intro::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)) @@ -213,8 +214,8 @@ void Intro::checkInput() else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE)) { JA_StopMusic(); - section.name = SECTION_PROG_TITLE; - section.subsection = SUBSECTION_TITLE_1; + section->name = SECTION_PROG_TITLE; + section->subsection = SUBSECTION_TITLE_1; } } @@ -363,8 +364,8 @@ void Intro::updateScenes() bitmaps[5]->setEnabled(false); texts[8]->setEnabled(false); JA_StopMusic(); - section.name = SECTION_PROG_TITLE; - section.subsection = SUBSECTION_TITLE_1; + section->name = SECTION_PROG_TITLE; + section->subsection = SUBSECTION_TITLE_1; } break; @@ -428,16 +429,14 @@ void Intro::render() } // Bucle principal -section_t Intro::run() +void Intro::run() { JA_PlayMusic(music, 0); - while (section.name == SECTION_PROG_INTRO) + while (section->name == SECTION_PROG_INTRO) { update(); checkEvents(); render(); } - - return section; } diff --git a/source/intro.h b/source/intro.h index 013e1bc..5c28524 100644 --- a/source/intro.h +++ b/source/intro.h @@ -29,11 +29,11 @@ private: std::vector bitmaps; // Vector con los sprites inteligentes para los dibujos de la intro std::vector 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 Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa - section_t section; // Estado del bucle principal para saber si continua o se sale JA_Music_t *music; // Musica para la intro int scene; // Indica que escena está activa @@ -57,13 +57,13 @@ private: public: // Constructor - Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang); + Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section); // Destructor ~Intro(); // Bucle principal - section_t run(); + void run(); }; #endif diff --git a/source/logo.cpp b/source/logo.cpp index d8795c1..91539fd 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -4,13 +4,14 @@ #define END_LOGO 200 // Constructor -Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input) +Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, section_t *section) { // Copia la dirección de los objetos this->renderer = renderer; this->screen = screen; this->asset = asset; this->input = input; + this->section = section; // Reserva memoria para los punteros eventHandler = new SDL_Event(); @@ -19,8 +20,8 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input) // Inicializa variables counter = 0; - section.name = SECTION_PROG_LOGO; - section.subsection = 0; + section->name = SECTION_PROG_LOGO; + section->subsection = 0; ticks = 0; ticksSpeed = 15; } @@ -40,8 +41,8 @@ void Logo::checkLogoEnd() { if (counter >= END_LOGO + 20) { - section.name = SECTION_PROG_INTRO; - section.subsection = 0; + section->name = SECTION_PROG_INTRO; + section->subsection = 0; } } @@ -54,7 +55,7 @@ void Logo::checkEvents() // Evento de salida de la aplicación if (eventHandler->type == SDL_QUIT) { - section.name = SECTION_PROG_QUIT; + section->name = SECTION_PROG_QUIT; break; } } @@ -65,7 +66,7 @@ void Logo::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)) @@ -85,8 +86,8 @@ void Logo::checkInput() else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE)) { - section.name = SECTION_PROG_TITLE; - section.subsection = SUBSECTION_TITLE_1; + section->name = SECTION_PROG_TITLE; + section->subsection = SUBSECTION_TITLE_1; } } @@ -144,16 +145,14 @@ void Logo::render() } // Bucle para el logo del juego -section_t Logo::run() +void Logo::run() { JA_StopMusic(); - while (section.name == SECTION_PROG_LOGO) + while (section->name == SECTION_PROG_LOGO) { update(); checkEvents(); render(); } - - return section; } diff --git a/source/logo.h b/source/logo.h index 145736e..669c25b 100644 --- a/source/logo.h +++ b/source/logo.h @@ -24,11 +24,11 @@ private: Texture *texture; // Textura con los graficos SDL_Event *eventHandler; // Manejador de eventos Sprite *sprite; // Sprite con la textura del logo + 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 Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa - section_t section; // Estado del bucle principal para saber si continua o se sale int counter; // Contador // Actualiza las variables del objeto @@ -51,13 +51,13 @@ private: public: // Constructor - Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input); + Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, section_t *section); // Destructor ~Logo(); // Bucle principal - section_t run(); + void run(); }; #endif diff --git a/source/title.cpp b/source/title.cpp index a5131de..45df3b3 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -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 diff --git a/source/title.h b/source/title.h index 7e58a43..b2f2e1a 100644 --- a/source/title.h +++ b/source/title.h @@ -52,6 +52,7 @@ private: HiScoreTable *hiScoreTable; // Objeto para mostrar las mejores puntuaciones online Game *demoGame; // Objeto para lanzar la demo del juego SDL_Event *eventHandler; // Manejador de eventos + section_t *section; // Indicador para el bucle del titulo Texture *dustTexture; // Textura con los graficos del polvo Texture *coffeeTexture; // Textura con los graficos de la palabra coffee @@ -83,7 +84,6 @@ private: float sin[360]; // Vector con los valores del seno precalculados bool menuVisible; // Indicador para saber si se muestra el menu del titulo o la frase intermitente bool demo; // Indica si el modo demo estará activo - section_t section; // Indicador para el bucle del titulo section_t nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint8 postFade; // Opción a realizar cuando termina el fundido @@ -121,13 +121,13 @@ private: void applyOptions(); // Ejecuta la parte donde se muestran las instrucciones - section_t runInstructions(mode_e mode); + void runInstructions(mode_e mode); // Ejecuta la parte donde se muestra la tabla de puntuaciones - section_t runHiScoreTable(mode_hiScoreTable_e mode); + void runHiScoreTable(mode_hiScoreTable_e mode); // Ejecuta el juego en modo demo - section_t runDemoGame(); + void runDemoGame(); // Modifica las opciones para los controles de los jugadores bool updatePlayerInputs(int numPlayer); @@ -146,13 +146,13 @@ private: public: // Constructor - Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t section); + Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section); // Destructor ~Title(); // Bucle para el titulo del juego - section_t run(); + void run(); }; #endif