From be857cc8c8452339cb9b70bbd3f404ad97645735 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 11 Mar 2025 09:27:34 +0100 Subject: [PATCH] Modificat checkInput en varies seccions per a gastar global_inputs.cpp --- source/credits.cpp | 57 ++++++++++++++++++++-------------------- source/director.cpp | 3 ++- source/game.cpp | 5 +++- source/global_inputs.cpp | 29 ++++++++++++++++++++ source/hiscore_table.cpp | 11 -------- source/instructions.cpp | 11 -------- source/intro.cpp | 10 ------- source/logo.cpp | 16 +++-------- source/logo.h | 2 +- source/screen.cpp | 13 --------- source/title.cpp | 6 ++--- 11 files changed, 71 insertions(+), 92 deletions(-) diff --git a/source/credits.cpp b/source/credits.cpp index dd7c08d..34823ea 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -9,6 +9,7 @@ #include // Para runtime_error #include // Para basic_string, string #include // Para vector +#include // Para vector #include "balloon_manager.h" // Para BalloonManager #include "fade.h" // Para Fade, FadeType, FadeMode #include "global_inputs.h" // Para check, update @@ -166,7 +167,7 @@ void Credits::fillTextTexture() SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0); SDL_RenderClear(Screen::get()->getRenderer()); - std::vector texts = { + const std::array TEXTS = { lang::getText(121), lang::getText(122), lang::getText(123), @@ -178,50 +179,50 @@ void Credits::fillTextTexture() "WWW.KENNEY.NL", "JAILDOCTOR"}; - const int space_post_title = 3 + text->getCharacterSize(); - const int space_pre_title = text->getCharacterSize() * 4; - const int texts_height = 1 * text->getCharacterSize() + 7 * space_post_title + 3 * space_pre_title; - credits_rect_dst_.h = credits_rect_src_.h = texts_height; + const int SPACE_POST_TITLE = 3 + text->getCharacterSize(); + const int SPACE_PRE_TITLE = text->getCharacterSize() * 4; + const int TEXTS_HEIGHT = 1 * text->getCharacterSize() + 7 * SPACE_POST_TITLE + 3 * SPACE_PRE_TITLE; + credits_rect_dst_.h = credits_rect_src_.h = TEXTS_HEIGHT; - int y = (param.game.height - texts_height) / 2; + int y = (param.game.height - TEXTS_HEIGHT) / 2; y = 0; text->setPalette(1); - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(0), 1, no_color, 1, shdw_txt_color); + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(0), 1, no_color, 1, shdw_txt_color); text->setPalette(0); - y += space_post_title; - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(4), 1, no_color, 1, shdw_txt_color); + y += SPACE_POST_TITLE; + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(4), 1, no_color, 1, shdw_txt_color); - y += space_pre_title; + y += SPACE_PRE_TITLE; text->setPalette(1); - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(1), 1, no_color, 1, shdw_txt_color); + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(1), 1, no_color, 1, shdw_txt_color); text->setPalette(0); - y += space_post_title; - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(4), 1, no_color, 1, shdw_txt_color); + y += SPACE_POST_TITLE; + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(4), 1, no_color, 1, shdw_txt_color); - y += space_pre_title; + y += SPACE_PRE_TITLE; text->setPalette(1); - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(2), 1, no_color, 1, shdw_txt_color); + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(2), 1, no_color, 1, shdw_txt_color); text->setPalette(0); - y += space_post_title; - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(5), 1, no_color, 1, shdw_txt_color); - y += space_post_title; - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(6), 1, no_color, 1, shdw_txt_color); + y += SPACE_POST_TITLE; + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(5), 1, no_color, 1, shdw_txt_color); + y += SPACE_POST_TITLE; + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(6), 1, no_color, 1, shdw_txt_color); - y += space_pre_title; + y += SPACE_PRE_TITLE; text->setPalette(1); - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(3), 1, no_color, 1, shdw_txt_color); + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(3), 1, no_color, 1, shdw_txt_color); text->setPalette(0); - y += space_post_title; - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(7), 1, no_color, 1, shdw_txt_color); - y += space_post_title; - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(8), 1, no_color, 1, shdw_txt_color); - y += space_post_title; - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(9), 1, no_color, 1, shdw_txt_color); + y += SPACE_POST_TITLE; + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(7), 1, no_color, 1, shdw_txt_color); + y += SPACE_POST_TITLE; + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(8), 1, no_color, 1, shdw_txt_color); + y += SPACE_POST_TITLE; + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXTS.at(9), 1, no_color, 1, shdw_txt_color); // Mini logo - y += space_pre_title; + y += SPACE_PRE_TITLE; mini_logo_rect_src_.y = y; auto mini_logo_sprite = std::make_unique(Resource::get()->getTexture("logo_jailgames_mini.png")); mini_logo_sprite->setPosition(1 + param.game.game_area.center_x - mini_logo_sprite->getWidth() / 2, 1 + y); diff --git a/source/director.cpp b/source/director.cpp index 7cd2cf2..bc25de3 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -55,6 +55,7 @@ Director::Director(int argc, const char *argv[]) section::name = section::Name::LOGO; #else // NORMAL GAME section::name = section::Name::LOGO; + section::options = section::Options::NONE; section::attract_mode = section::AttractMode::TITLE_TO_DEMO; #endif @@ -97,11 +98,11 @@ void Director::init() // Inicializa y crea el resto de objetos initSDL(); + SDL_ShowCursor(SDL_DISABLE); initJailAudio(); dbg_init(renderer_); lang::loadFromFile(getLangFile(static_cast(options.game.language))); Screen::init(window_, renderer_); - SDL_ShowCursor(SDL_DISABLE); Resource::init(); Input::init(Asset::get()->get("gamecontrollerdb.txt")); bindInputs(); diff --git a/source/game.cpp b/source/game.cpp index a081df0..4f95a1b 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1357,12 +1357,14 @@ void Game::checkPauseInput() { // Comprueba los mandos for (int i = 0; i < input_->getNumControllers(); ++i) + { if (input_->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) && input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) { pause(!paused_); return; } + } // Comprueba el teclado if (input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) @@ -1379,7 +1381,8 @@ void Game::handleDemoMode() for (const auto &player : players_) { if (player->isPlaying()) - { // Maneja el input específico del jugador en modo demo. + { + // Maneja el input específico del jugador en modo demo. handleDemoPlayerInput(player, index); } diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index c5bf4e9..d1752c9 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -132,6 +132,28 @@ namespace globalInputs Notifier::get()->show({"Autofire " + boolToOnOff(options.game.autofire)}); } + // Salta una sección del juego + void skip_section() + { + switch (section::name) + { + case section::Name::INTRO: + JA_StopMusic(); + // Continua en el case de abajo + case section::Name::LOGO: + case section::Name::HI_SCORE_TABLE: + case section::Name::INSTRUCTIONS: + { + section::name = section::Name::TITLE; + section::options = section::Options::TITLE_1; + section::attract_mode = section::AttractMode::TITLE_TO_DEMO; + break; + } + default: + break; + } + } + // Comprueba los inputs que se pueden introducir en cualquier sección del juego void check() { @@ -172,6 +194,13 @@ namespace globalInputs return; } + // Saltar sección + if (Input::get()->checkAnyButtonPressed()) + { + skip_section(); + return; + } + // Reset if (Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index 5c7aba4..c7c644f 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -165,17 +165,6 @@ void HiScoreTable::checkEvents() // Comprueba las entradas void HiScoreTable::checkInput() { - // Comprueba si se ha pulsado cualquier botón (de los usados para jugar) - if (Input::get()->checkAnyButtonPressed()) - { - // JA_StopMusic(); - section::name = section::Name::TITLE; - section::options = section::Options::TITLE_1; - section::attract_mode = section::AttractMode::TITLE_TO_DEMO; - return; - } - - // Comprueba los inputs que se pueden introducir en cualquier sección del juego globalInputs::check(); } diff --git a/source/instructions.cpp b/source/instructions.cpp index 4e712de..b8a1001 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -306,17 +306,6 @@ void Instructions::checkEvents() // Comprueba las entradas void Instructions::checkInput() { - // Comprueba si se ha pulsado cualquier botón (de los usados para jugar) - if (Input::get()->checkAnyButtonPressed()) - { - // JA_StopMusic(); - section::name = section::Name::TITLE; - section::options = section::Options::TITLE_1; - section::attract_mode = section::AttractMode::TITLE_TO_DEMO; - return; - } - - // Comprueba los inputs que se pueden introducir en cualquier sección del juego globalInputs::check(); } diff --git a/source/intro.cpp b/source/intro.cpp index 43269f5..673a009 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -163,16 +163,6 @@ void Intro::checkEvents() // Comprueba las entradas void Intro::checkInput() { - // Comprueba si se ha pulsado cualquier botón (de los usados para jugar) - if (Input::get()->checkAnyButtonPressed()) - { - JA_StopMusic(); - section::name = section::Name::TITLE; - section::options = section::Options::TITLE_1; - return; - } - - // Comprueba los inputs que se pueden introducir en cualquier sección del juego globalInputs::check(); } diff --git a/source/logo.cpp b/source/logo.cpp index 7b90b95..40eeba3 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -24,22 +24,21 @@ Logo::Logo() { // Inicializa variables - counter_ = 0; section::name = section::Name::LOGO; dest_.x = param.game.game_area.center_x - jail_texture_->getWidth() / 2; dest_.y = param.game.game_area.center_y - jail_texture_->getHeight() / 2; since_sprite_->setPosition({(param.game.width - since_texture_->getWidth()) / 2, 83 + jail_texture_->getHeight() + 5, since_texture_->getWidth(), since_texture_->getHeight()}); since_sprite_->setY(dest_.y + jail_texture_->getHeight() + 5); since_sprite_->setSpriteClip(0, 0, since_texture_->getWidth(), since_texture_->getHeight()); - since_texture_->setColor(0x00, 0x00, 0x00); // Esto en linux no hace nada ?? + since_texture_->setColor(0x00, 0x00, 0x00); // Crea los sprites de cada linea for (int i = 0; i < jail_texture_->getHeight(); ++i) { auto temp = std::make_unique(jail_texture_, 0, i, jail_texture_->getWidth(), 1); temp->setSpriteClip(0, i, jail_texture_->getWidth(), 1); - const int posX = (i % 2 == 0) ? param.game.width + (i * 3) : -jail_texture_->getWidth() - (i * 3); - temp->setX(posX); + const int POS_X = (i % 2 == 0) ? param.game.width + (i * 3) : -jail_texture_->getWidth() - (i * 3); + temp->setX(POS_X); temp->setY(dest_.y + i); jail_sprite_.push_back(std::move(temp)); } @@ -76,15 +75,6 @@ void Logo::checkEvents() // Comprueba las entradas void Logo::checkInput() { - // Comprueba si se ha pulsado cualquier botón (de los usados para jugar) - if (Input::get()->checkAnyButtonPressed()) - { - section::name = section::Name::TITLE; - section::options = section::Options::TITLE_1; - return; - } - - // Comprueba los inputs que se pueden introducir en cualquier sección del juego globalInputs::check(); } diff --git a/source/logo.h b/source/logo.h index fa3165c..729eb8b 100644 --- a/source/logo.h +++ b/source/logo.h @@ -57,7 +57,7 @@ private: // Variables std::vector color_; // Vector con los colores para el fade - int counter_; // Contador + int counter_ = 0; // Contador Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa SDL_Point dest_; // Posición X donde dibujar el logo LogoState state_ = LogoState::JAILGAMES; // El estado indica qué logo se está procesando diff --git a/source/screen.cpp b/source/screen.cpp index 90f6e5c..02861b0 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -118,12 +118,6 @@ void Screen::renderScreen() // Establece el modo de video void Screen::setVideoMode(ScreenVideoMode videoMode) { -#ifdef ARCADE - options.video.mode = ScreenVideoMode::WINDOW; -#else - options.video.mode = videoMode; -#endif - switch (options.video.mode) { case ScreenVideoMode::WINDOW: @@ -131,13 +125,6 @@ void Screen::setVideoMode(ScreenVideoMode videoMode) // Cambia a modo de ventana SDL_SetWindowFullscreen(window_, 0); -#ifdef ARCADE - // Oculta el puntero - SDL_ShowCursor(SDL_DISABLE); -#else - // Muestra el puntero - SDL_ShowCursor(SDL_ENABLE); -#endif // Modifica el tamaño de la ventana SDL_Point pos = getNewPosition(); SDL_SetWindowSize(window_, param.game.width * options.video.window.size, param.game.height * options.video.window.size); diff --git a/source/title.cpp b/source/title.cpp index f77be07..a09d8a6 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -46,9 +46,9 @@ Title::Title() // Asigna valores a otras variables section::options = section::Options::TITLE_1; - const bool is_title_to_demo = (section::attract_mode == section::AttractMode::TITLE_TO_DEMO); - next_section_ = is_title_to_demo ? section::Name::GAME_DEMO : section::Name::LOGO; - section::attract_mode = is_title_to_demo ? section::AttractMode::TITLE_TO_LOGO : section::AttractMode::TITLE_TO_DEMO; + const bool IS_TITLE_TO_DEMO = (section::attract_mode == section::AttractMode::TITLE_TO_DEMO); + next_section_ = IS_TITLE_TO_DEMO ? section::Name::GAME_DEMO : section::Name::LOGO; + section::attract_mode = IS_TITLE_TO_DEMO ? section::AttractMode::TITLE_TO_LOGO : section::AttractMode::TITLE_TO_DEMO; } // Destructor