diff --git a/data/config/param.txt b/data/config/param.txt index 40fed28..756a91e 100644 --- a/data/config/param.txt +++ b/data/config/param.txt @@ -16,4 +16,5 @@ scoreboard.w 300 scoreboard.h 32 #TITLE -pressStart 160 \ No newline at end of file +pressStart 160 +titleCounter 800 \ No newline at end of file diff --git a/source/common/utils.h b/source/common/utils.h index 851aec1..4a79641 100644 --- a/source/common/utils.h +++ b/source/common/utils.h @@ -169,7 +169,8 @@ struct param_t int fadeRandomSquaresMult; // Cantidad de cuadrados que se pintaran cada vez int fadePostDuration; // Duración final del fade - int pressStart; // Posición del texto para empezar a jugar + int pressStart; // Posición del texto para empezar a jugar + int titleCounter; // Tiempo de inactividad del titulo }; // Calcula el cuadrado de la distancia entre dos puntos diff --git a/source/const.h b/source/const.h index 0e24933..cb20287 100644 --- a/source/const.h +++ b/source/const.h @@ -50,7 +50,9 @@ const int GAMECANVAS_THIRD_QUARTER_Y = (HEIGHT / 4) * 3; #define SECTION_PROG_TITLE 2 #define SECTION_PROG_GAME 3 #define SECTION_PROG_HI_SCORE_TABLE 4 -#define SECTION_PROG_QUIT 5 +#define SECTION_PROG_GAME_DEMO 5 +#define SECTION_PROG_INSTRUCTIONS 6 +#define SECTION_PROG_QUIT 7 // Subsecciones #define SUBSECTION_GAME_PLAY_1P 0 @@ -59,7 +61,6 @@ const int GAMECANVAS_THIRD_QUARTER_Y = (HEIGHT / 4) * 3; #define SUBSECTION_GAME_GAMEOVER 3 #define SUBSECTION_TITLE_1 3 #define SUBSECTION_TITLE_2 4 -#define SUBSECTION_TITLE_INSTRUCTIONS 5 // Ningun tipo #define NO_KIND 0 diff --git a/source/director.cpp b/source/director.cpp index 1441d03..0636b0b 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -395,8 +395,8 @@ void Director::initOptions() // Opciones de video options->video.mode = 0; options->video.window.size = 3; - //options->video.window.width = options->video.window.size * param->gameWidth; - //options->video.window.height = options->video.window.size * param->gameHeight; + // options->video.window.width = options->video.window.size * param->gameWidth; + // options->video.window.height = options->video.window.size * param->gameHeight; options->video.filter = FILTER_NEAREST; options->video.vSync = true; options->video.integerScale = true; @@ -638,6 +638,7 @@ bool Director::saveConfigFile() return success; } +// Ejecuta la seccion de juego con el logo void Director::runLogo() { logo = new Logo(renderer, screen, asset, input, param, section); @@ -645,6 +646,7 @@ void Director::runLogo() delete logo; } +// Ejecuta la seccion de juego de la introducción void Director::runIntro() { intro = new Intro(renderer, screen, asset, input, lang, param, section); @@ -652,6 +654,7 @@ void Director::runIntro() delete intro; } +// Ejecuta la seccion de juego con el titulo y los menus void Director::runTitle() { title = new Title(renderer, screen, input, asset, options, lang, param, section); @@ -659,6 +662,7 @@ void Director::runTitle() delete title; } +// Ejecuta la seccion de juego donde se juega void Director::runGame() { const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2; @@ -667,6 +671,30 @@ void Director::runGame() delete game; } +// Ejecuta la parte donde se muestra la tabla de puntuaciones +void Director::runHiScoreTable() +{ + hiScoreTable = new HiScoreTable(renderer, screen, asset, input, lang, param, options, section); + hiScoreTable->run(); + delete hiScoreTable; +} + +// Ejecuta la parte donde se muestran las instrucciones +void Director::runInstructions() +{ + instructions = new Instructions(renderer, screen, asset, input, lang, param, section); + instructions->run(); + delete instructions; +} + +// Ejecuta el juego en modo demo +void Director::runDemoGame() +{ + demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, param, options, section); + demoGame->run(); + delete demoGame; +} + void Director::run() { // Bucle principal @@ -689,6 +717,18 @@ void Director::run() case SECTION_PROG_GAME: runGame(); break; + + case SECTION_PROG_HI_SCORE_TABLE: + runHiScoreTable(); + break; + + case SECTION_PROG_GAME_DEMO: + runDemoGame(); + break; + + case SECTION_PROG_INSTRUCTIONS: + runInstructions(); + break; } } } diff --git a/source/director.h b/source/director.h index 9f123c8..0b95c26 100644 --- a/source/director.h +++ b/source/director.h @@ -34,17 +34,20 @@ class Director { private: // Objetos y punteros - SDL_Window *window; // La ventana donde dibujamos - SDL_Renderer *renderer; // El renderizador de la ventana - Screen *screen; // Objeto encargado de dibujar en pantalla - Logo *logo; // Objeto para la sección del logo - Intro *intro; // Objeto para la sección de la intro - Title *title; // Objeto para la sección del titulo y el menu de opciones - Game *game; // Objeto para la sección del juego - 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; + SDL_Window *window; // La ventana donde dibujamos + SDL_Renderer *renderer; // El renderizador de la ventana + Screen *screen; // Objeto encargado de dibujar en pantalla + Logo *logo; // Objeto para la sección del logo + Intro *intro; // Objeto para la sección de la intro + Title *title; // Objeto para la sección del titulo y el menu de opciones + Game *game; // Objeto para la sección del juego + Instructions *instructions; // Objeto para la sección de las instrucciones + HiScoreTable *hiScoreTable; // Objeto para mostrar las mejores puntuaciones online + Game *demoGame; // Objeto para lanzar la demo del juego + 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 options_t *options; // Variable con todas las opciones del programa @@ -97,6 +100,15 @@ private: // Ejecuta la seccion de juego donde se juega void runGame(); + // Ejecuta la parte donde se muestran las instrucciones + void runInstructions(); + + // Ejecuta la parte donde se muestra la tabla de puntuaciones + void runHiScoreTable(); + + // Ejecuta el juego en modo demo + void runDemoGame(); + public: // Constructor Director(int argc, char *argv[]); diff --git a/source/game.cpp b/source/game.cpp index 3e50f74..6cc3b32 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1564,8 +1564,7 @@ void Game::updatePlayers() { if (demo.enabled) { - section->name = SECTION_PROG_TITLE; - section->subsection = SUBSECTION_TITLE_INSTRUCTIONS; + section->name = SECTION_PROG_HI_SCORE_TABLE; } else { @@ -2817,8 +2816,13 @@ void Game::checkGameInput() } } + // Si pulsamos la tecla de salir, se acaba el programa + if (input->checkInput(input_exit)) + { + section->name = SECTION_PROG_QUIT; + } // Si se pulsa cualquier tecla, se sale del modo demo - if (input->checkAnyInput()) + else if (input->checkAnyInput()) { section->name = SECTION_PROG_TITLE; } @@ -2830,8 +2834,7 @@ void Game::checkGameInput() } else { - section->name = SECTION_PROG_TITLE; - section->subsection = SUBSECTION_TITLE_INSTRUCTIONS; + section->name = SECTION_PROG_HI_SCORE_TABLE; } } // Modo Demo no activo diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index e3be4de..c656056 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -73,25 +73,11 @@ void HiScoreTable::update() // Actualiza el fondo background->update(); - if (mode == mhst_auto) - { // Modo automático - counter++; + counter++; - if (counter == counterEnd) - { - section->name = SECTION_PROG_TITLE; - section->subsection = SUBSECTION_TITLE_1; - } - } - else - { // Modo manual - ++counter %= 60000; - - if (manualQuit) - { - section->name = SECTION_PROG_TITLE; - section->subsection = SUBSECTION_TITLE_2; - } + if (counter == counterEnd) + { + section->name = SECTION_PROG_INSTRUCTIONS; } } } @@ -130,11 +116,6 @@ void HiScoreTable::fillTexture() text->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, (i * spaceBetweenLines) + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor); } - if ((mode == mhst_manual) && (counter % 50 > 14)) - { - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, param->gameHeight - 12, lang->getText(22), 1, orangeColor, 1, shdwTxtColor); - } - // Cambia el destino de renderizado SDL_SetRenderTarget(renderer, temp); } @@ -152,7 +133,7 @@ void HiScoreTable::render() background->render(); // Establece la ventana del backbuffer - viewArea.y = mode == mhst_auto ? std::max(8, param->gameHeight - counter + 100) : 0; + viewArea.y = std::max(8, param->gameHeight - counter + 100); // Copia el backbuffer al renderizador SDL_RenderCopy(renderer, backbuffer, nullptr, &viewArea); @@ -201,27 +182,15 @@ void HiScoreTable::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)) { - if (mode == mhst_auto) - { - JA_StopMusic(); - section->name = SECTION_PROG_TITLE; - section->subsection = SUBSECTION_TITLE_1; - } - else - { - if (counter > 30) - { - manualQuit = true; - } - } + JA_StopMusic(); + section->name = SECTION_PROG_TITLE; + section->subsection = SUBSECTION_TITLE_1; } } // Bucle para la pantalla de instrucciones -void HiScoreTable::run(mode_hiScoreTable_e mode) +void HiScoreTable::run() { - this->mode = mode; - while (section->name == SECTION_PROG_HI_SCORE_TABLE) { update(); diff --git a/source/hiscore_table.h b/source/hiscore_table.h index d6083fe..711880e 100644 --- a/source/hiscore_table.h +++ b/source/hiscore_table.h @@ -15,12 +15,7 @@ #ifndef HISCORE_TABLE_H #define HISCORE_TABLE_H -enum mode_hiScoreTable_e -{ - mhst_manual, - mhst_auto -}; - +// Clase HiScoreTable class HiScoreTable { private: @@ -44,7 +39,6 @@ private: 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 - mode_hiScoreTable_e mode; // Modo en el que se van a ejecutar las instrucciones SDL_Rect viewArea; // Parte de la textura que se muestra en pantalla // Actualiza las variables @@ -73,7 +67,7 @@ public: ~HiScoreTable(); // Bucle principal - void run(mode_hiScoreTable_e mode); + void run(); }; #endif diff --git a/source/instructions.cpp b/source/instructions.cpp index 2c0967f..1e2e6ef 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -1,8 +1,6 @@ #include "instructions.h" #include -const Uint8 SELF = 0; - // Constructor Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, section_t *section) { @@ -41,13 +39,10 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, // Crea un backbuffer para el renderizador backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->gameWidth, param->gameHeight); - if (backbuffer == nullptr) - { - std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; - } + SDL_SetTextureBlendMode(backbuffer, SDL_BLENDMODE_BLEND); // Inicializa variables - section->name = SELF; + section->name = SECTION_PROG_INSTRUCTIONS; ticks = 0; ticksSpeed = 15; manualQuit = false; @@ -84,25 +79,12 @@ void Instructions::update() // Actualiza el contador de ticks ticks = SDL_GetTicks(); - if (mode == m_auto) - { // Modo automático - counter++; + counter++; - if (counter == counterEnd) - { - section->name = SECTION_PROG_TITLE; - section->subsection = SUBSECTION_TITLE_1; - } - } - else - { // Modo manual - ++counter %= 60000; - - if (manualQuit) - { - section->name = SECTION_PROG_TITLE; - section->subsection = SUBSECTION_TITLE_2; - } + if (counter == counterEnd) + { + section->name = SECTION_PROG_TITLE; + section->subsection = SUBSECTION_TITLE_1; } } } @@ -141,11 +123,6 @@ void Instructions::render() text->writeShadowed(84, 140, lang->getText(20), shdwTxtColor); text->writeShadowed(84, 156, lang->getText(21), shdwTxtColor); - if ((mode == m_manual) && (counter % 50 > 14)) - { - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, GAMECANVAS_CENTER_X, param->gameHeight - 12, lang->getText(22), 1, orangeColor, 1, shdwTxtColor); - } - // Disquito sprite->setTexture(itemTextures[0]); sprite->setPos(destRect1); @@ -191,14 +168,7 @@ void Instructions::render() screen->clean(bgColor); // Establece la ventana del backbuffer - if (mode == m_auto) - { - window.y = std::max(8, param->gameHeight - counter + 100); - } - else - { - window.y = 0; - } + window.y = std::max(8, param->gameHeight - counter + 100); // Copia el backbuffer al renderizador SDL_RenderCopy(renderer, backbuffer, nullptr, &window); @@ -247,28 +217,16 @@ void Instructions::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)) { - if (mode == m_auto) - { JA_StopMusic(); section->name = SECTION_PROG_TITLE; section->subsection = SUBSECTION_TITLE_1; - } - else - { - if (counter > 30) - { - manualQuit = true; - } - } } } // Bucle para la pantalla de instrucciones -void Instructions::run(mode_e mode) +void Instructions::run() { - this->mode = mode; - - while (section->name == SELF) + while (section->name == SECTION_PROG_INSTRUCTIONS) { update(); checkEvents(); diff --git a/source/instructions.h b/source/instructions.h index ae12c1f..d777ac6 100644 --- a/source/instructions.h +++ b/source/instructions.h @@ -14,12 +14,6 @@ #ifndef INSTRUCTIONS_H #define INSTRUCTIONS_H -enum mode_e -{ - m_manual, - m_auto -}; - // Clase Instructions class Instructions { @@ -44,7 +38,6 @@ private: 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 - mode_e mode; // Modo en el que se van a ejecutar las instrucciones // Actualiza las variables void update(); @@ -66,7 +59,7 @@ public: ~Instructions(); // Bucle principal - void run(mode_e mode); + void run(); }; #endif diff --git a/source/load_param.cpp b/source/load_param.cpp index b43456d..2b9367d 100644 --- a/source/load_param.cpp +++ b/source/load_param.cpp @@ -180,6 +180,11 @@ bool setOptions(param_t *param, std::string var, std::string value) param->pressStart = std::stoi(value); } + else if (var == "titleCounter") + { + param->titleCounter = std::stoi(value); + } + else { success = false; diff --git a/source/title.cpp b/source/title.cpp index f55ecb5..2df076e 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -68,7 +68,7 @@ void Title::init() { // Inicializa variables section->subsection = SUBSECTION_TITLE_1; - counter = TITLE_COUNTER; + counter = 0; nextSection.name = SECTION_PROG_GAME; postFade = 0; ticks = 0; @@ -134,9 +134,9 @@ void Title::update() // Sección 2 - La pantalla con el titulo, el fondo animado y la música else if (section->subsection == SUBSECTION_TITLE_2) { - if (counter > 0) + if (counter < param->titleCounter) { - counter--; + counter++; // Reproduce la música if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) @@ -163,33 +163,8 @@ void Title::update() JA_StopMusic(); break; - case 1: // 2 PLAYERS - section->name = SECTION_PROG_GAME; - section->subsection = SUBSECTION_GAME_PLAY_2P; - JA_StopMusic(); - break; - - case 2: // QUIT - section->name = SECTION_PROG_QUIT; - JA_StopMusic(); - break; - case 3: // TIME OUT - counter = TITLE_COUNTER; - if (demo) - { - runDemoGame(); - if (section->name != SECTION_PROG_QUIT) - { - runInstructions(m_auto); - } - if (section->name != SECTION_PROG_QUIT) - { - runHiScoreTable(mhst_auto); - } - } - else - section->name = SECTION_PROG_LOGO; + section->name = SECTION_PROG_GAME_DEMO; break; default: @@ -197,35 +172,9 @@ void Title::update() } } } - else if (counter == 0) + else if (counter >= param->titleCounter) { - if (demo) - { - if (section->name != SECTION_PROG_QUIT) - { - runHiScoreTable(mhst_auto); - } - runDemoGame(); - if (section->name != SECTION_PROG_QUIT) - { - runInstructions(m_auto); - } - init(); - demo = false; - counter = TITLE_COUNTER; - } - else - { - section->name = SECTION_PROG_LOGO; - } - } - - // Sección Instrucciones - if (section->subsection == SUBSECTION_TITLE_INSTRUCTIONS) - { - runInstructions(m_auto); - counter = TITLE_COUNTER; - demo = true; + section->name = SECTION_PROG_GAME_DEMO; } } } @@ -355,30 +304,6 @@ void Title::run() } } -// Ejecuta la parte donde se muestran las instrucciones -void Title::runInstructions(mode_e mode) -{ - instructions = new Instructions(renderer, screen, asset, input, lang, param, section); - instructions->run(mode); - delete instructions; -} - -// Ejecuta la parte donde se muestra la tabla de puntuaciones -void Title::runHiScoreTable(mode_hiScoreTable_e mode) -{ - hiScoreTable = new HiScoreTable(renderer, screen, asset, input, lang, param, options, section); - hiScoreTable->run(mode); - delete hiScoreTable; -} - -// Ejecuta el juego en modo demo -void Title::runDemoGame() -{ - demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, param, options, section); - demoGame->run(); - delete demoGame; -} - // Modifica las opciones para los controles de los jugadores bool Title::updatePlayerInputs(int numPlayer) { diff --git a/source/title.h b/source/title.h index eeaa264..03dcf42 100644 --- a/source/title.h +++ b/source/title.h @@ -28,12 +28,7 @@ // Textos #define TEXT_COPYRIGHT "@2020,2024 JailDesigner" -// Contadores -#define TITLE_COUNTER 800 - -// Cantidad de eventos de la pantalla de titulo -#define TITLE_TOTAL_EVENTS 2 - +// Clase Title class Title { private: @@ -91,15 +86,6 @@ private: // Cambia el valor de la variable de modo de pantalla completa void switchFullScreenModeVar(); - // Ejecuta la parte donde se muestran las instrucciones - void runInstructions(mode_e mode); - - // Ejecuta la parte donde se muestra la tabla de puntuaciones - void runHiScoreTable(mode_hiScoreTable_e mode); - - // Ejecuta el juego en modo demo - void runDemoGame(); - // Modifica las opciones para los controles de los jugadores bool updatePlayerInputs(int numPlayer);