diff --git a/source/const.h b/source/const.h index 0f4e1c1..f95e0e4 100644 --- a/source/const.h +++ b/source/const.h @@ -44,24 +44,6 @@ constexpr int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2; constexpr int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4; constexpr int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3; -// Secciones del programa -constexpr int SECTION_LOGO = 0; -constexpr int SECTION_LOADING_SCREEN = 1; -constexpr int SECTION_TITLE = 2; -constexpr int SECTION_CREDITS = 3; -constexpr int SECTION_GAME = 4; -constexpr int SECTION_DEMO = 5; -constexpr int SECTION_GAME_OVER = 6; -constexpr int SECTION_ENDING = 7; -constexpr int SECTION_ENDING2 = 8; -constexpr int SECTION_QUIT = 9; - -// Subsecciones -constexpr int SUBSECTION_LOGO_TO_INTRO = 0; -constexpr int SUBSECTION_LOGO_TO_TITLE = 1; -constexpr int SUBSECTION_TITLE_WITH_LOADING_SCREEN = 2; -constexpr int SUBSECTION_TITLE_WITHOUT_LOADING_SCREEN = 3; - // Colores const color_t borderColor = {0x27, 0x27, 0x36}; const color_t black = {0xFF, 0xFF, 0xFF}; diff --git a/source/credits.cpp b/source/credits.cpp index 5757047..502cea0 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -14,6 +14,7 @@ #include "text.h" // Para Text, TXT_CENTER, TXT_COLOR #include "asset.h" #include "options.h" +#include "global_inputs.h" class Asset; // Constructor @@ -89,42 +90,7 @@ void Credits::checkEvents() // Comprueba las entradas void Credits::checkInput() { - - if (input_->checkInput(input_exit, REPEAT_FALSE)) - { - options.section.name = SECTION_QUIT; - } - - else if (input_->checkInput(input_toggle_border, REPEAT_FALSE)) - { - screen_->toggleBorder(); - } - - else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE)) - { - screen_->toggleVideoMode(); - } - - else if (input_->checkInput(input_window_dec_size, REPEAT_FALSE)) - { - screen_->decWindowSize(); - } - - else if (input_->checkInput(input_window_inc_size, REPEAT_FALSE)) - { - screen_->incWindowSize(); - } - - else if (input_->checkInput(input_toggle_palette, REPEAT_FALSE)) - { - switchPalette(); - } - - else if (input_->checkInput(input_pause, REPEAT_FALSE) || input_->checkInput(input_accept, REPEAT_FALSE) || input_->checkInput(input_jump, REPEAT_FALSE)) - { - options.section.name = SECTION_TITLE; - options.section.subsection = 0; - } + globalInputs::check(); } // Inicializa los textos diff --git a/source/demo.cpp b/source/demo.cpp index 4622574..e883461 100644 --- a/source/demo.cpp +++ b/source/demo.cpp @@ -13,6 +13,7 @@ #include "utils.h" // Para color_t, stringToColor, options_t, secti... #include "options.h" #include "debug.h" +#include "global_inputs.h" // Constructor Demo::Demo() @@ -87,45 +88,7 @@ void Demo::checkEvents() // Comprueba las entradas void Demo::checkInput() { - if (input->checkInput(input_exit, REPEAT_FALSE)) - { - options.section.name = SECTION_QUIT; - } - - else if (input->checkInput(input_toggle_border, REPEAT_FALSE)) - { - screen->toggleBorder(); - reLoadTextures(); - } - - else if (input->checkInput(input_toggle_videomode, REPEAT_FALSE)) - { - screen->toggleVideoMode(); - reLoadTextures(); - } - - else if (input->checkInput(input_window_dec_size, REPEAT_FALSE)) - { - screen->decWindowSize(); - reLoadTextures(); - } - - else if (input->checkInput(input_window_inc_size, REPEAT_FALSE)) - { - screen->incWindowSize(); - reLoadTextures(); - } - - else if (input->checkInput(input_toggle_palette, REPEAT_FALSE)) - { - switchPalette(); - } - - else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_jump, REPEAT_FALSE)) - { - options.section.name = SECTION_TITLE; - options.section.subsection = 0; - } + globalInputs::check(); } // Bucle para el juego diff --git a/source/ending.cpp b/source/ending.cpp index dd6b34b..d54fe84 100644 --- a/source/ending.cpp +++ b/source/ending.cpp @@ -17,6 +17,7 @@ #include "texture.h" // Para Texture #include "utils.h" // Para color_t, stringToColor, options_t #include "options.h" +#include "global_inputs.h" // Constructor Ending::Ending() @@ -172,37 +173,7 @@ void Ending::checkEvents() // Comprueba las entradas void Ending::checkInput() { - - if (input->checkInput(input_exit, REPEAT_FALSE)) - { - options.section.name = SECTION_LOGO; - options.section.subsection = SUBSECTION_LOGO_TO_INTRO; - } - - else if (input->checkInput(input_toggle_border, REPEAT_FALSE)) - { - screen->toggleBorder(); - } - - else if (input->checkInput(input_toggle_videomode, REPEAT_FALSE)) - { - screen->toggleVideoMode(); - } - - else if (input->checkInput(input_window_dec_size, REPEAT_FALSE)) - { - screen->decWindowSize(); - } - - else if (input->checkInput(input_window_inc_size, REPEAT_FALSE)) - { - screen->incWindowSize(); - } - - else if (input->checkInput(input_toggle_palette, REPEAT_FALSE)) - { - switchPalette(); - } + globalInputs::check(); } // Inicializa los textos diff --git a/source/ending2.cpp b/source/ending2.cpp index b773e09..97e5a21 100644 --- a/source/ending2.cpp +++ b/source/ending2.cpp @@ -14,6 +14,7 @@ #include "texture.h" // for Texture #include "utils.h" // for color_t, stringToColor, options_t #include "options.h" +#include "global_inputs.h" // Constructor Ending2::Ending2() @@ -202,37 +203,7 @@ void Ending2::checkEvents() // Comprueba las entradas void Ending2::checkInput() { - - if (input->checkInput(input_exit, REPEAT_FALSE)) - { - options.section.name = SECTION_LOGO; - options.section.subsection = SUBSECTION_LOGO_TO_INTRO; - } - - else if (input->checkInput(input_toggle_border, REPEAT_FALSE)) - { - screen->toggleBorder(); - } - - else if (input->checkInput(input_toggle_videomode, REPEAT_FALSE)) - { - screen->toggleVideoMode(); - } - - else if (input->checkInput(input_window_dec_size, REPEAT_FALSE)) - { - screen->decWindowSize(); - } - - else if (input->checkInput(input_window_inc_size, REPEAT_FALSE)) - { - screen->incWindowSize(); - } - - else if (input->checkInput(input_toggle_palette, REPEAT_FALSE)) - { - switchPalette(); - } + globalInputs::check(); } // Bucle principal diff --git a/source/game.cpp b/source/game.cpp index 38a7ffb..31c7a6e 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -22,6 +22,7 @@ #include "utils.h" // for options_t, cheat_t, stringToColor #include "options.h" #include "notifier.h" +#include "global_inputs.h" // Constructor Game::Game() @@ -201,12 +202,7 @@ void Game::checkEvents() // Comprueba el teclado void Game::checkInput() { - if (input_->checkInput(input_exit, REPEAT_FALSE)) - { - options.section.name = SECTION_TITLE; - } - - else if (input_->checkInput(input_toggle_music, REPEAT_FALSE)) + if (input_->checkInput(input_toggle_music, REPEAT_FALSE)) { board_.music = !board_.music; board_.music ? JA_ResumeMusic() : JA_PauseMusic(); @@ -217,39 +213,7 @@ void Game::checkInput() switchPause(); } - else if (input_->checkInput(input_toggle_border, REPEAT_FALSE)) - { - screen_->toggleBorder(); - reLoadTextures(); - } - - else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE)) - { - screen_->toggleVideoMode(); - reLoadTextures(); - } - - else if (input_->checkInput(input_toggle_shaders, REPEAT_FALSE)) - { - screen_->toggleShaders(); - } - - else if (input_->checkInput(input_window_dec_size, REPEAT_FALSE)) - { - screen_->decWindowSize(); - reLoadTextures(); - } - - else if (input_->checkInput(input_window_inc_size, REPEAT_FALSE)) - { - screen_->incWindowSize(); - reLoadTextures(); - } - - else if (input_->checkInput(input_toggle_palette, REPEAT_FALSE)) - { - switchPalette(); - } + globalInputs::check(); } // Bucle para el juego @@ -506,7 +470,7 @@ void Game::killPlayer() setBlackScreen(); // Crea la nueva habitación y el nuevo jugador - room_ = new Room(resource_->getRoom(current_room_),item_tracker_, &board_.items, board_.jailEnabled); + room_ = new Room(resource_->getRoom(current_room_), item_tracker_, &board_.items, board_.jailEnabled); const std::string playerPNG = options.cheat.altSkin ? "player2.png" : "player.png"; const std::string playerANI = options.cheat.altSkin ? "player2.ani" : "player.ani"; const player_t player = {spawn_point_, playerPNG, playerANI, room_}; diff --git a/source/game_over.cpp b/source/game_over.cpp index d69b2ac..d93ffe4 100644 --- a/source/game_over.cpp +++ b/source/game_over.cpp @@ -12,6 +12,7 @@ #include "text.h" // Para Text, TXT_CENTER, TXT_COLOR #include "texture.h" // Para Texture #include "options.h" +#include "global_inputs.h" // Constructor GameOver::GameOver() @@ -139,36 +140,7 @@ void GameOver::checkEvents() // Comprueba las entradas void GameOver::checkInput() { - - if (input->checkInput(input_exit, REPEAT_FALSE)) - { - options.section.name = SECTION_QUIT; - } - - else if (input->checkInput(input_toggle_border, REPEAT_FALSE)) - { - screen->toggleBorder(); - } - - else if (input->checkInput(input_toggle_videomode, REPEAT_FALSE)) - { - screen->toggleVideoMode(); - } - - else if (input->checkInput(input_window_dec_size, REPEAT_FALSE)) - { - screen->decWindowSize(); - } - - else if (input->checkInput(input_window_inc_size, REPEAT_FALSE)) - { - screen->incWindowSize(); - } - - else if (input->checkInput(input_toggle_palette, REPEAT_FALSE)) - { - switchPalette(); - } + globalInputs::check(); } // Bucle principal diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp new file mode 100644 index 0000000..13a140b --- /dev/null +++ b/source/global_inputs.cpp @@ -0,0 +1,79 @@ +#include "global_inputs.h" +#include "input.h" // Para Input, InputDeviceToUse, InputType, INPU... +#include "notifier.h" // Para Notifier +#include "options.h" // Para Options, options, OptionsGame, OptionsAudio +#include "screen.h" // Para Screen, ScreenVideoMode + +namespace globalInputs +{ + // Cambia la paleta + void switchPalette() + { + options.palette = options.palette == p_zxspectrum ? p_zxarne : p_zxspectrum; + } + + // Cambia de seccion + void skip_section() + { + switch (options.section.name) + { + case SECTION_LOGO: + case SECTION_LOADING_SCREEN: + case SECTION_CREDITS: + case SECTION_DEMO: + case SECTION_GAME_OVER: + case SECTION_ENDING: + case SECTION_ENDING2: + options.section.name = SECTION_TITLE; + options.section.subsection = 0; + break; + + default: + break; + } + } + + // Comprueba los inputs que se pueden introducir en cualquier sección del juego + void check() + { + if (Input::get()->checkInput(input_exit, REPEAT_FALSE)) + { + options.section.name = SECTION_QUIT; + } + + else if (Input::get()->checkInput(input_accept, REPEAT_FALSE)) + { + skip_section(); + } + + else if (Input::get()->checkInput(input_toggle_border, REPEAT_FALSE)) + { + Screen::get()->toggleBorder(); + } + + else if (Input::get()->checkInput(input_toggle_videomode, REPEAT_FALSE)) + { + Screen::get()->toggleVideoMode(); + } + + else if (Input::get()->checkInput(input_window_dec_size, REPEAT_FALSE)) + { + Screen::get()->decWindowSize(); + } + + else if (Input::get()->checkInput(input_window_inc_size, REPEAT_FALSE)) + { + Screen::get()->incWindowSize(); + } + + else if (Input::get()->checkInput(input_toggle_shaders, REPEAT_FALSE)) + { + Screen::get()->toggleShaders(); + } + + else if (Input::get()->checkInput(input_toggle_palette, REPEAT_FALSE)) + { + switchPalette(); + } + } +} \ No newline at end of file diff --git a/source/global_inputs.h b/source/global_inputs.h new file mode 100644 index 0000000..5047ad9 --- /dev/null +++ b/source/global_inputs.h @@ -0,0 +1,5 @@ +namespace globalInputs +{ + // Comprueba los inputs que se pueden introducir en cualquier sección del juego + void check(); +} \ No newline at end of file diff --git a/source/loading_screen.cpp b/source/loading_screen.cpp index 1bcb17f..518fef0 100644 --- a/source/loading_screen.cpp +++ b/source/loading_screen.cpp @@ -11,6 +11,7 @@ #include "texture.h" // for Texture #include "utils.h" // for options_t, section_t, color_t, stringToC... #include "options.h" +#include "global_inputs.h" // Constructor LoadingScreen::LoadingScreen() @@ -92,42 +93,7 @@ void LoadingScreen::checkEvents() // Comprueba las entradas void LoadingScreen::checkInput() { - - if (input_->checkInput(input_exit, REPEAT_FALSE)) - { - options.section.name = SECTION_QUIT; - } - - else if (input_->checkInput(input_toggle_border, REPEAT_FALSE)) - { - screen_->toggleBorder(); - } - - else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE)) - { - screen_->toggleVideoMode(); - } - - else if (input_->checkInput(input_window_dec_size, REPEAT_FALSE)) - { - screen_->decWindowSize(); - } - - else if (input_->checkInput(input_window_inc_size, REPEAT_FALSE)) - { - screen_->incWindowSize(); - } - - else if (input_->checkInput(input_toggle_palette, REPEAT_FALSE)) - { - switchPalette(); - } - - else if (input_->checkInput(input_pause, REPEAT_FALSE) || input_->checkInput(input_accept, REPEAT_FALSE) || input_->checkInput(input_jump, REPEAT_FALSE)) - { - options.section.name = SECTION_TITLE; - options.section.subsection = 0; - } + globalInputs::check(); } // Gestiona el contador de carga diff --git a/source/logo.cpp b/source/logo.cpp index 7448151..7eacabc 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -11,6 +11,7 @@ #include "utils.h" // for color_t, section_t, options_t, stringToC... #include "asset.h" #include "options.h" +#include "global_inputs.h" class Asset; // lines 11-11 // Constructor @@ -87,41 +88,7 @@ void Logo::checkEvents() // Comprueba las entradas void Logo::checkInput() { - if (input_->checkInput(input_exit, REPEAT_FALSE)) - { - options.section.name = SECTION_TITLE; - } - - else if (input_->checkInput(input_toggle_border, REPEAT_FALSE)) - { - screen_->toggleBorder(); - } - - else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE)) - { - screen_->toggleVideoMode(); - } - - else if (input_->checkInput(input_window_dec_size, REPEAT_FALSE)) - { - screen_->decWindowSize(); - } - - else if (input_->checkInput(input_window_inc_size, REPEAT_FALSE)) - { - screen_->incWindowSize(); - } - - else if (input_->checkInput(input_toggle_palette, REPEAT_FALSE)) - { - switchPalette(); - } - - else if (input_->checkInput(input_pause, REPEAT_FALSE) || input_->checkInput(input_accept, REPEAT_FALSE) || input_->checkInput(input_jump, REPEAT_FALSE)) - { - options.section.subsection = SUBSECTION_LOGO_TO_TITLE; - endSection(); - } + globalInputs::check(); } // Gestiona el logo de JAILGAME @@ -310,12 +277,6 @@ void Logo::run() } } -// Cambia la paleta -void Logo::switchPalette() -{ - options.palette = options.palette == p_zxspectrum ? p_zxarne : p_zxspectrum; -} - // Termina la sección void Logo::endSection() { diff --git a/source/logo.h b/source/logo.h index 7c5b796..27b37ab 100644 --- a/source/logo.h +++ b/source/logo.h @@ -55,9 +55,6 @@ private: // Gestiona el color de las texturas void updateTextureColors(); - // Cambia la paleta - void switchPalette(); - // Termina la sección void endSection(); diff --git a/source/options.h b/source/options.h index 4e6e31a..e3de6ba 100644 --- a/source/options.h +++ b/source/options.h @@ -5,6 +5,24 @@ #include // Para string, basic_string #include "utils.h" +// Secciones del programa +constexpr int SECTION_LOGO = 0; +constexpr int SECTION_LOADING_SCREEN = 1; +constexpr int SECTION_TITLE = 2; +constexpr int SECTION_CREDITS = 3; +constexpr int SECTION_GAME = 4; +constexpr int SECTION_DEMO = 5; +constexpr int SECTION_GAME_OVER = 6; +constexpr int SECTION_ENDING = 7; +constexpr int SECTION_ENDING2 = 8; +constexpr int SECTION_QUIT = 9; + +// Subsecciones +constexpr int SUBSECTION_LOGO_TO_INTRO = 0; +constexpr int SUBSECTION_LOGO_TO_TITLE = 1; +constexpr int SUBSECTION_TITLE_WITH_LOADING_SCREEN = 2; +constexpr int SUBSECTION_TITLE_WITHOUT_LOADING_SCREEN = 3; + // Posiciones de las notificaciones enum not_pos_e { diff --git a/source/title.cpp b/source/title.cpp index 6cdd202..4b9c3d1 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -16,6 +16,7 @@ #include "texture.h" // Para Texture #include "utils.h" // Para color_t, stringToColor, options_t #include "options.h" +#include "global_inputs.h" // Constructor Title::Title()