Modificat checkInput en varies seccions per a gastar global_inputs.cpp

This commit is contained in:
2025-03-11 09:27:34 +01:00
parent 482dc3de54
commit be857cc8c8
11 changed files with 71 additions and 92 deletions

View File

@@ -9,6 +9,7 @@
#include <stdexcept> // Para runtime_error #include <stdexcept> // Para runtime_error
#include <string> // Para basic_string, string #include <string> // Para basic_string, string
#include <vector> // Para vector #include <vector> // Para vector
#include <array> // Para vector
#include "balloon_manager.h" // Para BalloonManager #include "balloon_manager.h" // Para BalloonManager
#include "fade.h" // Para Fade, FadeType, FadeMode #include "fade.h" // Para Fade, FadeType, FadeMode
#include "global_inputs.h" // Para check, update #include "global_inputs.h" // Para check, update
@@ -166,7 +167,7 @@ void Credits::fillTextTexture()
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
SDL_RenderClear(Screen::get()->getRenderer()); SDL_RenderClear(Screen::get()->getRenderer());
std::vector<std::string> texts = { const std::array<std::string, 10> TEXTS = {
lang::getText(121), lang::getText(121),
lang::getText(122), lang::getText(122),
lang::getText(123), lang::getText(123),
@@ -178,50 +179,50 @@ void Credits::fillTextTexture()
"WWW.KENNEY.NL", "WWW.KENNEY.NL",
"JAILDOCTOR"}; "JAILDOCTOR"};
const int space_post_title = 3 + text->getCharacterSize(); const int SPACE_POST_TITLE = 3 + text->getCharacterSize();
const int space_pre_title = text->getCharacterSize() * 4; const int SPACE_PRE_TITLE = text->getCharacterSize() * 4;
const int texts_height = 1 * text->getCharacterSize() + 7 * space_post_title + 3 * space_pre_title; 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; 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; y = 0;
text->setPalette(1); 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); text->setPalette(0);
y += space_post_title; 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); 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->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); text->setPalette(0);
y += space_post_title; 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); 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->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); text->setPalette(0);
y += space_post_title; 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); 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; 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); 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->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); text->setPalette(0);
y += space_post_title; 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); 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; 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); 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; 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); 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 // Mini logo
y += space_pre_title; y += SPACE_PRE_TITLE;
mini_logo_rect_src_.y = y; mini_logo_rect_src_.y = y;
auto mini_logo_sprite = std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png")); auto mini_logo_sprite = std::make_unique<Sprite>(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); mini_logo_sprite->setPosition(1 + param.game.game_area.center_x - mini_logo_sprite->getWidth() / 2, 1 + y);

View File

@@ -55,6 +55,7 @@ Director::Director(int argc, const char *argv[])
section::name = section::Name::LOGO; section::name = section::Name::LOGO;
#else // NORMAL GAME #else // NORMAL GAME
section::name = section::Name::LOGO; section::name = section::Name::LOGO;
section::options = section::Options::NONE;
section::attract_mode = section::AttractMode::TITLE_TO_DEMO; section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
#endif #endif
@@ -97,11 +98,11 @@ void Director::init()
// Inicializa y crea el resto de objetos // Inicializa y crea el resto de objetos
initSDL(); initSDL();
SDL_ShowCursor(SDL_DISABLE);
initJailAudio(); initJailAudio();
dbg_init(renderer_); dbg_init(renderer_);
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language))); lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
Screen::init(window_, renderer_); Screen::init(window_, renderer_);
SDL_ShowCursor(SDL_DISABLE);
Resource::init(); Resource::init();
Input::init(Asset::get()->get("gamecontrollerdb.txt")); Input::init(Asset::get()->get("gamecontrollerdb.txt"));
bindInputs(); bindInputs();

View File

