globalInputs implementat en totes les seccions excepte Title i Game

This commit is contained in:
2025-02-23 08:57:01 +01:00
parent 2ac425483b
commit 8ae686a70b
14 changed files with 121 additions and 305 deletions

View File

@@ -44,24 +44,6 @@ constexpr int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2;
constexpr int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4; constexpr int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
constexpr int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3; 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 // Colores
const color_t borderColor = {0x27, 0x27, 0x36}; const color_t borderColor = {0x27, 0x27, 0x36};
const color_t black = {0xFF, 0xFF, 0xFF}; const color_t black = {0xFF, 0xFF, 0xFF};

View File

@@ -14,6 +14,7 @@
#include "text.h" // Para Text, TXT_CENTER, TXT_COLOR #include "text.h" // Para Text, TXT_CENTER, TXT_COLOR
#include "asset.h" #include "asset.h"
#include "options.h" #include "options.h"
#include "global_inputs.h"
class Asset; class Asset;
// Constructor // Constructor
@@ -89,42 +90,7 @@ void Credits::checkEvents()
// Comprueba las entradas // Comprueba las entradas
void Credits::checkInput() void Credits::checkInput()
{ {
globalInputs::check();
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;
}
} }
// Inicializa los textos // Inicializa los textos

View File

@@ -13,6 +13,7 @@
#include "utils.h" // Para color_t, stringToColor, options_t, secti... #include "utils.h" // Para color_t, stringToColor, options_t, secti...
#include "options.h" #include "options.h"
#include "debug.h" #include "debug.h"
#include "global_inputs.h"
// Constructor // Constructor
Demo::Demo() Demo::Demo()
@@ -87,45 +88,7 @@ void Demo::checkEvents()
// Comprueba las entradas // Comprueba las entradas
void Demo::checkInput() void Demo::checkInput()
{ {
if (input->checkInput(input_exit, REPEAT_FALSE)) globalInputs::check();
{
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;
}
} }
// Bucle para el juego // Bucle para el juego

View File

@@ -17,6 +17,7 @@
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
#include "utils.h" // Para color_t, stringToColor, options_t #include "utils.h" // Para color_t, stringToColor, options_t
#include "options.h" #include "options.h"
#include "global_inputs.h"
// Constructor // Constructor
Ending::Ending() Ending::Ending()
@@ -172,37 +173,7 @@ void Ending::checkEvents()
// Comprueba las entradas // Comprueba las entradas
void Ending::checkInput() void Ending::checkInput()
{ {
globalInputs::check();
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();
}
} }
// Inicializa los textos // Inicializa los textos

View File

@@ -14,6 +14,7 @@
#include "texture.h" // for Texture #include "texture.h" // for Texture
#include "utils.h" // for color_t, stringToColor, options_t #include "utils.h" // for color_t, stringToColor, options_t
#include "options.h" #include "options.h"
#include "global_inputs.h"
// Constructor // Constructor
Ending2::Ending2() Ending2::Ending2()
@@ -202,37 +203,7 @@ void Ending2::checkEvents()
// Comprueba las entradas // Comprueba las entradas
void Ending2::checkInput() void Ending2::checkInput()
{ {
globalInputs::check();
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();
}
} }
// Bucle principal // Bucle principal

View File

@@ -22,6 +22,7 @@
#include "utils.h" // for options_t, cheat_t, stringToColor #include "utils.h" // for options_t, cheat_t, stringToColor
#include "options.h" #include "options.h"
#include "notifier.h" #include "notifier.h"
#include "global_inputs.h"
// Constructor // Constructor
Game::Game() Game::Game()
@@ -201,12 +202,7 @@ void Game::checkEvents()
// Comprueba el teclado // Comprueba el teclado
void Game::checkInput() void Game::checkInput()
{ {
if (input_->checkInput(input_exit, REPEAT_FALSE)) if (input_->checkInput(input_toggle_music, REPEAT_FALSE))
{
options.section.name = SECTION_TITLE;
}
else if (input_->checkInput(input_toggle_music, REPEAT_FALSE))
{ {
board_.music = !board_.music; board_.music = !board_.music;
board_.music ? JA_ResumeMusic() : JA_PauseMusic(); board_.music ? JA_ResumeMusic() : JA_PauseMusic();
@@ -217,39 +213,7 @@ void Game::checkInput()
switchPause(); switchPause();
} }
else if (input_->checkInput(input_toggle_border, REPEAT_FALSE)) globalInputs::check();
{
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();
}
} }
// Bucle para el juego // Bucle para el juego
@@ -506,7 +470,7 @@ void Game::killPlayer()
setBlackScreen(); setBlackScreen();
// Crea la nueva habitación y el nuevo jugador // 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 playerPNG = options.cheat.altSkin ? "player2.png" : "player.png";
const std::string playerANI = options.cheat.altSkin ? "player2.ani" : "player.ani"; const std::string playerANI = options.cheat.altSkin ? "player2.ani" : "player.ani";
const player_t player = {spawn_point_, playerPNG, playerANI, room_}; const player_t player = {spawn_point_, playerPNG, playerANI, room_};

View File

@@ -12,6 +12,7 @@
#include "text.h" // Para Text, TXT_CENTER, TXT_COLOR #include "text.h" // Para Text, TXT_CENTER, TXT_COLOR
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
#include "options.h" #include "options.h"
#include "global_inputs.h"
// Constructor // Constructor
GameOver::GameOver() GameOver::GameOver()
@@ -139,36 +140,7 @@ void GameOver::checkEvents()
// Comprueba las entradas // Comprueba las entradas
void GameOver::checkInput() void GameOver::checkInput()
{ {
globalInputs::check();
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();
}
} }
// Bucle principal // Bucle principal

79
source/global_inputs.cpp Normal file
View File

@@ -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();
}
}
}

5
source/global_inputs.h Normal file
View File

@@ -0,0 +1,5 @@
namespace globalInputs
{
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
void check();
}

View File

@@ -11,6 +11,7 @@
#include "texture.h" // for Texture #include "texture.h" // for Texture
#include "utils.h" // for options_t, section_t, color_t, stringToC... #include "utils.h" // for options_t, section_t, color_t, stringToC...
#include "options.h" #include "options.h"
#include "global_inputs.h"
// Constructor // Constructor
LoadingScreen::LoadingScreen() LoadingScreen::LoadingScreen()
@@ -92,42 +93,7 @@ void LoadingScreen::checkEvents()
// Comprueba las entradas // Comprueba las entradas
void LoadingScreen::checkInput() void LoadingScreen::checkInput()
{ {
globalInputs::check();
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;
}
} }
// Gestiona el contador de carga // Gestiona el contador de carga

View File

@@ -11,6 +11,7 @@
#include "utils.h" // for color_t, section_t, options_t, stringToC... #include "utils.h" // for color_t, section_t, options_t, stringToC...
#include "asset.h" #include "asset.h"
#include "options.h" #include "options.h"
#include "global_inputs.h"
class Asset; // lines 11-11 class Asset; // lines 11-11
// Constructor // Constructor
@@ -87,41 +88,7 @@ void Logo::checkEvents()
// Comprueba las entradas // Comprueba las entradas
void Logo::checkInput() void Logo::checkInput()
{ {
if (input_->checkInput(input_exit, REPEAT_FALSE)) globalInputs::check();
{
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();
}
} }
// Gestiona el logo de JAILGAME // 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 // Termina la sección
void Logo::endSection() void Logo::endSection()
{ {

View File

@@ -55,9 +55,6 @@ private:
// Gestiona el color de las texturas // Gestiona el color de las texturas
void updateTextureColors(); void updateTextureColors();
// Cambia la paleta
void switchPalette();
// Termina la sección // Termina la sección
void endSection(); void endSection();

View File

@@ -5,6 +5,24 @@
#include <string> // Para string, basic_string #include <string> // Para string, basic_string
#include "utils.h" #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 // Posiciones de las notificaciones
enum not_pos_e enum not_pos_e
{ {

View File

@@ -16,6 +16,7 @@
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
#include "utils.h" // Para color_t, stringToColor, options_t #include "utils.h" // Para color_t, stringToColor, options_t
#include "options.h" #include "options.h"
#include "global_inputs.h"
// Constructor // Constructor
Title::Title() Title::Title()