@@ -1357,12 +1357,14 @@ void Game::checkPauseInput()
{ {
// Comprueba los mandos // Comprueba los mandos
for (int i = 0; i < input_->getNumControllers(); ++i) for (int i = 0; i < input_->getNumControllers(); ++i)
{
if (input_->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) && if (input_->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
{ {
pause(!paused_); pause(!paused_);
return; return;
} }
}
// Comprueba el teclado // Comprueba el teclado
if (input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) if (input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
@@ -1379,7 +1381,8 @@ void Game::handleDemoMode()
for (const auto &player : players_) for (const auto &player : players_)
{ {
if (player->isPlaying()) 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); handleDemoPlayerInput(player, index);
} }

View File

@@ -132,6 +132,28 @@ namespace globalInputs
Notifier::get()->show({"Autofire " + boolToOnOff(options.game.autofire)}); 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 // Comprueba los inputs que se pueden introducir en cualquier sección del juego
void check() void check()
{ {
@@ -172,6 +194,13 @@ namespace globalInputs
return; return;
} }
// Saltar sección
if (Input::get()->checkAnyButtonPressed())
{
skip_section();
return;
}
// Reset // Reset
if (Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) if (Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
{ {

View File

@@ -165,17 +165,6 @@ void HiScoreTable::checkEvents()
// Comprueba las entradas // Comprueba las entradas
void HiScoreTable::checkInput() 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(); globalInputs::check();
} }

View File

@@ -306,17 +306,6 @@ void Instructions::checkEvents()
// Comprueba las entradas // Comprueba las entradas
void Instructions::checkInput() 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(); globalInputs::check();
} }

View File

@@ -163,16 +163,6 @@ void Intro::checkEvents()
// Comprueba las entradas // Comprueba las entradas
void Intro::checkInput() 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(); globalInputs::check();
} }

View File

@@ -24,22 +24,21 @@ Logo::Logo()
{ {
// Inicializa variables // Inicializa variables
counter_ = 0;
section::name = section::Name::LOGO; section::name = section::Name::LOGO;
dest_.x = param.game.game_area.center_x - jail_texture_->getWidth() / 2; dest_.x = param.game.game_area.center_x - jail_texture_->getWidth() / 2;
dest_.y = param.game.game_area.center_y - jail_texture_->getHeight() / 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_->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_->setY(dest_.y + jail_texture_->getHeight() + 5);
since_sprite_->setSpriteClip(0, 0, since_texture_->getWidth(), since_texture_->getHeight()); 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 // Crea los sprites de cada linea
for (int i = 0; i < jail_texture_->getHeight(); ++i) for (int i = 0; i < jail_texture_->getHeight(); ++i)
{ {
auto temp = std::make_unique<Sprite>(jail_texture_, 0, i, jail_texture_->getWidth(), 1); auto temp = std::make_unique<Sprite>(jail_texture_, 0, i, jail_texture_->getWidth(), 1);
temp->setSpriteClip(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); const int POS_X = (i % 2 == 0) ? param.game.width + (i * 3) : -jail_texture_->getWidth() - (i * 3);
temp->setX(posX); temp->setX(POS_X);
temp->setY(dest_.y + i); temp->setY(dest_.y + i);
jail_sprite_.push_back(std::move(temp)); jail_sprite_.push_back(std::move(temp));
} }
@@ -76,15 +75,6 @@ void Logo::checkEvents()
// Comprueba las entradas // Comprueba las entradas
void Logo::checkInput() 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(); globalInputs::check();
} }

View File

@@ -57,7 +57,7 @@ private:
// Variables // Variables
std::vector<Color> color_; // Vector con los colores para el fade std::vector<Color> 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 Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
SDL_Point dest_; // Posición X donde dibujar el logo SDL_Point dest_; // Posición X donde dibujar el logo
LogoState state_ = LogoState::JAILGAMES; // El estado indica qué logo se está procesando LogoState state_ = LogoState::JAILGAMES; // El estado indica qué logo se está procesando

View File

@@ -118,12 +118,6 @@ void Screen::renderScreen()
// Establece el modo de video // Establece el modo de video
void Screen::setVideoMode(ScreenVideoMode videoMode) void Screen::setVideoMode(ScreenVideoMode videoMode)
{ {
#ifdef ARCADE
options.video.mode = ScreenVideoMode::WINDOW;
#else
options.video.mode = videoMode;
#endif
switch (options.video.mode) switch (options.video.mode)
{ {
case ScreenVideoMode::WINDOW: case ScreenVideoMode::WINDOW:
@@ -131,13 +125,6 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
// Cambia a modo de ventana // Cambia a modo de ventana
SDL_SetWindowFullscreen(window_, 0); 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 // Modifica el tamaño de la ventana
SDL_Point pos = getNewPosition(); SDL_Point pos = getNewPosition();
SDL_SetWindowSize(window_, param.game.width * options.video.window.size, param.game.height * options.video.window.size); SDL_SetWindowSize(window_, param.game.width * options.video.window.size, param.game.height * options.video.window.size);

View File

@@ -46,9 +46,9 @@ Title::Title()
// Asigna valores a otras variables // Asigna valores a otras variables
section::options = section::Options::TITLE_1; section::options = section::Options::TITLE_1;
const bool is_title_to_demo = (section::attract_mode == 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; 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; section::attract_mode = IS_TITLE_TO_DEMO ? section::AttractMode::TITLE_TO_LOGO : section::AttractMode::TITLE_TO_DEMO;
} }
// Destructor // Destructor