Compare commits
10 Commits
cd68c5ffea
...
2024-11-03
| Author | SHA1 | Date | |
|---|---|---|---|
| e0e82ee273 | |||
| 371c477d0d | |||
| f29eb2f411 | |||
| 69a92cba66 | |||
| 86cd7b0f16 | |||
| a1ccb6102a | |||
| 2dd8bbbbf7 | |||
| c66cc965f1 | |||
| 0757f63b73 | |||
| 80a110e1d7 |
@@ -206,7 +206,7 @@ NORMAL
|
|||||||
DIFICIL
|
DIFICIL
|
||||||
|
|
||||||
## 69 - MENU DE OPCIONES
|
## 69 - MENU DE OPCIONES
|
||||||
TECLAT
|
Teclat
|
||||||
|
|
||||||
## 70 - MENU DE OPCIONES
|
## 70 - MENU DE OPCIONES
|
||||||
MANDO
|
MANDO
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ NORMAL
|
|||||||
HARD
|
HARD
|
||||||
|
|
||||||
## 69 - MENU DE OPCIONES
|
## 69 - MENU DE OPCIONES
|
||||||
KEYBOARD
|
Keyboard
|
||||||
|
|
||||||
## 70 - MENU DE OPCIONES
|
## 70 - MENU DE OPCIONES
|
||||||
GAME CONTROLLER
|
GAME CONTROLLER
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ NORMAL
|
|||||||
DIFICIL
|
DIFICIL
|
||||||
|
|
||||||
## 69 - MENU DE OPCIONES
|
## 69 - MENU DE OPCIONES
|
||||||
TECLADO
|
Teclado
|
||||||
|
|
||||||
## 70 - MENU DE OPCIONES
|
## 70 - MENU DE OPCIONES
|
||||||
MANDO
|
MANDO
|
||||||
|
|||||||
@@ -16,11 +16,7 @@ DefineButtons::DefineButtons(std::unique_ptr<Text> text_)
|
|||||||
x_ = param.game.width / 2;
|
x_ = param.game.width / 2;
|
||||||
y_ = param.title.press_start_position;
|
y_ = param.title.press_start_position;
|
||||||
|
|
||||||
buttons_.emplace_back(lang::getText(95), InputType::FIRE_LEFT, SDL_CONTROLLER_BUTTON_INVALID);
|
clearButtons();
|
||||||
buttons_.emplace_back(lang::getText(96), InputType::FIRE_CENTER, SDL_CONTROLLER_BUTTON_INVALID);
|
|
||||||
buttons_.emplace_back(lang::getText(97), InputType::FIRE_RIGHT, SDL_CONTROLLER_BUTTON_INVALID);
|
|
||||||
buttons_.emplace_back(lang::getText(98), InputType::START, SDL_CONTROLLER_BUTTON_INVALID);
|
|
||||||
buttons_.emplace_back(lang::getText(99), InputType::EXIT, SDL_CONTROLLER_BUTTON_INVALID);
|
|
||||||
|
|
||||||
for (int i = 0; i < input_->getNumControllers(); ++i)
|
for (int i = 0; i < input_->getNumControllers(); ++i)
|
||||||
{
|
{
|
||||||
@@ -33,19 +29,17 @@ void DefineButtons::render()
|
|||||||
{
|
{
|
||||||
if (enabled_)
|
if (enabled_)
|
||||||
{
|
{
|
||||||
text_->writeCentered(x_, y_ - 10, lang::getText(100) + std::to_string(options.controller[index_controller_].player_id));
|
text_->writeCentered(x_, y_ - 10, lang::getText(100) + std::to_string(options.controllers.at(index_controller_).player_id));
|
||||||
text_->writeCentered(x_, y_, controller_names_[index_controller_]);
|
text_->writeCentered(x_, y_, controller_names_.at(index_controller_));
|
||||||
text_->writeCentered(x_, y_ + 10, buttons_[index_button_].label);
|
text_->writeCentered(x_, y_ + 10, buttons_.at(index_button_).label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el botón que se ha pulsado
|
// Comprueba el botón que se ha pulsado
|
||||||
void DefineButtons::doControllerButtonDown(SDL_ControllerButtonEvent &event)
|
void DefineButtons::doControllerButtonDown(const SDL_ControllerButtonEvent &event)
|
||||||
{
|
{
|
||||||
size_t i = input_->getJoyIndex(event.which);
|
// Solo pilla botones del mando que toca
|
||||||
|
if (input_->getJoyIndex(event.which) != static_cast<int>(index_controller_))
|
||||||
// Solo pillamos botones del mando que toca
|
|
||||||
if (i != index_controller_)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -53,7 +47,7 @@ void DefineButtons::doControllerButtonDown(SDL_ControllerButtonEvent &event)
|
|||||||
const auto button = static_cast<SDL_GameControllerButton>(event.button);
|
const auto button = static_cast<SDL_GameControllerButton>(event.button);
|
||||||
if (checkButtonNotInUse(button))
|
if (checkButtonNotInUse(button))
|
||||||
{
|
{
|
||||||
buttons_[index_button_].button = button;
|
buttons_.at(index_button_).button = button;
|
||||||
incIndexButton();
|
incIndexButton();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,14 +55,14 @@ void DefineButtons::doControllerButtonDown(SDL_ControllerButtonEvent &event)
|
|||||||
// Asigna los botones definidos al input_
|
// Asigna los botones definidos al input_
|
||||||
void DefineButtons::bindButtons()
|
void DefineButtons::bindButtons()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < buttons_.size(); ++i)
|
for (const auto &button : buttons_)
|
||||||
{
|
{
|
||||||
input_->bindGameControllerButton(index_controller_, buttons_[i].input, buttons_[i].button);
|
input_->bindGameControllerButton(index_controller_, button.input, button.button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba los eventos
|
||||||
void DefineButtons::checkInput()
|
void DefineButtons::checkEvents()
|
||||||
{
|
{
|
||||||
if (enabled_)
|
if (enabled_)
|
||||||
{
|
{
|
||||||
@@ -85,13 +79,11 @@ void DefineButtons::checkInput()
|
|||||||
section::options = section::Options::QUIT_WITH_KEYBOARD;
|
section::options = section::Options::QUIT_WITH_KEYBOARD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SDL_CONTROLLERBUTTONDOWN:
|
case SDL_CONTROLLERBUTTONDOWN:
|
||||||
{
|
{
|
||||||
doControllerButtonDown(event.cbutton);
|
doControllerButtonDown(event.cbutton);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -107,6 +99,7 @@ bool DefineButtons::enable(int index)
|
|||||||
enabled_ = true;
|
enabled_ = true;
|
||||||
index_controller_ = index;
|
index_controller_ = index;
|
||||||
index_button_ = 0;
|
index_button_ = 0;
|
||||||
|
clearButtons();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,15 +107,12 @@ bool DefineButtons::enable(int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si está habilitado
|
// Comprueba si está habilitado
|
||||||
bool DefineButtons::isEnabled()
|
bool DefineButtons::isEnabled() { return enabled_; }
|
||||||
{
|
|
||||||
return enabled_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Incrementa el indice de los botones
|
// Incrementa el indice de los botones
|
||||||
void DefineButtons::incIndexButton()
|
void DefineButtons::incIndexButton()
|
||||||
{
|
{
|
||||||
index_button_++;
|
++index_button_;
|
||||||
|
|
||||||
// Comprueba si ha finalizado
|
// Comprueba si ha finalizado
|
||||||
if (index_button_ == buttons_.size())
|
if (index_button_ == buttons_.size())
|
||||||
@@ -133,11 +123,7 @@ void DefineButtons::incIndexButton()
|
|||||||
// Guarda los cambios en las opciones
|
// Guarda los cambios en las opciones
|
||||||
saveBindingsToOptions();
|
saveBindingsToOptions();
|
||||||
|
|
||||||
// input_->allActive(index_controller_);
|
// Deshabilita
|
||||||
|
|
||||||
// Reinicia variables
|
|
||||||
index_button_ = 0;
|
|
||||||
index_controller_ = 0;
|
|
||||||
enabled_ = false;
|
enabled_ = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,19 +132,14 @@ void DefineButtons::incIndexButton()
|
|||||||
void DefineButtons::saveBindingsToOptions()
|
void DefineButtons::saveBindingsToOptions()
|
||||||
{
|
{
|
||||||
// Modifica las opciones para colocar los valores asignados
|
// Modifica las opciones para colocar los valores asignados
|
||||||
options.controller[index_controller_].name = input_->getControllerName(index_controller_);
|
auto &controller = options.controllers.at(index_controller_);
|
||||||
for (int j = 0; j < (int)options.controller[index_controller_].inputs.size(); ++j)
|
controller.name = input_->getControllerName(index_controller_);
|
||||||
|
for (size_t j = 0; j < controller.inputs.size(); ++j)
|
||||||
{
|
{
|
||||||
options.controller[index_controller_].buttons[j] = input_->getControllerBinding(index_controller_, options.controller[index_controller_].inputs[j]);
|
controller.buttons.at(j) = input_->getControllerBinding(index_controller_, controller.inputs.at(j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Intercambia los jugadores asignados a los dos primeros mandos
|
|
||||||
void DefineButtons::swapControllers()
|
|
||||||
{
|
|
||||||
std::swap(options.controller[0].player_id, options.controller[1].player_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba que un botón no esté ya asignado
|
// Comprueba que un botón no esté ya asignado
|
||||||
bool DefineButtons::checkButtonNotInUse(SDL_GameControllerButton button)
|
bool DefineButtons::checkButtonNotInUse(SDL_GameControllerButton button)
|
||||||
{
|
{
|
||||||
@@ -171,3 +152,14 @@ bool DefineButtons::checkButtonNotInUse(SDL_GameControllerButton button)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Limpia la asignación de botones
|
||||||
|
void DefineButtons::clearButtons()
|
||||||
|
{
|
||||||
|
buttons_.clear();
|
||||||
|
buttons_.emplace_back(lang::getText(95), InputType::FIRE_LEFT, SDL_CONTROLLER_BUTTON_INVALID);
|
||||||
|
buttons_.emplace_back(lang::getText(96), InputType::FIRE_CENTER, SDL_CONTROLLER_BUTTON_INVALID);
|
||||||
|
buttons_.emplace_back(lang::getText(97), InputType::FIRE_RIGHT, SDL_CONTROLLER_BUTTON_INVALID);
|
||||||
|
buttons_.emplace_back(lang::getText(98), InputType::START, SDL_CONTROLLER_BUTTON_INVALID);
|
||||||
|
buttons_.emplace_back(lang::getText(99), InputType::SERVICE, SDL_CONTROLLER_BUTTON_INVALID);
|
||||||
|
}
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_events.h> // para SDL_ControllerButtonEvent
|
#include <SDL2/SDL_events.h> // Para SDL_ControllerButtonEvent
|
||||||
#include <SDL2/SDL_gamecontroller.h> // para SDL_GameControllerButton
|
#include <SDL2/SDL_gamecontroller.h> // Para SDL_GameControllerButton
|
||||||
#include <memory> // para shared_ptr, unique_ptr
|
#include <stddef.h> // Para size_t
|
||||||
#include <string> // para string
|
#include <memory> // Para shared_ptr, unique_ptr
|
||||||
#include <vector> // para vector
|
#include <string> // Para string
|
||||||
class Input;
|
#include <vector> // Para vector
|
||||||
class Text;
|
class Input; // lines 8-8
|
||||||
enum class InputType : int;
|
class Text; // lines 9-9
|
||||||
|
enum class InputType : int; // lines 10-10
|
||||||
|
|
||||||
struct DefineButtonsButton
|
struct DefineButtonsButton
|
||||||
{
|
{
|
||||||
@@ -41,7 +42,7 @@ private:
|
|||||||
void incIndexButton();
|
void incIndexButton();
|
||||||
|
|
||||||
// Comprueba el botón que se ha pulsado
|
// Comprueba el botón que se ha pulsado
|
||||||
void doControllerButtonDown(SDL_ControllerButtonEvent &event);
|
void doControllerButtonDown(const SDL_ControllerButtonEvent &event);
|
||||||
|
|
||||||
// Asigna los botones definidos al input
|
// Asigna los botones definidos al input
|
||||||
void bindButtons();
|
void bindButtons();
|
||||||
@@ -52,6 +53,9 @@ private:
|
|||||||
// Comprueba que un botón no esté ya asignado
|
// Comprueba que un botón no esté ya asignado
|
||||||
bool checkButtonNotInUse(SDL_GameControllerButton button);
|
bool checkButtonNotInUse(SDL_GameControllerButton button);
|
||||||
|
|
||||||
|
// Limpia la asignación de botones
|
||||||
|
void clearButtons();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit DefineButtons(std::unique_ptr<Text> text);
|
explicit DefineButtons(std::unique_ptr<Text> text);
|
||||||
@@ -62,15 +66,12 @@ public:
|
|||||||
// Dibuja el objeto en pantalla
|
// Dibuja el objeto en pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba los eventos
|
||||||
void checkInput();
|
void checkEvents();
|
||||||
|
|
||||||
// Habilita el objeto
|
// Habilita el objeto
|
||||||
bool enable(int index);
|
bool enable(int index);
|
||||||
|
|
||||||
// Comprueba si está habilitado
|
// Comprueba si está habilitado
|
||||||
bool isEnabled();
|
bool isEnabled();
|
||||||
|
|
||||||
// Intercambia los jugadores asignados a los dos primeros mandos
|
|
||||||
void swapControllers();
|
|
||||||
};
|
};
|
||||||
@@ -7,17 +7,17 @@
|
|||||||
#include <SDL2/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DR...
|
#include <SDL2/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DR...
|
||||||
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_0, SDL_SCANCODE_DOWN
|
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_0, SDL_SCANCODE_DOWN
|
||||||
#include <SDL2/SDL_stdinc.h> // Para SDL_bool, Uint32
|
#include <SDL2/SDL_stdinc.h> // Para SDL_bool, Uint32
|
||||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
#include <bits/chrono.h> // Para duration, system_clock
|
||||||
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO...
|
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO...
|
||||||
#include <stdio.h> // Para printf, perror
|
#include <stdio.h> // Para printf, perror
|
||||||
#include <string.h> // Para strcmp
|
|
||||||
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
|
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
|
||||||
#include <unistd.h> // Para getuid
|
#include <unistd.h> // Para getuid
|
||||||
#include <cstdlib> // Para exit, EXIT_FAILURE, rand, srand
|
#include <algorithm> // Para min
|
||||||
#include <iostream> // Para basic_ostream, operator<<, cout
|
#include <cstdlib> // Para exit, EXIT_FAILURE, size_t, rand
|
||||||
|
#include <iostream> // Para basic_ostream, operator<<, basi...
|
||||||
#include <memory> // Para make_unique, unique_ptr, make_s...
|
#include <memory> // Para make_unique, unique_ptr, make_s...
|
||||||
#include <stdexcept> // Para runtime_error
|
#include <stdexcept> // Para runtime_error
|
||||||
#include <string> // Para operator+, allocator, char_traits
|
#include <string> // Para operator+, char_traits, allocator
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
#include "asset.h" // Para Asset, AssetType
|
#include "asset.h" // Para Asset, AssetType
|
||||||
#include "dbgtxt.h" // Para dbg_init
|
#include "dbgtxt.h" // Para dbg_init
|
||||||
@@ -27,13 +27,13 @@
|
|||||||
#include "input.h" // Para Input, InputType
|
#include "input.h" // Para Input, InputType
|
||||||
#include "instructions.h" // Para Instructions
|
#include "instructions.h" // Para Instructions
|
||||||
#include "intro.h" // Para Intro
|
#include "intro.h" // Para Intro
|
||||||
#include "jail_audio.h" // Para JA_EnableMusic, JA_EnableSound
|
#include "jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundV...
|
||||||
#include "lang.h" // Para Code, loadFromFile
|
#include "lang.h" // Para Code, loadFromFile
|
||||||
#include "logo.h" // Para Logo
|
#include "logo.h" // Para Logo
|
||||||
#include "manage_hiscore_table.h" // Para ManageHiScoreTable
|
#include "manage_hiscore_table.h" // Para ManageHiScoreTable
|
||||||
#include "notifier.h" // Para Notifier
|
#include "notifier.h" // Para Notifier
|
||||||
#include "on_screen_help.h" // Para OnScreenHelp
|
#include "on_screen_help.h" // Para OnScreenHelp
|
||||||
#include "options.h" // Para Options, options, OptionsContro...
|
#include "options.h" // Para Options, OptionsController, opt...
|
||||||
#include "param.h" // Para Param, ParamGame, param, loadPa...
|
#include "param.h" // Para Param, ParamGame, param, loadPa...
|
||||||
#include "resource.h" // Para Resource
|
#include "resource.h" // Para Resource
|
||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
@@ -46,6 +46,13 @@
|
|||||||
#include <pwd.h> // para getpwuid, passwd
|
#include <pwd.h> // para getpwuid, passwd
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Inicia la semilla aleatoria
|
||||||
|
void initRand()
|
||||||
|
{
|
||||||
|
unsigned int seed = static_cast<unsigned int>(std::chrono::system_clock::now().time_since_epoch().count());
|
||||||
|
std::srand(seed);
|
||||||
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Director::Director(int argc, const char *argv[])
|
Director::Director(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
@@ -67,6 +74,8 @@ Director::Director(int argc, const char *argv[])
|
|||||||
|
|
||||||
std::cout << "Game start" << std::endl;
|
std::cout << "Game start" << std::endl;
|
||||||
|
|
||||||
|
initRand();
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
checkProgramArguments(argc, argv);
|
checkProgramArguments(argc, argv);
|
||||||
|
|
||||||
@@ -89,7 +98,7 @@ Director::Director(int argc, const char *argv[])
|
|||||||
#else
|
#else
|
||||||
const std::string paramFilePath = overrides.param_file == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
|
const std::string paramFilePath = overrides.param_file == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
|
||||||
#endif
|
#endif
|
||||||
loadParams(paramFilePath);
|
loadParamsFromFile(paramFilePath);
|
||||||
|
|
||||||
// Carga el fichero de puntuaciones
|
// Carga el fichero de puntuaciones
|
||||||
{
|
{
|
||||||
@@ -100,30 +109,18 @@ Director::Director(int argc, const char *argv[])
|
|||||||
manager->loadFromFile(Asset::get()->get("score.bin"));
|
manager->loadFromFile(Asset::get()->get("score.bin"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa SDL
|
// Inicializa todo
|
||||||
initSDL();
|
initSDL();
|
||||||
|
|
||||||
// Inicializa JailAudio
|
|
||||||
initJailAudio();
|
initJailAudio();
|
||||||
|
|
||||||
// Inicializa el texto de debug
|
|
||||||
dbg_init(renderer_);
|
dbg_init(renderer_);
|
||||||
|
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
||||||
// Crea los objetos
|
|
||||||
lang::loadFromFile(getLangFile((lang::Code)options.game.language));
|
|
||||||
|
|
||||||
Screen::init(window_, renderer_);
|
Screen::init(window_, renderer_);
|
||||||
|
|
||||||
Resource::init();
|
Resource::init();
|
||||||
|
|
||||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||||
bindInputs();
|
bindInputs();
|
||||||
|
|
||||||
auto notifier_text = std::make_shared<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
auto notifier_text = std::make_shared<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
||||||
Notifier::init(std::string(), notifier_text, Asset::get()->get("notify.wav"));
|
Notifier::init(std::string(), notifier_text, Asset::get()->get("notify.wav"));
|
||||||
|
|
||||||
OnScreenHelp::init();
|
OnScreenHelp::init();
|
||||||
|
|
||||||
globalInputs::init();
|
globalInputs::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,25 +188,21 @@ void Director::bindInputs()
|
|||||||
|
|
||||||
// Mando - Control del programa
|
// Mando - Control del programa
|
||||||
Input::get()->bindGameControllerButton(i, InputType::SERVICE, SDL_CONTROLLER_BUTTON_BACK);
|
Input::get()->bindGameControllerButton(i, InputType::SERVICE, SDL_CONTROLLER_BUTTON_BACK);
|
||||||
Input::get()->bindGameControllerButton(i, InputType::EXIT, InputType::START);
|
|
||||||
Input::get()->bindGameControllerButton(i, InputType::PAUSE, InputType::FIRE_RIGHT);
|
|
||||||
Input::get()->bindGameControllerButton(i, InputType::VIDEO_SHADERS, InputType::FIRE_LEFT);
|
|
||||||
Input::get()->bindGameControllerButton(i, InputType::MUTE, InputType::LEFT);
|
|
||||||
Input::get()->bindGameControllerButton(i, InputType::SHOWINFO, InputType::RIGHT);
|
|
||||||
Input::get()->bindGameControllerButton(i, InputType::RESET, InputType::FIRE_CENTER);
|
|
||||||
Input::get()->bindGameControllerButton(i, InputType::CONFIG, InputType::DOWN);
|
|
||||||
Input::get()->bindGameControllerButton(i, InputType::SWAP_CONTROLLERS, InputType::UP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mapea las asignaciones a los botones desde el archivo de configuración, si se da el caso
|
// Mapea las asignaciones a los botones desde el archivo de configuración, si se da el caso
|
||||||
for (int i = 0; i < num_gamepads; ++i)
|
const size_t max_controllers = std::min(2, num_gamepads);
|
||||||
for (int index = 0; index < (int)options.controller.size(); ++index)
|
for (size_t i = 0; i < max_controllers; ++i)
|
||||||
if (Input::get()->getControllerName(i) == options.controller[index].name)
|
|
||||||
{
|
{
|
||||||
options.controller[index].plugged = true;
|
for (auto &controller : options.controllers)
|
||||||
for (int j = 0; j < (int)options.controller[index].inputs.size(); ++j)
|
|
||||||
{
|
{
|
||||||
Input::get()->bindGameControllerButton(i, options.controller[index].inputs[j], options.controller[index].buttons[j]);
|
if (Input::get()->getControllerName(i) == controller.name)
|
||||||
|
{
|
||||||
|
for (size_t j = 0; j < controller.inputs.size(); ++j)
|
||||||
|
{
|
||||||
|
Input::get()->bindGameControllerButton(i, controller.inputs.at(j), controller.buttons.at(j));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,15 +219,25 @@ void Director::bindInputs()
|
|||||||
Input::get()->bindGameControllerButton(i, InputType::SWAP_CONTROLLERS, InputType::UP);
|
Input::get()->bindGameControllerButton(i, InputType::SWAP_CONTROLLERS, InputType::UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Guarda las asignaciones de botones en las opciones
|
// Guarda las asignaciones de botones en las opciones de los dos primeros mandos
|
||||||
for (int i = 0; i < num_gamepads; ++i)
|
for (size_t i = 0; i < max_controllers; ++i)
|
||||||
{
|
{
|
||||||
options.controller[i].name = Input::get()->getControllerName(i);
|
// Variables asociadas al mando
|
||||||
for (int j = 0; j < (int)options.controller[i].inputs.size(); ++j)
|
options.controllers.at(i).index = i;
|
||||||
|
options.controllers.at(i).name = Input::get()->getControllerName(i);
|
||||||
|
options.controllers.at(i).plugged = true;
|
||||||
|
// Asignaciones de botones
|
||||||
|
for (size_t j = 0; j < options.controllers.at(i).inputs.size(); ++j)
|
||||||
{
|
{
|
||||||
options.controller[i].buttons[j] = Input::get()->getControllerBinding(i, options.controller[i].inputs[j]);
|
options.controllers.at(i).buttons.at(j) = Input::get()->getControllerBinding(i, options.controllers.at(i).inputs.at(j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Asegura que algún jugador tenga el teclado asignado
|
||||||
|
if (getPlayerWhoUsesKeyboard() == 0)
|
||||||
|
{
|
||||||
|
setKeyboardToPlayer(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa JailAudio
|
// Inicializa JailAudio
|
||||||
@@ -267,34 +270,35 @@ bool Director::initSDL()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Inicia el generador de numeros aleatorios
|
/*
|
||||||
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
|
|
||||||
|
|
||||||
// Muestra información de la pantalla
|
// Muestra información de la pantalla
|
||||||
/*std::cout << "\nDisplay modes list:" << std::endl;
|
std::cout << "\nDisplay modes list:" << std::endl;
|
||||||
for (int i = 0; i < SDL_GetNumDisplayModes(0); ++i)
|
for (int i = 0; i < SDL_GetNumDisplayModes(0); ++i)
|
||||||
{
|
{
|
||||||
SDL_DisplayMode DM;
|
SDL_DisplayMode DM;
|
||||||
SDL_GetDisplayMode(0,i,&DM);
|
SDL_GetDisplayMode(0,i,&DM);
|
||||||
std::cout << " - " + std::to_string(DM.w) + "x" + std::to_string(DM.h) + " @ " + std::to_string(DM.refresh_rate) + "Hz" << std::endl;
|
std::cout << " - " << DM.w << "x" << DM.h << " @ " << DM.refresh_rate << "Hz" << std::endl;
|
||||||
}*/
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
SDL_DisplayMode DM;
|
SDL_DisplayMode DM;
|
||||||
SDL_GetCurrentDisplayMode(0, &DM);
|
SDL_GetCurrentDisplayMode(0, &DM);
|
||||||
std::cout << "\nCurrent display mode: " + std::to_string(DM.w) + "x" + std::to_string(DM.h) + " @ " + std::to_string(DM.refresh_rate) + "Hz" << std::endl;
|
std::cout << "\nCurrent display mode: " << DM.w << "x" << DM.h << " @ " << DM.refresh_rate << "Hz" << std::endl;
|
||||||
std::cout << "Window resolution : " + std::to_string(param.game.width) + "x" + std::to_string(param.game.height) + " x" + std::to_string(options.video.window.size) << std::endl;
|
std::cout << "Window resolution : " << param.game.width << "x" << param.game.height << " x" << options.video.window.size << std::endl;
|
||||||
|
|
||||||
// Establece el filtro de la textura
|
// Establece el filtro de la textura
|
||||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast<int>(options.video.filter)).c_str()))
|
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast<int>(options.video.filter)).c_str()))
|
||||||
{
|
{
|
||||||
std::cout << "Warning: texture filtering not enabled!\n";
|
std::cout << "Warning: texture filtering not enabled!\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NO_SHADERS
|
#ifndef NO_SHADERS
|
||||||
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
|
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
|
||||||
{
|
{
|
||||||
std::cout << "Warning: opengl not enabled!\n";
|
std::cout << "Warning: opengl not enabled!\n";
|
||||||
}
|
}
|
||||||
#endif // NO_SHADERS
|
#endif
|
||||||
|
|
||||||
// Crea la ventana
|
// Crea la ventana
|
||||||
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.size, param.game.height * options.video.window.size, SDL_WINDOW_HIDDEN);
|
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.size, param.game.height * options.video.window.size, SDL_WINDOW_HIDDEN);
|
||||||
if (!window_)
|
if (!window_)
|
||||||
@@ -310,10 +314,12 @@ bool Director::initSDL()
|
|||||||
{
|
{
|
||||||
flags = SDL_RENDERER_PRESENTVSYNC;
|
flags = SDL_RENDERER_PRESENTVSYNC;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NO_SHADERS
|
#ifndef NO_SHADERS
|
||||||
// La aceleración se activa según el define
|
// La aceleración se activa según el define
|
||||||
flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
|
flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
renderer_ = SDL_CreateRenderer(window_, -1, flags);
|
renderer_ = SDL_CreateRenderer(window_, -1, flags);
|
||||||
|
|
||||||
if (!renderer_)
|
if (!renderer_)
|
||||||
@@ -323,14 +329,9 @@ bool Director::initSDL()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Inicializa el color de renderizado
|
|
||||||
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
|
||||||
|
|
||||||
// Establece el tamaño del buffer de renderizado
|
|
||||||
SDL_RenderSetLogicalSize(renderer_, param.game.width, param.game.height);
|
SDL_RenderSetLogicalSize(renderer_, param.game.width, param.game.height);
|
||||||
SDL_RenderSetIntegerScale(renderer_, static_cast<SDL_bool>(options.video.integer_scale));
|
SDL_RenderSetIntegerScale(renderer_, static_cast<SDL_bool>(options.video.integer_scale));
|
||||||
|
|
||||||
// Establece el modo de mezcla
|
|
||||||
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
|
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -506,40 +507,22 @@ void Director::setFileList()
|
|||||||
throw std::runtime_error("Falta algun fichero");
|
throw std::runtime_error("Falta algun fichero");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga los parametros para configurar el juego
|
|
||||||
void Director::loadParams(const std::string &file_path)
|
|
||||||
{
|
|
||||||
loadParamsFromFile(file_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
void Director::checkProgramArguments(int argc, const char *argv[])
|
void Director::checkProgramArguments(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
const std::vector<std::string> argument_list = {"--h", "--320x240", "--clear_score"};
|
|
||||||
|
|
||||||
// Establece la ruta del programa
|
// Establece la ruta del programa
|
||||||
executable_path_ = argv[0];
|
executable_path_ = argv[0];
|
||||||
|
|
||||||
// Comprueba el resto de parámetros
|
// Comprueba el resto de parámetros
|
||||||
for (int i = 1; i < argc; ++i)
|
for (int i = 1; i < argc; ++i)
|
||||||
{
|
{
|
||||||
if (strcmp(argv[i], "--h") == 0)
|
std::string arg = argv[i];
|
||||||
{
|
|
||||||
for (const auto &argument : argument_list)
|
|
||||||
{
|
|
||||||
std::cout << argument << std::endl;
|
|
||||||
}
|
|
||||||
// std::exit(EXIT_SUCCESS);
|
|
||||||
section::name = section::Name::QUIT;
|
|
||||||
section::options = section::Options::QUIT_FROM_EVENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(argv[i], "--320x240") == 0)
|
if (arg == "--320x240")
|
||||||
{
|
{
|
||||||
overrides.param_file = argv[i];
|
overrides.param_file = arg;
|
||||||
}
|
}
|
||||||
|
else if (arg == "--clear_score")
|
||||||
if (strcmp(argv[i], "--clear_score") == 0)
|
|
||||||
{
|
{
|
||||||
overrides.clear_hi_score_table = true;
|
overrides.clear_hi_score_table = true;
|
||||||
}
|
}
|
||||||
@@ -673,54 +656,57 @@ int Director::run()
|
|||||||
case section::Name::INIT:
|
case section::Name::INIT:
|
||||||
section::name = section::Name::LOGO;
|
section::name = section::Name::LOGO;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case section::Name::LOGO:
|
case section::Name::LOGO:
|
||||||
runLogo();
|
runLogo();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case section::Name::INTRO:
|
case section::Name::INTRO:
|
||||||
runIntro();
|
runIntro();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case section::Name::TITLE:
|
case section::Name::TITLE:
|
||||||
runTitle();
|
runTitle();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case section::Name::GAME:
|
case section::Name::GAME:
|
||||||
runGame();
|
runGame();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case section::Name::HI_SCORE_TABLE:
|
case section::Name::HI_SCORE_TABLE:
|
||||||
runHiScoreTable();
|
runHiScoreTable();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case section::Name::GAME_DEMO:
|
case section::Name::GAME_DEMO:
|
||||||
runDemoGame();
|
runDemoGame();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case section::Name::INSTRUCTIONS:
|
case section::Name::INSTRUCTIONS:
|
||||||
runInstructions();
|
runInstructions();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ARCADE
|
std::string return_code;
|
||||||
// Comprueba si ha de apagar el sistema
|
switch (section::options)
|
||||||
if (section::options == section::Options::QUIT_WITH_CONTROLLER)
|
{
|
||||||
shutdownSystem();
|
case section::Options::QUIT_WITH_KEYBOARD:
|
||||||
#endif
|
return_code = "with keyboard";
|
||||||
|
break;
|
||||||
|
case section::Options::QUIT_WITH_CONTROLLER:
|
||||||
|
return_code = "with controller";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return_code = "from event";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
const auto return_code = (section::options == section::Options::QUIT_WITH_KEYBOARD) ? "with keyboard" : (section::options == section::Options::QUIT_WITH_CONTROLLER) ? "with controller"
|
|
||||||
: "from event";
|
|
||||||
std::cout << "\nGame end " << return_code << std::endl;
|
std::cout << "\nGame end " << return_code << std::endl;
|
||||||
|
|
||||||
#ifndef VERBOSE
|
#ifndef VERBOSE
|
||||||
// Habilita de nuevo los std::cout
|
// Habilita de nuevo los std::cout
|
||||||
std::cout.rdbuf(orig_buf);
|
std::cout.rdbuf(orig_buf);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ARCADE
|
||||||
|
// Comprueba si ha de apagar el sistema
|
||||||
|
if (section::options == section::Options::QUIT_WITH_CONTROLLER)
|
||||||
|
shutdownSystem();
|
||||||
|
#endif
|
||||||
|
|
||||||
return (section::options == section::Options::QUIT_WITH_CONTROLLER) ? 1 : 0;
|
return (section::options == section::Options::QUIT_WITH_CONTROLLER) ? 1 : 0;
|
||||||
}
|
}
|
||||||
@@ -733,15 +719,12 @@ std::string Director::getLangFile(lang::Code code)
|
|||||||
case lang::Code::ba_BA:
|
case lang::Code::ba_BA:
|
||||||
return Asset::get()->get("ba_BA.txt");
|
return Asset::get()->get("ba_BA.txt");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case lang::Code::es_ES:
|
case lang::Code::es_ES:
|
||||||
return Asset::get()->get("es_ES.txt");
|
return Asset::get()->get("es_ES.txt");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case lang::Code::en_UK:
|
case lang::Code::en_UK:
|
||||||
return Asset::get()->get("en_UK.txt");
|
return Asset::get()->get("en_UK.txt");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,9 +34,6 @@ private:
|
|||||||
// Asigna los botones y teclas al objeto Input
|
// Asigna los botones y teclas al objeto Input
|
||||||
void bindInputs();
|
void bindInputs();
|
||||||
|
|
||||||
// Carga los parametros para configurar el juego
|
|
||||||
void loadParams(const std::string &file_path);
|
|
||||||
|
|
||||||
// Crea el indice de ficheros
|
// Crea el indice de ficheros
|
||||||
void setFileList();
|
void setFileList();
|
||||||
|
|
||||||
|
|||||||
140
source/game.cpp
140
source/game.cpp
@@ -1,39 +1,39 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "asset.h" // for Asset
|
#include "asset.h" // Para Asset
|
||||||
#include "background.h" // for Background
|
#include "background.h" // Para Background
|
||||||
#include "balloon.h" // for Balloon, BALLOON_SCORE, BALLOON_VE...
|
#include "balloon.h" // Para Balloon, BALLOON_SCORE, BALLOON_VE...
|
||||||
#include "balloon_formations.h" // for BalloonFormations, BalloonFormatio...
|
#include "balloon_formations.h" // Para BalloonFormations, BalloonFormatio...
|
||||||
#include "bullet.h" // for Bullet, BulletType, BulletMoveStatus
|
#include "bullet.h" // Para Bullet, BulletType, BulletMoveStatus
|
||||||
#include "explosions.h" // for Explosions
|
#include "explosions.h" // Para Explosions
|
||||||
#include "fade.h" // for Fade, FadeType
|
#include "fade.h" // Para Fade, FadeType
|
||||||
#include "global_inputs.h" // for check
|
#include "global_inputs.h" // Para check
|
||||||
#include "input.h" // for InputType, Input, INPUT_DO_NOT_ALL...
|
#include "input.h" // Para InputType, Input, INPUT_DO_NOT_ALL...
|
||||||
#include "item.h" // for Item, ItemType
|
#include "item.h" // Para Item, ItemType
|
||||||
#include "jail_audio.h" // for JA_PlaySound, JA_GetMusicState
|
#include "jail_audio.h" // Para JA_PlaySound, JA_GetMusicState
|
||||||
#include "lang.h" // for getText
|
#include "lang.h" // Para getText
|
||||||
#include "manage_hiscore_table.h" // for ManageHiScoreTable, HiScoreEntry
|
#include "manage_hiscore_table.h" // Para ManageHiScoreTable, HiScoreEntry
|
||||||
#include "notifier.h" // for Notifier
|
#include "notifier.h" // Para Notifier
|
||||||
#include "param.h" // for Param, param, ParamGame, ParamFade
|
#include "param.h" // Para Param, param, ParamGame, ParamFade
|
||||||
#include "path_sprite.h" // for Path, PathSprite, createPath, Path...
|
#include "path_sprite.h" // Para Path, PathSprite, createPath, Path...
|
||||||
#include "player.h" // for Player, PlayerStatus
|
#include "player.h" // Para Player, PlayerStatus
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // Para Resource
|
||||||
#include "scoreboard.h" // for Scoreboard, ScoreboardMode, SCOREB...
|
#include "scoreboard.h" // Para Scoreboard, ScoreboardMode, SCOREB...
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // Para Screen
|
||||||
#include "section.h" // for Name, name, Options, options
|
#include "section.h" // Para Name, name, Options, options
|
||||||
#include "smart_sprite.h" // for SmartSprite
|
#include "smart_sprite.h" // Para SmartSprite
|
||||||
#include "text.h" // for Text
|
#include "text.h" // Para Text
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // Para Texture
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
||||||
#include <SDL2/SDL_keycode.h> // for SDLK_1, SDLK_2, SDLK_3, SDLK_4
|
#include <SDL2/SDL_keycode.h> // Para SDLK_1, SDLK_2, SDLK_3, SDLK_4
|
||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_FOCUS_GAINED, SDL_...
|
#include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_FOCUS_GAINED, SDL_...
|
||||||
#include <algorithm> // for find_if, clamp, min, remove_if
|
#include <algorithm> // Para find_if, clamp, min, remove_if
|
||||||
#include <functional> // for function
|
#include <functional> // Para function
|
||||||
#include <iterator> // for distance, size
|
#include <iterator> // Para distance, size
|
||||||
#include <numeric> // for accumulate
|
#include <numeric> // Para accumulate
|
||||||
#include <stdlib.h> // for rand, size_t
|
#include <stdlib.h> // Para rand, size_t
|
||||||
|
|
||||||
struct JA_Sound_t; // lines 36-36
|
struct JA_Sound_t; // lines 36-36
|
||||||
|
|
||||||
@@ -87,6 +87,7 @@ Game::Game(int player_id, int current_stage, bool demo)
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// Si se empieza en una fase que no es la primera
|
// Si se empieza en una fase que no es la primera
|
||||||
|
if (!demo_.enabled)
|
||||||
for (int i = 0; i < current_stage_; ++i)
|
for (int i = 0; i < current_stage_; ++i)
|
||||||
{
|
{
|
||||||
balloons_popped_ += balloon_formations_->getStage(i).power_to_complete;
|
balloons_popped_ += balloon_formations_->getStage(i).power_to_complete;
|
||||||
@@ -1450,7 +1451,7 @@ void Game::checkEvents()
|
|||||||
case SDLK_3: // Activa el modo para pasar el juego automaticamente
|
case SDLK_3: // Activa el modo para pasar el juego automaticamente
|
||||||
{
|
{
|
||||||
auto_pop_balloons_ = !auto_pop_balloons_;
|
auto_pop_balloons_ = !auto_pop_balloons_;
|
||||||
Notifier::get()->showText("auto_pop_balloons_ " + boolToString(auto_pop_balloons_));
|
Notifier::get()->showText({"auto_pop_balloons_ " + boolToString(auto_pop_balloons_)});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SDLK_4: // Suelta un item
|
case SDLK_4: // Suelta un item
|
||||||
@@ -1590,12 +1591,12 @@ std::shared_ptr<Player> Game::getPlayer(int id)
|
|||||||
// Obtiene un controlador a partir del "id" del jugador
|
// Obtiene un controlador a partir del "id" del jugador
|
||||||
int Game::getController(int player_id)
|
int Game::getController(int player_id)
|
||||||
{
|
{
|
||||||
auto it = std::find_if(options.controller.begin(), options.controller.end(), [player_id](const auto &controller)
|
auto it = std::find_if(options.controllers.begin(), options.controllers.end(), [player_id](const auto &controller)
|
||||||
{ return controller.player_id == player_id; });
|
{ return controller.player_id == player_id; });
|
||||||
|
|
||||||
if (it != options.controller.end())
|
if (it != options.controllers.end())
|
||||||
{
|
{
|
||||||
return std::distance(options.controller.begin(), it);
|
return std::distance(options.controllers.begin(), it);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@@ -1604,19 +1605,13 @@ int Game::getController(int player_id)
|
|||||||
// Gestiona la entrada durante el juego
|
// Gestiona la entrada durante el juego
|
||||||
void Game::checkInput()
|
void Game::checkInput()
|
||||||
{
|
{
|
||||||
checkPauseInput(); // Verifica si se debe pausar el juego.
|
// Verifica si se debe pausar el juego.
|
||||||
|
checkPauseInput();
|
||||||
|
|
||||||
if (demo_.enabled)
|
demo_.enabled ? handleDemoMode() : handlePlayersInput();
|
||||||
{ // Controla el comportamiento de los jugadores en modo demo.
|
|
||||||
handleDemoMode();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // Gestiona el input normal de los jugadores.
|
|
||||||
handlePlayersInput();
|
|
||||||
}
|
|
||||||
|
|
||||||
screen_->checkInput(); // Verifica el input en la pantalla del juego.
|
// Verifica los inputs globales.
|
||||||
globalInputs::check(); // Verifica los inputs globales.
|
globalInputs::check();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verifica si alguno de los controladores ha solicitado una pausa y actualiza el estado de pausa del juego.
|
// Verifica si alguno de los controladores ha solicitado una pausa y actualiza el estado de pausa del juego.
|
||||||
@@ -1624,16 +1619,17 @@ 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_->checkModInput(InputType::SERVICE, InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, 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_); // Alterna entre pausado y no pausado.
|
pause(!paused_);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el teclado
|
// Comprueba el teclado
|
||||||
if (input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
if (input_->checkInput(InputType::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||||
{
|
{
|
||||||
pause(!paused_); // Alterna entre pausado y no pausado.
|
pause(!paused_);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1727,17 +1723,17 @@ void Game::handlePlayersInput()
|
|||||||
// Maneja las entradas de movimiento y disparo para un jugador en modo normal.
|
// Maneja las entradas de movimiento y disparo para un jugador en modo normal.
|
||||||
void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player)
|
void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player)
|
||||||
{
|
{
|
||||||
const auto controllerIndex = player->getController();
|
const auto &controller = options.controllers.at(player->getController());
|
||||||
const bool autofire = player->isPowerUp() || options.game.autofire;
|
const bool autofire = player->isPowerUp() || options.game.autofire;
|
||||||
|
|
||||||
if (input_->checkInput(InputType::LEFT, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
if (input_->checkInput(InputType::LEFT, INPUT_ALLOW_REPEAT, controller.type, controller.index))
|
||||||
{
|
{
|
||||||
player->setInput(InputType::LEFT);
|
player->setInput(InputType::LEFT);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo_.keys.left = 1;
|
demo_.keys.left = 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (input_->checkInput(InputType::RIGHT, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
else if (input_->checkInput(InputType::RIGHT, INPUT_ALLOW_REPEAT, controller.type, controller.index))
|
||||||
{
|
{
|
||||||
player->setInput(InputType::RIGHT);
|
player->setInput(InputType::RIGHT);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
@@ -1752,27 +1748,27 @@ void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
handleFireInputs(player, autofire, controllerIndex); // Verifica y maneja todas las posibles entradas de disparo.
|
handleFireInputs(player, autofire, player->getController()); // Verifica y maneja todas las posibles entradas de disparo.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Procesa las entradas de disparo del jugador, permitiendo disparos automáticos si está habilitado.
|
// Procesa las entradas de disparo del jugador, permitiendo disparos automáticos si está habilitado.
|
||||||
void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire, int controllerIndex)
|
void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire, int controllerIndex)
|
||||||
{
|
{
|
||||||
if (input_->checkInput(InputType::FIRE_CENTER, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
if (input_->checkInput(InputType::FIRE_CENTER, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||||
{
|
{
|
||||||
handleFireInput(player, BulletType::UP);
|
handleFireInput(player, BulletType::UP);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo_.keys.fire = 1;
|
demo_.keys.fire = 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (input_->checkInput(InputType::FIRE_LEFT, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
else if (input_->checkInput(InputType::FIRE_LEFT, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||||
{
|
{
|
||||||
handleFireInput(player, BulletType::LEFT);
|
handleFireInput(player, BulletType::LEFT);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
demo_.keys.fire_left = 1;
|
demo_.keys.fire_left = 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (input_->checkInput(InputType::FIRE_RIGHT, autofire, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
else if (input_->checkInput(InputType::FIRE_RIGHT, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||||
{
|
{
|
||||||
handleFireInput(player, BulletType::RIGHT);
|
handleFireInput(player, BulletType::RIGHT);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
@@ -1785,15 +1781,15 @@ void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire
|
|||||||
void Game::handlePlayerContinue(const std::shared_ptr<Player> &player)
|
void Game::handlePlayerContinue(const std::shared_ptr<Player> &player)
|
||||||
{
|
{
|
||||||
const auto controllerIndex = player->getController();
|
const auto controllerIndex = player->getController();
|
||||||
if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||||
{
|
{
|
||||||
player->setPlayingState(PlayerState::PLAYING);
|
player->setPlayingState(PlayerState::PLAYING);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disminuye el contador de continuación si se presiona cualquier botón de disparo.
|
// Disminuye el contador de continuación si se presiona cualquier botón de disparo.
|
||||||
if (input_->checkInput(InputType::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index) ||
|
if (input_->checkInput(InputType::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
|
||||||
input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index) ||
|
input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
|
||||||
input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||||
{
|
{
|
||||||
player->decContinueCounter();
|
player->decContinueCounter();
|
||||||
}
|
}
|
||||||
@@ -1803,9 +1799,9 @@ void Game::handlePlayerContinue(const std::shared_ptr<Player> &player)
|
|||||||
void Game::handleNameInput(const std::shared_ptr<Player> &player)
|
void Game::handleNameInput(const std::shared_ptr<Player> &player)
|
||||||
{
|
{
|
||||||
const auto controllerIndex = player->getController();
|
const auto controllerIndex = player->getController();
|
||||||
if (input_->checkInput(InputType::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index) ||
|
if (input_->checkInput(InputType::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
|
||||||
input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index) ||
|
input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
|
||||||
input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||||
{
|
{
|
||||||
if (player->getRecordNamePos() == 7)
|
if (player->getRecordNamePos() == 7)
|
||||||
{
|
{
|
||||||
@@ -1819,15 +1815,15 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player)
|
|||||||
player->setInput(InputType::RIGHT);
|
player->setInput(InputType::RIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (input_->checkInput(InputType::UP, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
else if (input_->checkInput(InputType::UP, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||||
{
|
{
|
||||||
player->setInput(InputType::UP);
|
player->setInput(InputType::UP);
|
||||||
}
|
}
|
||||||
else if (input_->checkInput(InputType::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
else if (input_->checkInput(InputType::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||||
{
|
{
|
||||||
player->setInput(InputType::DOWN);
|
player->setInput(InputType::DOWN);
|
||||||
}
|
}
|
||||||
else if (input_->checkInput(InputType::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
else if (input_->checkInput(InputType::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||||
{
|
{
|
||||||
player->setInput(InputType::LEFT);
|
player->setInput(InputType::LEFT);
|
||||||
}
|
}
|
||||||
@@ -1837,7 +1833,7 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player)
|
|||||||
player->setInput(InputType::RIGHT);
|
player->setInput(InputType::RIGHT);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
else if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].device_type, options.controller[controllerIndex].index))
|
else if (input_->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||||
{
|
{
|
||||||
player->setInput(InputType::START);
|
player->setInput(InputType::START);
|
||||||
addScoreToScoreBoard(player->getRecordName(), player->getScore());
|
addScoreToScoreBoard(player->getRecordName(), player->getScore());
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
|
#include <SDL2/SDL_stdinc.h> // Para Uint32, Uint8
|
||||||
#include <memory> // for shared_ptr, unique_ptr
|
#include <memory> // Para shared_ptr, unique_ptr
|
||||||
#include <string> // for string
|
#include <string> // Para string
|
||||||
#include <vector> // for vector
|
#include <vector> // Para vector
|
||||||
#include "balloon.h" // for Balloon
|
#include "balloon.h" // Para Balloon
|
||||||
#include "manage_hiscore_table.h" // for HiScoreEntry
|
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
||||||
#include "options.h" // for Options, OptionsGame, options
|
#include "options.h" // Para Options, OptionsGame, options
|
||||||
#include "player.h" // for Player
|
#include "player.h" // Para Player
|
||||||
#include "utils.h" // for Demo
|
#include "utils.h" // Para Demo
|
||||||
class Asset; // lines 14-14
|
class Asset; // lines 14-14
|
||||||
class Background; // lines 15-15
|
class Background; // lines 15-15
|
||||||
class BalloonFormations; // lines 16-16
|
class BalloonFormations; // lines 16-16
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "options.h" // Para Options, OptionsAudio, options, OptionsM...
|
#include "options.h" // Para Options, OptionsAudio, options, OptionsM...
|
||||||
#include "section.h" // Para Name, Options, name, options
|
#include "section.h" // Para Name, Options, name, options
|
||||||
#include "utils.h" // Para boolToOnOff, stringInVector
|
#include "utils.h" // Para boolToOnOff, stringInVector
|
||||||
|
#include "screen.h"
|
||||||
|
|
||||||
namespace globalInputs
|
namespace globalInputs
|
||||||
{
|
{
|
||||||
@@ -39,9 +40,9 @@ namespace globalInputs
|
|||||||
{
|
{
|
||||||
#ifdef ARCADE
|
#ifdef ARCADE
|
||||||
const int index = code == section::Options::QUIT_WITH_CONTROLLER ? 116 : 94;
|
const int index = code == section::Options::QUIT_WITH_CONTROLLER ? 116 : 94;
|
||||||
Notifier::get()->showText(lang::getText(index), std::string(), -1, exit_code);
|
Notifier::get()->showText({lang::getText(index), std::string()}, -1, exit_code);
|
||||||
#else
|
#else
|
||||||
Notifier::get()->showText(lang::getText(94), std::string(), -1, exit_code);
|
Notifier::get()->showText({lang::getText(94), std::string()}, -1, exit_code);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,11 +51,11 @@ namespace globalInputs
|
|||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
section::name = section::Name::INIT;
|
section::name = section::Name::INIT;
|
||||||
Notifier::get()->showText("Reset");
|
Notifier::get()->showText({"Reset"});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activa o desactiva el audio
|
// Activa o desactiva el audio
|
||||||
void switchAudio()
|
void toggleAudio()
|
||||||
{
|
{
|
||||||
options.audio.enabled = !options.audio.enabled;
|
options.audio.enabled = !options.audio.enabled;
|
||||||
if (options.audio.enabled)
|
if (options.audio.enabled)
|
||||||
@@ -67,33 +68,80 @@ namespace globalInputs
|
|||||||
JA_SetMusicVolume(0);
|
JA_SetMusicVolume(0);
|
||||||
JA_SetSoundVolume(0);
|
JA_SetSoundVolume(0);
|
||||||
}
|
}
|
||||||
Notifier::get()->showText("Audio " + boolToOnOff(options.audio.enabled));
|
Notifier::get()->showText({"Audio " + boolToOnOff(options.audio.enabled)});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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()
|
||||||
{
|
{
|
||||||
// Comprueba si se sale con el teclado
|
// Teclado
|
||||||
if (Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
{
|
||||||
|
#ifndef ARCADE
|
||||||
|
// Comprueba el teclado para cambiar entre pantalla completa y ventana
|
||||||
|
if (Input::get()->checkInput(InputType::WINDOW_FULLSCREEN, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||||
|
{
|
||||||
|
Screen::get()->toggleVideoMode();
|
||||||
|
const std::string mode = options.video.mode == ScreenVideoMode::WINDOW ? "Window" : "Fullscreen";
|
||||||
|
Notifier::get()->showText({mode + " mode"});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba el teclado para decrementar el tamaño de la ventana
|
||||||
|
if (Input::get()->checkInput(InputType::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||||
|
{
|
||||||
|
Screen::get()->decWindowSize();
|
||||||
|
const std::string size = std::to_string(options.video.window.size);
|
||||||
|
Notifier::get()->showText({"Window size x" + size});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba el teclado para incrementar el tamaño de la ventana
|
||||||
|
if (Input::get()->checkInput(InputType::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||||
|
{
|
||||||
|
Screen::get()->incWindowSize();
|
||||||
|
const std::string size = std::to_string(options.video.window.size);
|
||||||
|
Notifier::get()->showText({"Window size x" + size});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// Salir
|
||||||
|
if (Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||||
{
|
{
|
||||||
quit(section::Options::QUIT_WITH_KEYBOARD);
|
quit(section::Options::QUIT_WITH_KEYBOARD);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si se va a resetear el juego
|
// Reset
|
||||||
else if (Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
if (Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
// Audio
|
||||||
|
if (Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||||
{
|
{
|
||||||
switchAudio();
|
toggleAudio();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
// Shaders
|
||||||
|
if (Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||||
|
{
|
||||||
|
Screen::get()->toggleShaders();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
// Comprueba el teclado para mostrar la información de debug
|
||||||
|
if (Input::get()->checkInput(InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||||
|
{
|
||||||
|
Screen::get()->toggleDebugInfo();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// OnScreenHelp
|
||||||
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||||
{
|
{
|
||||||
service_pressed_counter[0]++;
|
service_pressed_counter[0]++;
|
||||||
|
|
||||||
@@ -104,35 +152,56 @@ namespace globalInputs
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
service_pressed_counter[0] = 0;
|
service_pressed_counter[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mandos
|
||||||
|
{
|
||||||
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
||||||
{
|
{
|
||||||
// Comprueba si se sale con el mando
|
// Salir
|
||||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
||||||
|
Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||||
{
|
{
|
||||||
quit(section::Options::QUIT_WITH_CONTROLLER);
|
quit(section::Options::QUIT_WITH_CONTROLLER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si se va a resetear el juego
|
// Reset
|
||||||
else if (Input::get()->checkModInput(InputType::SERVICE, InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
||||||
|
Input::get()->checkInput(InputType::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si se va a activar o desactivar el audio
|
// Audio
|
||||||
else if (Input::get()->checkModInput(InputType::SERVICE, InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
||||||
|
Input::get()->checkInput(InputType::MUTE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||||
{
|
{
|
||||||
switchAudio();
|
toggleAudio();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
// Shaders
|
||||||
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
||||||
|
Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||||
|
{
|
||||||
|
Screen::get()->toggleShaders();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
// Debug Info
|
||||||
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
||||||
|
Input::get()->checkInput(InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||||
|
{
|
||||||
|
Screen::get()->toggleDebugInfo();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// OnScreenHelp
|
||||||
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||||
{
|
{
|
||||||
service_pressed_counter[i + 1]++;
|
service_pressed_counter[i + 1]++;
|
||||||
|
|
||||||
@@ -143,8 +212,7 @@ namespace globalInputs
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
service_pressed_counter[i + 1] = 0;
|
service_pressed_counter[i + 1] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,9 +208,6 @@ void HiScoreTable::checkInput()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input para el resto de objetos
|
|
||||||
Screen::get()->checkInput();
|
|
||||||
|
|
||||||
// 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
|
||||||
globalInputs::check();
|
globalInputs::check();
|
||||||
}
|
}
|
||||||
|
|||||||
386
source/input.cpp
386
source/input.cpp
@@ -1,9 +1,13 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include <SDL2/SDL.h> // para SDL_INIT_GAMECONTROLLER, SDL_InitSubS...
|
#include <SDL2/SDL.h> // Para SDL_INIT_GAMECONTROLLER, SDL_InitSubS...
|
||||||
#include <SDL2/SDL_error.h> // para SDL_GetError
|
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||||
#include <SDL2/SDL_events.h> // para SDL_ENABLE
|
#include <SDL2/SDL_events.h> // Para SDL_ENABLE
|
||||||
#include <SDL2/SDL_keyboard.h> // para SDL_GetKeyboardState
|
#include <SDL2/SDL_keyboard.h> // Para SDL_GetKeyboardState
|
||||||
#include <iostream> // para basic_ostream, operator<<, cout, basi...
|
#include <algorithm> // Para find
|
||||||
|
#include <iostream> // Para basic_ostream, operator<<, cout, endl
|
||||||
|
#include <iterator> // Para distance
|
||||||
|
#include <unordered_map> // Para unordered_map, operator==, _Node_cons...
|
||||||
|
#include <utility> // Para pair
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
Input *Input::input_ = nullptr;
|
Input *Input::input_ = nullptr;
|
||||||
@@ -28,49 +32,23 @@ Input *Input::get()
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Input::Input(const std::string &game_controller_db_path)
|
Input::Input(const std::string &game_controller_db_path)
|
||||||
: game_controller_db_path_(game_controller_db_path),
|
: game_controller_db_path_(game_controller_db_path)
|
||||||
enabled_(true)
|
|
||||||
{
|
{
|
||||||
// Busca si hay mandos conectados
|
// Busca si hay mandos conectados
|
||||||
discoverGameControllers();
|
discoverGameControllers();
|
||||||
|
|
||||||
// Inicializa las vectores
|
// Inicializa los vectores
|
||||||
KeyBindings kb;
|
key_bindings_.resize(static_cast<int>(InputType::NUMBER_OF_INPUTS), KeyBindings());
|
||||||
kb.scancode = 0;
|
controller_bindings_.resize(num_gamepads_, std::vector<ControllerBindings>(static_cast<int>(InputType::NUMBER_OF_INPUTS), ControllerBindings()));
|
||||||
kb.active = false;
|
|
||||||
key_bindings_.resize(static_cast<int>(InputType::NUMBER_OF_INPUTS), kb);
|
|
||||||
|
|
||||||
ControllerBindings gcb;
|
|
||||||
gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
|
|
||||||
gcb.active = false;
|
|
||||||
controller_bindings_.resize(num_gamepads_);
|
|
||||||
for (int i = 0; i < num_gamepads_; ++i)
|
|
||||||
{
|
|
||||||
controller_bindings_[i].resize(static_cast<int>(InputType::NUMBER_OF_INPUTS), gcb);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Listado de los inputs usados para jugar, excluyendo botones para la interfaz
|
|
||||||
game_inputs_.clear();
|
|
||||||
game_inputs_.push_back(InputType::FIRE_LEFT);
|
|
||||||
game_inputs_.push_back(InputType::FIRE_CENTER);
|
|
||||||
game_inputs_.push_back(InputType::FIRE_RIGHT);
|
|
||||||
game_inputs_.push_back(InputType::UP);
|
|
||||||
game_inputs_.push_back(InputType::DOWN);
|
|
||||||
game_inputs_.push_back(InputType::LEFT);
|
|
||||||
game_inputs_.push_back(InputType::RIGHT);
|
|
||||||
|
|
||||||
// Listado de los inputs para jugar que utilizan botones, ni palancas ni crucetas
|
// Listado de los inputs para jugar que utilizan botones, ni palancas ni crucetas
|
||||||
button_inputs_.clear();
|
button_inputs_ = {InputType::FIRE_LEFT, InputType::FIRE_CENTER, InputType::FIRE_RIGHT, InputType::START};
|
||||||
button_inputs_.push_back(InputType::FIRE_LEFT);
|
|
||||||
button_inputs_.push_back(InputType::FIRE_CENTER);
|
|
||||||
button_inputs_.push_back(InputType::FIRE_RIGHT);
|
|
||||||
button_inputs_.push_back(InputType::START);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asigna inputs a teclas
|
// Asigna inputs a teclas
|
||||||
void Input::bindKey(InputType input, SDL_Scancode code)
|
void Input::bindKey(InputType input, SDL_Scancode code)
|
||||||
{
|
{
|
||||||
key_bindings_[static_cast<int>(input)].scancode = code;
|
key_bindings_.at(static_cast<int>(input)).scancode = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asigna inputs a botones del mando
|
// Asigna inputs a botones del mando
|
||||||
@@ -78,7 +56,7 @@ void Input::bindGameControllerButton(int controller_index, InputType input, SDL_
|
|||||||
{
|
{
|
||||||
if (controller_index < num_gamepads_)
|
if (controller_index < num_gamepads_)
|
||||||
{
|
{
|
||||||
controller_bindings_[controller_index][static_cast<int>(input)].button = button;
|
controller_bindings_.at(controller_index).at(static_cast<int>(input)).button = button;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,41 +65,24 @@ void Input::bindGameControllerButton(int controller_index, InputType input_targe
|
|||||||
{
|
{
|
||||||
if (controller_index < num_gamepads_)
|
if (controller_index < num_gamepads_)
|
||||||
{
|
{
|
||||||
controller_bindings_[controller_index][static_cast<int>(input_target)].button = controller_bindings_[controller_index][static_cast<int>(input_source)].button;
|
controller_bindings_.at(controller_index).at(static_cast<int>(input_target)).button = controller_bindings_.at(controller_index).at(static_cast<int>(input_source)).button;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si un input esta activo
|
// Comprueba si un input esta activo
|
||||||
bool Input::checkInput(InputType input, bool repeat, int device, int controller_index)
|
bool Input::checkInput(InputType input, bool repeat, InputDeviceToUse device, int controller_index)
|
||||||
{
|
{
|
||||||
if (!enabled_)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool success_keyboard = false;
|
bool success_keyboard = false;
|
||||||
bool success_controller = false;
|
bool success_controller = false;
|
||||||
const int input_index = static_cast<int>(input);
|
const int input_index = static_cast<int>(input);
|
||||||
|
|
||||||
if (device == INPUT_USE_ANY)
|
if (device == InputDeviceToUse::KEYBOARD || device == InputDeviceToUse::ANY)
|
||||||
{
|
|
||||||
controller_index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
|
||||||
{
|
{
|
||||||
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
|
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
|
||||||
|
|
||||||
if (repeat)
|
if (repeat)
|
||||||
{
|
{
|
||||||
if (keyStates[key_bindings_[input_index].scancode] != 0)
|
success_keyboard = keyStates[key_bindings_[input_index].scancode] != 0;
|
||||||
{
|
|
||||||
success_keyboard = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success_keyboard = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -142,26 +103,29 @@ bool Input::checkInput(InputType input, bool repeat, int device, int controller_
|
|||||||
if (keyStates[key_bindings_[input_index].scancode] == 0)
|
if (keyStates[key_bindings_[input_index].scancode] == 0)
|
||||||
{
|
{
|
||||||
key_bindings_[input_index].active = false;
|
key_bindings_[input_index].active = false;
|
||||||
success_keyboard = false;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
success_keyboard = false;
|
success_keyboard = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (gameControllerFound() && controller_index < num_gamepads_)
|
if (gameControllerFound() && controller_index >= 0 && controller_index < num_gamepads_)
|
||||||
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
|
if ((device == InputDeviceToUse::CONTROLLER) || (device == InputDeviceToUse::ANY))
|
||||||
{
|
{
|
||||||
success_controller = checkAxisInput(input, controller_index);
|
success_controller = checkAxisInput(input, controller_index);
|
||||||
if (!success_controller)
|
if (!success_controller)
|
||||||
{
|
{
|
||||||
if (repeat)
|
if (repeat)
|
||||||
{
|
{
|
||||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) != 0)
|
success_controller = SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) != 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
|
if (!controller_bindings_.at(controller_index).at(input_index).active)
|
||||||
|
{
|
||||||
|
if (SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) != 0)
|
||||||
|
{
|
||||||
|
controller_bindings_.at(controller_index).at(input_index).active = true;
|
||||||
success_controller = true;
|
success_controller = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -171,142 +135,13 @@ bool Input::checkInput(InputType input, bool repeat, int device, int controller_
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!controller_bindings_[controller_index][input_index].active)
|
if (SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) == 0)
|
||||||
{
|
{
|
||||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) != 0)
|
controller_bindings_.at(controller_index).at(input_index).active = false;
|
||||||
{
|
|
||||||
controller_bindings_[controller_index][input_index].active = true;
|
|
||||||
success_controller = true;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
success_controller = false;
|
success_controller = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) == 0)
|
|
||||||
{
|
|
||||||
controller_bindings_[controller_index][input_index].active = false;
|
|
||||||
success_controller = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success_controller = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (success_keyboard || success_controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si un input con modificador esta activo
|
|
||||||
bool Input::checkModInput(InputType input_mod, InputType input, bool repeat, int device, int controller_index)
|
|
||||||
{
|
|
||||||
if (!enabled_ || controller_index >= num_gamepads_ || !checkInput(input_mod, INPUT_ALLOW_REPEAT, device, controller_index))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool success_keyboard = false;
|
|
||||||
bool success_controller = false;
|
|
||||||
const int input_index = static_cast<int>(input);
|
|
||||||
|
|
||||||
if (device == INPUT_USE_ANY)
|
|
||||||
{
|
|
||||||
controller_index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
|
||||||
{
|
|
||||||
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
|
|
||||||
|
|
||||||
if (repeat)
|
|
||||||
{
|
|
||||||
if (keyStates[key_bindings_[input_index].scancode] != 0)
|
|
||||||
{
|
|
||||||
success_keyboard = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success_keyboard = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!key_bindings_[input_index].active)
|
|
||||||
{
|
|
||||||
if (keyStates[key_bindings_[input_index].scancode] != 0)
|
|
||||||
{
|
|
||||||
key_bindings_[input_index].active = true;
|
|
||||||
success_keyboard = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success_keyboard = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (keyStates[key_bindings_[input_index].scancode] == 0)
|
|
||||||
{
|
|
||||||
key_bindings_[input_index].active = false;
|
|
||||||
success_keyboard = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success_keyboard = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gameControllerFound() && controller_index < num_gamepads_)
|
|
||||||
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
|
|
||||||
{
|
|
||||||
success_controller = checkAxisInput(input, controller_index);
|
|
||||||
if (!success_controller)
|
|
||||||
{
|
|
||||||
if (repeat)
|
|
||||||
{
|
|
||||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) != 0)
|
|
||||||
{
|
|
||||||
success_controller = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success_controller = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!controller_bindings_[controller_index][input_index].active)
|
|
||||||
{
|
|
||||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) != 0)
|
|
||||||
{
|
|
||||||
controller_bindings_[controller_index][input_index].active = true;
|
|
||||||
success_controller = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success_controller = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][input_index].button) == 0)
|
|
||||||
{
|
|
||||||
controller_bindings_[controller_index][input_index].active = false;
|
|
||||||
success_controller = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success_controller = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,14 +149,9 @@ bool Input::checkModInput(InputType input_mod, InputType input, bool repeat, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si hay almenos un input activo
|
// Comprueba si hay almenos un input activo
|
||||||
bool Input::checkAnyInput(int device, int controller_index)
|
bool Input::checkAnyInput(InputDeviceToUse device, int controller_index)
|
||||||
{
|
{
|
||||||
if (device == INPUT_USE_ANY)
|
if (device == InputDeviceToUse::KEYBOARD || device == InputDeviceToUse::ANY)
|
||||||
{
|
|
||||||
controller_index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY)
|
|
||||||
{
|
{
|
||||||
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
|
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
|
||||||
|
|
||||||
@@ -337,7 +167,7 @@ bool Input::checkAnyInput(int device, int controller_index)
|
|||||||
|
|
||||||
if (gameControllerFound())
|
if (gameControllerFound())
|
||||||
{
|
{
|
||||||
if (device == INPUT_USE_GAMECONTROLLER || device == INPUT_USE_ANY)
|
if (device == InputDeviceToUse::CONTROLLER || device == InputDeviceToUse::ANY)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < (int)controller_bindings_.size(); ++i)
|
for (int i = 0; i < (int)controller_bindings_.size(); ++i)
|
||||||
{
|
{
|
||||||
@@ -357,7 +187,7 @@ bool Input::checkAnyInput(int device, int controller_index)
|
|||||||
int Input::checkAnyButtonPressed(bool repeat)
|
int Input::checkAnyButtonPressed(bool repeat)
|
||||||
{
|
{
|
||||||
// Si está pulsado el botón de servicio, ningún botón se puede considerar pulsado
|
// Si está pulsado el botón de servicio, ningún botón se puede considerar pulsado
|
||||||
if (checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_ANY))
|
if (checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::ANY))
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -366,7 +196,7 @@ int Input::checkAnyButtonPressed(bool repeat)
|
|||||||
for (auto bi : button_inputs_)
|
for (auto bi : button_inputs_)
|
||||||
{
|
{
|
||||||
// Comprueba el teclado
|
// Comprueba el teclado
|
||||||
if (checkInput(bi, repeat, INPUT_USE_KEYBOARD))
|
if (checkInput(bi, repeat, InputDeviceToUse::KEYBOARD))
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -374,7 +204,7 @@ int Input::checkAnyButtonPressed(bool repeat)
|
|||||||
// Comprueba los mandos
|
// Comprueba los mandos
|
||||||
for (int i = 0; i < num_gamepads_; ++i)
|
for (int i = 0; i < num_gamepads_; ++i)
|
||||||
{
|
{
|
||||||
if (checkInput(bi, repeat, INPUT_USE_GAMECONTROLLER, i))
|
if (checkInput(bi, repeat, InputDeviceToUse::CONTROLLER, i))
|
||||||
{
|
{
|
||||||
return i + 1;
|
return i + 1;
|
||||||
}
|
}
|
||||||
@@ -395,11 +225,9 @@ bool Input::discoverGameControllers()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (SDL_GameControllerAddMappingsFromFile(game_controller_db_path_.c_str()) < 0)
|
if (SDL_GameControllerAddMappingsFromFile(game_controller_db_path_.c_str()) < 0)
|
||||||
{
|
|
||||||
{
|
{
|
||||||
std::cout << "Error, could not load " << game_controller_db_path_.c_str() << " file: " << SDL_GetError() << std::endl;
|
std::cout << "Error, could not load " << game_controller_db_path_.c_str() << " file: " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
num_joysticks_ = SDL_NumJoysticks();
|
num_joysticks_ = SDL_NumJoysticks();
|
||||||
num_gamepads_ = 0;
|
num_gamepads_ = 0;
|
||||||
@@ -408,7 +236,7 @@ bool Input::discoverGameControllers()
|
|||||||
joysticks_.clear();
|
joysticks_.clear();
|
||||||
for (int i = 0; i < num_joysticks_; ++i)
|
for (int i = 0; i < num_joysticks_; ++i)
|
||||||
{
|
{
|
||||||
SDL_Joystick *joy = SDL_JoystickOpen(i);
|
auto joy = SDL_JoystickOpen(i);
|
||||||
joysticks_.push_back(joy);
|
joysticks_.push_back(joy);
|
||||||
if (SDL_IsGameController(i))
|
if (SDL_IsGameController(i))
|
||||||
{
|
{
|
||||||
@@ -417,7 +245,6 @@ bool Input::discoverGameControllers()
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "\n** LOOKING FOR GAME CONTROLLERS" << std::endl;
|
std::cout << "\n** LOOKING FOR GAME CONTROLLERS" << std::endl;
|
||||||
// std::cout << " " << num_joysticks_ << " joysticks found" << std::endl;
|
|
||||||
std::cout << "Gamepads found: " << num_gamepads_ << std::endl;
|
std::cout << "Gamepads found: " << num_gamepads_ << std::endl;
|
||||||
|
|
||||||
if (num_gamepads_ > 0)
|
if (num_gamepads_ > 0)
|
||||||
@@ -432,44 +259,30 @@ bool Input::discoverGameControllers()
|
|||||||
{
|
{
|
||||||
connected_controllers_.push_back(pad);
|
connected_controllers_.push_back(pad);
|
||||||
const std::string name = SDL_GameControllerNameForIndex(i);
|
const std::string name = SDL_GameControllerNameForIndex(i);
|
||||||
{
|
|
||||||
std::cout << "#" << i << ": " << name << std::endl;
|
std::cout << "#" << i << ": " << name << std::endl;
|
||||||
}
|
|
||||||
controller_names_.push_back(name);
|
controller_names_.push_back(name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
{
|
{
|
||||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
SDL_GameControllerEventState(SDL_ENABLE);
|
SDL_GameControllerEventState(SDL_ENABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "\n** FINISHED LOOKING FOR GAME CONTROLLERS" << std::endl;
|
std::cout << "\n** FINISHED LOOKING FOR GAME CONTROLLERS" << std::endl;
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si hay algun mando conectado
|
// Comprueba si hay algun mando conectado
|
||||||
bool Input::gameControllerFound()
|
bool Input::gameControllerFound() { return num_gamepads_ > 0 ? true : false; }
|
||||||
{
|
|
||||||
return num_gamepads_ > 0 ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obten el nombre de un mando de juego
|
// Obten el nombre de un mando de juego
|
||||||
std::string Input::getControllerName(int controller_index) const
|
std::string Input::getControllerName(int controller_index) const { return num_gamepads_ > 0 ? controller_names_.at(controller_index) : std::string(); }
|
||||||
{
|
|
||||||
return num_gamepads_ > 0 ? controller_names_[controller_index] : "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obten el número de mandos conectados
|
// Obten el número de mandos conectados
|
||||||
int Input::getNumControllers() const
|
int Input::getNumControllers() const { return num_gamepads_; }
|
||||||
{
|
|
||||||
return num_gamepads_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el indice del controlador a partir de un event.id
|
// Obtiene el indice del controlador a partir de un event.id
|
||||||
int Input::getJoyIndex(int id) const
|
int Input::getJoyIndex(int id) const
|
||||||
@@ -485,14 +298,14 @@ int Input::getJoyIndex(int id) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Muestra por consola los controles asignados
|
// Muestra por consola los controles asignados
|
||||||
void Input::printBindings(int device, int controller_index) const
|
void Input::printBindings(InputDeviceToUse device, int controller_index) const
|
||||||
{
|
{
|
||||||
if (device == INPUT_USE_ANY || device == INPUT_USE_KEYBOARD)
|
if (device == InputDeviceToUse::ANY || device == InputDeviceToUse::KEYBOARD)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device == INPUT_USE_GAMECONTROLLER)
|
if (device == InputDeviceToUse::CONTROLLER)
|
||||||
{
|
{
|
||||||
if (controller_index >= num_gamepads_)
|
if (controller_index >= num_gamepads_)
|
||||||
{
|
{
|
||||||
@@ -500,13 +313,12 @@ void Input::printBindings(int device, int controller_index) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Muestra el nombre del mando
|
// Muestra el nombre del mando
|
||||||
std::cout << "\n"
|
std::cout << "\n" + controller_names_.at(controller_index) << std::endl;
|
||||||
<< controller_names_[controller_index] << std::endl;
|
|
||||||
|
|
||||||
// Muestra los botones asignados
|
// Muestra los botones asignados
|
||||||
for (auto bi : button_inputs_)
|
for (auto bi : button_inputs_)
|
||||||
{
|
{
|
||||||
std::cout << to_string(bi) << " : " << controller_bindings_[controller_index][static_cast<int>(bi)].button << std::endl;
|
std::cout << to_string(bi) << " : " << controller_bindings_.at(controller_index).at(static_cast<int>(bi)).button << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -520,116 +332,58 @@ SDL_GameControllerButton Input::getControllerBinding(int controller_index, Input
|
|||||||
// Obtiene el indice a partir del nombre del mando
|
// Obtiene el indice a partir del nombre del mando
|
||||||
int Input::getIndexByName(const std::string &name) const
|
int Input::getIndexByName(const std::string &name) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < num_gamepads_; ++i)
|
auto it = std::find(controller_names_.begin(), controller_names_.end(), name);
|
||||||
{
|
return it != controller_names_.end() ? std::distance(controller_names_.begin(), it) : -1;
|
||||||
if (controller_names_[i] == name)
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convierte un InputType a std::string
|
// Convierte un InputType a std::string
|
||||||
std::string Input::to_string(InputType input) const
|
std::string Input::to_string(InputType input) const
|
||||||
{
|
{
|
||||||
if (input == InputType::FIRE_LEFT)
|
switch (input)
|
||||||
{
|
{
|
||||||
|
case InputType::FIRE_LEFT:
|
||||||
return "input_fire_left";
|
return "input_fire_left";
|
||||||
}
|
case InputType::FIRE_CENTER:
|
||||||
|
|
||||||
if (input == InputType::FIRE_CENTER)
|
|
||||||
{
|
|
||||||
return "input_fire_center";
|
return "input_fire_center";
|
||||||
}
|
case InputType::FIRE_RIGHT:
|
||||||
|
|
||||||
if (input == InputType::FIRE_RIGHT)
|
|
||||||
{
|
|
||||||
return "input_fire_right";
|
return "input_fire_right";
|
||||||
}
|
case InputType::START:
|
||||||
|
|
||||||
if (input == InputType::START)
|
|
||||||
{
|
|
||||||
return "input_start";
|
return "input_start";
|
||||||
}
|
case InputType::SERVICE:
|
||||||
|
|
||||||
if (input == InputType::SERVICE)
|
|
||||||
{
|
|
||||||
return "input_service";
|
return "input_service";
|
||||||
}
|
default:
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Convierte un std::string a InputType
|
// Convierte un std::string a InputType
|
||||||
InputType Input::to_inputs_e(const std::string &name) const
|
InputType Input::to_inputs_e(const std::string &name) const
|
||||||
{
|
{
|
||||||
if (name == "input_fire_left")
|
static const std::unordered_map<std::string, InputType> inputMap = {
|
||||||
{
|
{"input_fire_left", InputType::FIRE_LEFT},
|
||||||
return InputType::FIRE_LEFT;
|
{"input_fire_center", InputType::FIRE_CENTER},
|
||||||
}
|
{"input_fire_right", InputType::FIRE_RIGHT},
|
||||||
|
{"input_start", InputType::START},
|
||||||
|
{"input_service", InputType::SERVICE}};
|
||||||
|
|
||||||
if (name == "input_fire_center")
|
auto it = inputMap.find(name);
|
||||||
{
|
return it != inputMap.end() ? it->second : InputType::NONE;
|
||||||
return InputType::FIRE_CENTER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name == "input_fire_right")
|
|
||||||
{
|
|
||||||
return InputType::FIRE_RIGHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name == "input_start")
|
|
||||||
{
|
|
||||||
return InputType::START;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name == "input_service")
|
|
||||||
{
|
|
||||||
return InputType::SERVICE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return InputType::NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el eje del mando
|
// Comprueba el eje del mando
|
||||||
bool Input::checkAxisInput(InputType input, int controller_index) const
|
bool Input::checkAxisInput(InputType input, int controller_index) const
|
||||||
{
|
{
|
||||||
bool success = false;
|
|
||||||
|
|
||||||
switch (input)
|
switch (input)
|
||||||
{
|
{
|
||||||
case InputType::LEFT:
|
case InputType::LEFT:
|
||||||
if (SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) < -30000)
|
return SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) < -30000;
|
||||||
{
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case InputType::RIGHT:
|
case InputType::RIGHT:
|
||||||
if (SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) > 30000)
|
return SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) > 30000;
|
||||||
{
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case InputType::UP:
|
case InputType::UP:
|
||||||
if (SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) < -30000)
|
return SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) < -30000;
|
||||||
{
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case InputType::DOWN:
|
case InputType::DOWN:
|
||||||
if (SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) > 30000)
|
return SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) > 30000;
|
||||||
{
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
@@ -11,9 +11,9 @@
|
|||||||
connectedControllers es un vector donde estan todos los mandos encontrados [0 .. n]
|
connectedControllers es un vector donde estan todos los mandos encontrados [0 .. n]
|
||||||
checkInput requiere de un indice para comprobar las pulsaciónes de un controlador en concreto [0 .. n]
|
checkInput requiere de un indice para comprobar las pulsaciónes de un controlador en concreto [0 .. n]
|
||||||
device contiene el tipo de dispositivo a comprobar:
|
device contiene el tipo de dispositivo a comprobar:
|
||||||
INPUT_USE_KEYBOARD solo mirará el teclado
|
InputDeviceToUse::KEYBOARD solo mirará el teclado
|
||||||
INPUT_USE_GAMECONTROLLER solo mirará el controlador especificado (Si no se especifica, el primero)
|
InputDeviceToUse::CONTROLLER solo mirará el controlador especificado (Si no se especifica, el primero)
|
||||||
INPUT_USE_ANY mirará tanto el teclado como el PRIMER controlador
|
InputDeviceToUse::ANY mirará tanto el teclado como el PRIMER controlador
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum class InputType : int
|
enum class InputType : int
|
||||||
@@ -52,9 +52,12 @@ enum class InputType : int
|
|||||||
constexpr bool INPUT_ALLOW_REPEAT = true;
|
constexpr bool INPUT_ALLOW_REPEAT = true;
|
||||||
constexpr bool INPUT_DO_NOT_ALLOW_REPEAT = false;
|
constexpr bool INPUT_DO_NOT_ALLOW_REPEAT = false;
|
||||||
|
|
||||||
constexpr int INPUT_USE_KEYBOARD = 0;
|
enum class InputDeviceToUse : int
|
||||||
constexpr int INPUT_USE_GAMECONTROLLER = 1;
|
{
|
||||||
constexpr int INPUT_USE_ANY = 2;
|
KEYBOARD = 0,
|
||||||
|
CONTROLLER = 1,
|
||||||
|
ANY = 2,
|
||||||
|
};
|
||||||
|
|
||||||
class Input
|
class Input
|
||||||
{
|
{
|
||||||
@@ -66,12 +69,20 @@ private:
|
|||||||
{
|
{
|
||||||
Uint8 scancode; // Scancode asociado
|
Uint8 scancode; // Scancode asociado
|
||||||
bool active; // Indica si está activo
|
bool active; // Indica si está activo
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
explicit KeyBindings(Uint8 sc = 0, bool act = false)
|
||||||
|
: scancode(sc), active(act) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ControllerBindings
|
struct ControllerBindings
|
||||||
{
|
{
|
||||||
SDL_GameControllerButton button; // GameControllerButton asociado
|
SDL_GameControllerButton button; // GameControllerButton asociado
|
||||||
bool active; // Indica si está activo
|
bool active; // Indica si está activo
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
explicit ControllerBindings(SDL_GameControllerButton btn = SDL_CONTROLLER_BUTTON_INVALID, bool act = false)
|
||||||
|
: button(btn), active(act) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
@@ -80,12 +91,10 @@ private:
|
|||||||
std::vector<KeyBindings> key_bindings_; // Vector con las teclas asociadas a los inputs predefinidos
|
std::vector<KeyBindings> key_bindings_; // Vector con las teclas asociadas a los inputs predefinidos
|
||||||
std::vector<std::vector<ControllerBindings>> controller_bindings_; // Vector con los botones asociadas a los inputs predefinidos para cada mando
|
std::vector<std::vector<ControllerBindings>> controller_bindings_; // Vector con los botones asociadas a los inputs predefinidos para cada mando
|
||||||
std::vector<std::string> controller_names_; // Vector con los nombres de los mandos
|
std::vector<std::string> controller_names_; // Vector con los nombres de los mandos
|
||||||
std::vector<InputType> game_inputs_; // Inputs usados para jugar, normalmente direcciones y botones
|
|
||||||
std::vector<InputType> button_inputs_; // Inputs asignados al jugador y a botones, excluyendo direcciones
|
std::vector<InputType> button_inputs_; // Inputs asignados al jugador y a botones, excluyendo direcciones
|
||||||
int num_joysticks_; // Número de joysticks conectados
|
int num_joysticks_ = 0; // Número de joysticks conectados
|
||||||
int num_gamepads_; // Número de mandos conectados
|
int num_gamepads_ = 0; // Número de mandos conectados
|
||||||
std::string game_controller_db_path_; // Ruta al archivo gamecontrollerdb.txt
|
std::string game_controller_db_path_; // Ruta al archivo gamecontrollerdb.txt
|
||||||
bool enabled_; // Indica si está habilitado
|
|
||||||
|
|
||||||
// Comprueba el eje del mando
|
// Comprueba el eje del mando
|
||||||
bool checkAxisInput(InputType input, int controller_index = 0) const;
|
bool checkAxisInput(InputType input, int controller_index = 0) const;
|
||||||
@@ -114,13 +123,10 @@ public:
|
|||||||
void bindGameControllerButton(int controller_index, InputType inputTarget, InputType inputSource);
|
void bindGameControllerButton(int controller_index, InputType inputTarget, InputType inputSource);
|
||||||
|
|
||||||
// Comprueba si un input esta activo
|
// Comprueba si un input esta activo
|
||||||
bool checkInput(InputType input, bool repeat = true, int device = INPUT_USE_ANY, int controller_index = 0);
|
bool checkInput(InputType input, bool repeat = true, InputDeviceToUse device = InputDeviceToUse::ANY, int controller_index = 0);
|
||||||
|
|
||||||
// Comprueba si un input con modificador esta activo
|
|
||||||
bool checkModInput(InputType input_mod, InputType input, bool repeat = true, int device = INPUT_USE_ANY, int controller_index = 0);
|
|
||||||
|
|
||||||
// Comprueba si hay almenos un input activo
|
// Comprueba si hay almenos un input activo
|
||||||
bool checkAnyInput(int device = INPUT_USE_ANY, int controller_index = 0);
|
bool checkAnyInput(InputDeviceToUse device = InputDeviceToUse::ANY, int controller_index = 0);
|
||||||
|
|
||||||
// Comprueba si hay algún botón pulsado
|
// Comprueba si hay algún botón pulsado
|
||||||
int checkAnyButtonPressed(bool repeat = INPUT_DO_NOT_ALLOW_REPEAT);
|
int checkAnyButtonPressed(bool repeat = INPUT_DO_NOT_ALLOW_REPEAT);
|
||||||
@@ -141,7 +147,7 @@ public:
|
|||||||
int getJoyIndex(int id) const;
|
int getJoyIndex(int id) const;
|
||||||
|
|
||||||
// Muestra por consola los controles asignados
|
// Muestra por consola los controles asignados
|
||||||
void printBindings(int device = INPUT_USE_KEYBOARD, int controller_index = 0) const;
|
void printBindings(InputDeviceToUse device = InputDeviceToUse::KEYBOARD, int controller_index = 0) const;
|
||||||
|
|
||||||
// Obtiene el SDL_GameControllerButton asignado a un input
|
// Obtiene el SDL_GameControllerButton asignado a un input
|
||||||
SDL_GameControllerButton getControllerBinding(int controller_index, InputType input) const;
|
SDL_GameControllerButton getControllerBinding(int controller_index, InputType input) const;
|
||||||
|
|||||||
@@ -313,9 +313,6 @@ void Instructions::checkInput()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input para el resto de objetos
|
|
||||||
Screen::get()->checkInput();
|
|
||||||
|
|
||||||
// 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
|
||||||
globalInputs::check();
|
globalInputs::check();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,9 +191,6 @@ void Intro::checkInput()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input para el resto de objetos
|
|
||||||
Screen::get()->checkInput();
|
|
||||||
|
|
||||||
// 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
|
||||||
globalInputs::check();
|
globalInputs::check();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "section.h" // Para Name, name, Options, options
|
#include "section.h" // Para Name, name, Options, options
|
||||||
#include "sprite.h" // Para Sprite
|
#include "sprite.h" // Para Sprite
|
||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
|
#include "utils.h" // Para Color, Zone
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo::Logo()
|
Logo::Logo()
|
||||||
@@ -105,9 +106,6 @@ void Logo::checkInput()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input para el resto de objetos
|
|
||||||
Screen::get()->checkInput();
|
|
||||||
|
|
||||||
// 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
|
||||||
globalInputs::check();
|
globalInputs::check();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // para SDL_Point
|
#include <SDL2/SDL_rect.h> // Para SDL_Point
|
||||||
#include <SDL2/SDL_stdinc.h> // para Uint32
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
#include <memory> // para unique_ptr, shared_ptr
|
#include <memory> // Para shared_ptr, unique_ptr
|
||||||
#include <vector> // para vector
|
#include <vector> // Para vector
|
||||||
#include "sprite.h" // para Sprite
|
class Sprite;
|
||||||
#include "utils.h" // para Color
|
class Texture; // lines 9-9
|
||||||
class Texture;
|
struct Color;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Esta clase gestiona un estado del programa. Se encarga de dibujar por pantalla el
|
Esta clase gestiona un estado del programa. Se encarga de dibujar por pantalla el
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||||
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||||
#include <string> // Para string
|
#include <string> // Para string
|
||||||
|
#include <algorithm>
|
||||||
|
#include <vector>
|
||||||
#include "jail_audio.h" // Para JA_DeleteSound, JA_LoadSound, JA_Pla...
|
#include "jail_audio.h" // Para JA_DeleteSound, JA_LoadSound, JA_Pla...
|
||||||
#include "param.h" // Para Param, param, ParamNotification, Par...
|
#include "param.h" // Para Param, param, ParamNotification, Par...
|
||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
@@ -51,8 +53,10 @@ Notifier::~Notifier()
|
|||||||
void Notifier::render()
|
void Notifier::render()
|
||||||
{
|
{
|
||||||
for (int i = (int)notifications_.size() - 1; i >= 0; --i)
|
for (int i = (int)notifications_.size() - 1; i >= 0; --i)
|
||||||
|
{
|
||||||
notifications_[i].sprite->render();
|
notifications_[i].sprite->render();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Actualiza el estado de las notificaiones
|
// Actualiza el estado de las notificaiones
|
||||||
void Notifier::update()
|
void Notifier::update()
|
||||||
@@ -154,39 +158,41 @@ void Notifier::clearFinishedNotifications()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notifier::showText(std::string text1, std::string text2, int icon, const std::string &code)
|
void Notifier::showText(std::vector<std::string> texts, int icon, const std::string &code)
|
||||||
{
|
{
|
||||||
// Cuenta el número de textos a mostrar
|
|
||||||
const int num_texts = !text1.empty() + !text2.empty();
|
|
||||||
|
|
||||||
// Si no hay texto, acaba
|
// Si no hay texto, acaba
|
||||||
if (num_texts == 0)
|
if (texts.empty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si solo hay un texto, lo coloca en la primera variable
|
|
||||||
if (num_texts == 1)
|
|
||||||
{
|
|
||||||
text1 += text2;
|
|
||||||
text2.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si las notificaciones no se apilan, elimina las anteriores
|
// Si las notificaciones no se apilan, elimina las anteriores
|
||||||
if (!stack_)
|
if (!stack_)
|
||||||
{
|
{
|
||||||
clearNotifications();
|
clearNotifications();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Elimina las cadenas vacías
|
||||||
|
texts.erase(std::remove_if(texts.begin(), texts.end(), [](const std::string &s)
|
||||||
|
{ return s.empty(); }),
|
||||||
|
texts.end());
|
||||||
|
|
||||||
|
// Encuentra la cadena más larga
|
||||||
|
std::string longest;
|
||||||
|
for (const auto &text : texts)
|
||||||
|
{
|
||||||
|
if (text.length() > longest.length())
|
||||||
|
longest = text;
|
||||||
|
}
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
constexpr auto icon_size = 16;
|
constexpr int icon_size = 16;
|
||||||
constexpr auto padding_out = 1;
|
constexpr int padding_out = 1;
|
||||||
const auto padding_in_h = text_->getCharacterSize();
|
const auto padding_in_h = text_->getCharacterSize();
|
||||||
const auto padding_in_v = text_->getCharacterSize() / 2;
|
const auto padding_in_v = text_->getCharacterSize() / 2;
|
||||||
const auto icon_space = icon >= 0 ? icon_size + padding_in_h : 0;
|
const int icon_space = icon >= 0 ? icon_size + padding_in_h : 0;
|
||||||
const std::string txt = text1.length() > text2.length() ? text1 : text2;
|
const int width = text_->lenght(longest) + (padding_in_h * 2) + icon_space;
|
||||||
const auto width = text_->lenght(txt) + (padding_in_h * 2) + icon_space;
|
const int height = (text_->getCharacterSize() * texts.size()) + (padding_in_v * 2);
|
||||||
const auto height = (text_->getCharacterSize() * num_texts) + (padding_in_v * 2);
|
|
||||||
const auto shape = NotificationShape::SQUARED;
|
const auto shape = NotificationShape::SQUARED;
|
||||||
|
|
||||||
// Posición horizontal
|
// Posición horizontal
|
||||||
@@ -212,11 +218,11 @@ void Notifier::showText(std::string text1, std::string text2, int icon, const st
|
|||||||
auto offset = 0;
|
auto offset = 0;
|
||||||
if (param.notification.pos_v == NotifyPosition::TOP)
|
if (param.notification.pos_v == NotifyPosition::TOP)
|
||||||
{
|
{
|
||||||
offset = (int)notifications_.size() > 0 ? notifications_.back().y + travel_dist : desp_v;
|
offset = !notifications_.empty() ? notifications_.back().y + travel_dist : desp_v;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
offset = (int)notifications_.size() > 0 ? notifications_.back().y - travel_dist : desp_v;
|
offset = !notifications_.empty() ? notifications_.back().y - travel_dist : desp_v;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea la notificacion
|
// Crea la notificacion
|
||||||
@@ -226,8 +232,7 @@ void Notifier::showText(std::string text1, std::string text2, int icon, const st
|
|||||||
n.code = code;
|
n.code = code;
|
||||||
n.y = offset;
|
n.y = offset;
|
||||||
n.travel_dist = travel_dist;
|
n.travel_dist = travel_dist;
|
||||||
n.text1 = text1;
|
n.texts = texts;
|
||||||
n.text2 = text2;
|
|
||||||
n.shape = shape;
|
n.shape = shape;
|
||||||
auto y_pos = offset + (param.notification.pos_v == NotifyPosition::TOP ? -travel_dist : travel_dist);
|
auto y_pos = offset + (param.notification.pos_v == NotifyPosition::TOP ? -travel_dist : travel_dist);
|
||||||
n.rect = {desp_h, y_pos, width, height};
|
n.rect = {desp_h, y_pos, width, height};
|
||||||
@@ -264,7 +269,7 @@ void Notifier::showText(std::string text1, std::string text2, int icon, const st
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja el icono de la notificación
|
// Dibuja el icono de la notificación
|
||||||
if (has_icons_ && icon >= 0 && num_texts == 2)
|
if (has_icons_ && icon >= 0 && texts.size() >= 2)
|
||||||
{
|
{
|
||||||
auto sp = std::make_unique<Sprite>(icon_texture_, (SDL_Rect){0, 0, icon_size, icon_size});
|
auto sp = std::make_unique<Sprite>(icon_texture_, (SDL_Rect){0, 0, icon_size, icon_size});
|
||||||
sp->setPosition({padding_in_h, padding_in_v, icon_size, icon_size});
|
sp->setPosition({padding_in_h, padding_in_v, icon_size, icon_size});
|
||||||
@@ -273,15 +278,12 @@ void Notifier::showText(std::string text1, std::string text2, int icon, const st
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Escribe el texto de la notificación
|
// Escribe el texto de la notificación
|
||||||
Color color{255, 255, 255};
|
const Color color{255, 255, 255};
|
||||||
if (num_texts == 2)
|
int iterator = 0;
|
||||||
{ // Dos lineas de texto
|
for (const auto &text : texts)
|
||||||
text_->writeColored(padding_in_h + icon_space, padding_in_v, text1, color);
|
{
|
||||||
text_->writeColored(padding_in_h + icon_space, padding_in_v + text_->getCharacterSize() + 1, text2, color);
|
text_->writeColored(padding_in_h + icon_space, padding_in_v + iterator * (text_->getCharacterSize() + 1), text, color);
|
||||||
}
|
++iterator;
|
||||||
else
|
|
||||||
{ // Una linea de texto
|
|
||||||
text_->writeColored(padding_in_h + icon_space, padding_in_v, text1, color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deja de dibujar en la textura
|
// Deja de dibujar en la textura
|
||||||
@@ -294,26 +296,18 @@ void Notifier::showText(std::string text1, std::string text2, int icon, const st
|
|||||||
n.texture->setAlpha(0);
|
n.texture->setAlpha(0);
|
||||||
|
|
||||||
// Añade la notificación a la lista
|
// Añade la notificación a la lista
|
||||||
notifications_.push_back(n);
|
notifications_.emplace_back(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indica si hay notificaciones activas
|
// Indica si hay notificaciones activas
|
||||||
bool Notifier::isActive()
|
bool Notifier::isActive() { return !notifications_.empty(); }
|
||||||
{
|
|
||||||
if ((int)notifications_.size() > 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finaliza y elimnina todas las notificaciones activas
|
// Finaliza y elimnina todas las notificaciones activas
|
||||||
void Notifier::clearNotifications()
|
void Notifier::clearNotifications()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < (int)notifications_.size(); ++i)
|
for (auto ¬ification : notifications_)
|
||||||
{
|
{
|
||||||
notifications_[i].status = NotificationStatus::FINISHED;
|
notification.status = NotificationStatus::FINISHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearFinishedNotifications();
|
clearFinishedNotifications();
|
||||||
@@ -323,9 +317,9 @@ void Notifier::clearNotifications()
|
|||||||
std::vector<std::string> Notifier::getCodes()
|
std::vector<std::string> Notifier::getCodes()
|
||||||
{
|
{
|
||||||
std::vector<std::string> codes;
|
std::vector<std::string> codes;
|
||||||
for (int i = 0; i < (int)notifications_.size(); ++i)
|
for (const auto ¬ification : notifications_)
|
||||||
{
|
{
|
||||||
codes.push_back(notifications_[i].code);
|
codes.emplace_back(notification.code);
|
||||||
}
|
}
|
||||||
return codes;
|
return codes;
|
||||||
}
|
}
|
||||||
@@ -35,8 +35,7 @@ private:
|
|||||||
{
|
{
|
||||||
std::shared_ptr<Texture> texture;
|
std::shared_ptr<Texture> texture;
|
||||||
std::shared_ptr<Sprite> sprite;
|
std::shared_ptr<Sprite> sprite;
|
||||||
std::string text1;
|
std::vector<std::string> texts;
|
||||||
std::string text2;
|
|
||||||
int counter;
|
int counter;
|
||||||
NotificationStatus status;
|
NotificationStatus status;
|
||||||
NotificationShape shape;
|
NotificationShape shape;
|
||||||
@@ -47,7 +46,7 @@ private:
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit Notification()
|
explicit Notification()
|
||||||
: texture(nullptr), sprite(nullptr), text1(""), text2(""), counter(0), status(NotificationStatus::RISING),
|
: texture(nullptr), sprite(nullptr), texts(), counter(0), status(NotificationStatus::RISING),
|
||||||
shape(NotificationShape::SQUARED), rect{0, 0, 0, 0}, y(0), travel_dist(0), code("") {}
|
shape(NotificationShape::SQUARED), rect{0, 0, 0, 0}, y(0), travel_dist(0), code("") {}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -95,15 +94,8 @@ public:
|
|||||||
// Actualiza el estado de las notificaiones
|
// Actualiza el estado de las notificaiones
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
/**
|
// Muestra una notificación de texto por pantalla
|
||||||
* @brief Muestra una notificación de texto por pantalla.
|
void showText(std::vector<std::string> texts, int icon = -1, const std::string &code = std::string());
|
||||||
*
|
|
||||||
* @param text1 Primer texto opcional para mostrar (valor predeterminado: cadena vacía).
|
|
||||||
* @param text2 Segundo texto opcional para mostrar (valor predeterminado: cadena vacía).
|
|
||||||
* @param icon Icono opcional para mostrar (valor predeterminado: -1).
|
|
||||||
* @param code Permite asignar un código a la notificación (valor predeterminado: cadena vacía).
|
|
||||||
*/
|
|
||||||
void showText(std::string text1 = std::string(), std::string text2 = std::string(), int icon = -1, const std::string &code = std::string());
|
|
||||||
|
|
||||||
// Indica si hay notificaciones activas
|
// Indica si hay notificaciones activas
|
||||||
bool isActive();
|
bool isActive();
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include <SDL2/SDL_gamecontroller.h> // para SDL_GameControllerButton, SDL_C...
|
#include <SDL2/SDL_gamecontroller.h> // Para SDL_GameControllerButton
|
||||||
#include <algorithm> // para max, min
|
#include <algorithm> // Para clamp
|
||||||
#include <fstream> // para basic_ostream, operator<<, basi...
|
#include <fstream> // Para basic_ostream, operator<<, basi...
|
||||||
#include <iostream> // para cout
|
#include <iostream> // Para cout
|
||||||
#include <vector> // para vector
|
#include <utility> // Para swap
|
||||||
#include "input.h" // para inputs_e, INPUT_USE_ANY, INPUT_...
|
#include <vector> // Para vector
|
||||||
#include "lang.h" // para lang_e
|
#include "input.h" // Para InputDeviceToUse
|
||||||
#include "screen.h" // para ScreenVideoMode, ScreenFilter
|
#include "lang.h" // Para Code
|
||||||
#include "utils.h" // para OptionsController, Options, op_...
|
#include "screen.h" // Para ScreenVideoMode, ScreenFilter
|
||||||
|
#include "utils.h" // Para boolToString, stringToBool, get...
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
Options options;
|
Options options;
|
||||||
@@ -45,37 +46,11 @@ void initOptions()
|
|||||||
options.game.autofire = true;
|
options.game.autofire = true;
|
||||||
|
|
||||||
// Opciones de control
|
// Opciones de control
|
||||||
options.controller.clear();
|
options.controllers.clear();
|
||||||
OptionsController c;
|
options.controllers.resize(2);
|
||||||
|
options.controllers.at(0).player_id = 1;
|
||||||
constexpr int num_players = 2;
|
options.controllers.at(1).player_id = 2;
|
||||||
for (int index = 0; index < num_players; ++index)
|
setKeyboardToPlayer(1);
|
||||||
{
|
|
||||||
c.index = index;
|
|
||||||
c.player_id = index + 1;
|
|
||||||
c.device_type = INPUT_USE_GAMECONTROLLER;
|
|
||||||
c.name = "NO NAME";
|
|
||||||
c.plugged = false;
|
|
||||||
|
|
||||||
// Inputs que se guardan en las opciones y, por tanto, a disco
|
|
||||||
c.inputs.clear();
|
|
||||||
c.inputs.push_back(InputType::FIRE_LEFT);
|
|
||||||
c.inputs.push_back(InputType::FIRE_CENTER);
|
|
||||||
c.inputs.push_back(InputType::FIRE_RIGHT);
|
|
||||||
c.inputs.push_back(InputType::START);
|
|
||||||
c.inputs.push_back(InputType::SERVICE);
|
|
||||||
|
|
||||||
// Botones asociados a los inputs anteriores
|
|
||||||
c.buttons.clear();
|
|
||||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_X);
|
|
||||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_Y);
|
|
||||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_B);
|
|
||||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_START);
|
|
||||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_BACK);
|
|
||||||
|
|
||||||
options.controller.push_back(c);
|
|
||||||
}
|
|
||||||
options.controller[0].device_type = INPUT_USE_ANY; // El primer jugador puede usar tanto el teclado como el primer mando
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga el fichero de configuración
|
// Carga el fichero de configuración
|
||||||
@@ -129,12 +104,11 @@ bool loadOptionsFile(std::string file_path)
|
|||||||
options.video.mode = ScreenVideoMode::WINDOW;
|
options.video.mode = ScreenVideoMode::WINDOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.video.window.size < 1 || options.video.window.size > 4)
|
options.video.window.size = std::clamp(options.video.window.size, 1, 4);
|
||||||
{
|
|
||||||
options.video.window.size = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.game.language != lang::Code::en_UK && options.game.language != lang::Code::ba_BA && options.game.language != lang::Code::es_ES)
|
if (options.game.language != lang::Code::en_UK &&
|
||||||
|
options.game.language != lang::Code::ba_BA &&
|
||||||
|
options.game.language != lang::Code::es_ES)
|
||||||
{
|
{
|
||||||
options.game.language = lang::Code::en_UK;
|
options.game.language = lang::Code::en_UK;
|
||||||
}
|
}
|
||||||
@@ -156,73 +130,58 @@ bool saveOptionsFile(std::string file_path)
|
|||||||
std::cout << "Writing file: " << getFileName(file_path) << std::endl;
|
std::cout << "Writing file: " << getFileName(file_path) << std::endl;
|
||||||
|
|
||||||
// Opciones de video
|
// Opciones de video
|
||||||
const auto value_video_mode_winow = std::to_string(static_cast<int>(ScreenVideoMode::WINDOW));
|
|
||||||
const auto value_video_mode_fullscreen = std::to_string(static_cast<int>(ScreenVideoMode::FULLSCREEN));
|
|
||||||
const auto value_filter_nearest = std::to_string(static_cast<int>(ScreenFilter::NEAREST));
|
|
||||||
const auto value_filter_lineal = std::to_string(static_cast<int>(ScreenFilter::LINEAL));
|
|
||||||
|
|
||||||
file << "## VIDEO\n";
|
file << "## VIDEO\n";
|
||||||
file << "## video.mode [" << value_video_mode_winow << ": window, " << value_video_mode_fullscreen << ": fullscreen]\n";
|
file << "## video.mode [" << static_cast<int>(ScreenVideoMode::WINDOW) << ": window, " << static_cast<int>(ScreenVideoMode::FULLSCREEN) << ": fullscreen]\n";
|
||||||
file << "## video.filter [" << value_filter_nearest << ": nearest, " << value_filter_lineal << ": lineal]\n";
|
file << "## video.filter [" << static_cast<int>(ScreenFilter::NEAREST) << ": nearest, " << static_cast<int>(ScreenFilter::LINEAL) << ": lineal]\n";
|
||||||
file << "\n";
|
file << "\n";
|
||||||
|
|
||||||
const auto valueVideoMode = std::to_string(static_cast<int>(options.video.mode));
|
file << "video.mode=" << static_cast<int>(options.video.mode) << "\n";
|
||||||
file << "video.mode=" << valueVideoMode << "\n";
|
file << "video.window.size=" << options.video.window.size << "\n";
|
||||||
|
file << "video.filter=" << static_cast<int>(options.video.filter) << "\n";
|
||||||
file << "video.window.size=" + std::to_string(options.video.window.size) + "\n";
|
file << "video.v_sync=" << boolToString(options.video.v_sync) << "\n";
|
||||||
|
file << "video.integer_scale=" << boolToString(options.video.integer_scale) << "\n";
|
||||||
const auto valueFilter = std::to_string(static_cast<int>(options.video.filter));
|
file << "video.shaders=" << boolToString(options.video.shaders) << "\n";
|
||||||
file << "video.filter=" << valueFilter << "\n";
|
|
||||||
|
|
||||||
file << "video.v_sync=" + boolToString(options.video.v_sync) + "\n";
|
|
||||||
file << "video.integer_scale=" + boolToString(options.video.integer_scale) + "\n";
|
|
||||||
file << "video.shaders=" + boolToString(options.video.shaders) + "\n";
|
|
||||||
|
|
||||||
// Opciones de audio
|
// Opciones de audio
|
||||||
file << "\n\n## AUDIO\n";
|
file << "\n\n## AUDIO\n";
|
||||||
file << "## volume [0 .. 100]\n";
|
file << "## volume [0 .. 100]\n";
|
||||||
file << "\n";
|
file << "\n";
|
||||||
|
|
||||||
file << "audio.enabled=" + boolToString(options.audio.enabled) + "\n";
|
file << "audio.enabled=" << boolToString(options.audio.enabled) << "\n";
|
||||||
file << "audio.volume=" + std::to_string(options.audio.volume) + "\n";
|
file << "audio.volume=" << options.audio.volume << "\n";
|
||||||
file << "audio.music.enabled=" + boolToString(options.audio.music.enabled) + "\n";
|
file << "audio.music.enabled=" << boolToString(options.audio.music.enabled) << "\n";
|
||||||
file << "audio.music.volume=" + std::to_string(options.audio.music.volume) + "\n";
|
file << "audio.music.volume=" << options.audio.music.volume << "\n";
|
||||||
file << "audio.sound.enabled=" + boolToString(options.audio.sound.enabled) + "\n";
|
file << "audio.sound.enabled=" << boolToString(options.audio.sound.enabled) << "\n";
|
||||||
file << "audio.sound.volume=" + std::to_string(options.audio.sound.volume) + "\n";
|
file << "audio.sound.volume=" << options.audio.sound.volume << "\n";
|
||||||
|
|
||||||
// Opciones del juego
|
// Opciones del juego
|
||||||
const auto value_difficulty_easy = std::to_string(static_cast<int>(GameDifficulty::EASY));
|
|
||||||
const auto value_difficulty_normal = std::to_string(static_cast<int>(GameDifficulty::NORMAL));
|
|
||||||
const auto value_difficulty_hard = std::to_string(static_cast<int>(GameDifficulty::HARD));
|
|
||||||
file << "\n\n## GAME\n";
|
file << "\n\n## GAME\n";
|
||||||
file << "## game.language [0: spanish, 1: valencian, 2: english]\n";
|
file << "## game.language [0: spanish, 1: valencian, 2: english]\n";
|
||||||
file << "## game.difficulty [" << value_difficulty_easy << ": easy, " << value_difficulty_normal << ": normal, " << value_difficulty_hard << ": hard]\n";
|
file << "## game.difficulty [" << static_cast<int>(GameDifficulty::EASY) << ": easy, " << static_cast<int>(GameDifficulty::NORMAL) << ": normal, " << static_cast<int>(GameDifficulty::HARD) << ": hard]\n";
|
||||||
file << "\n";
|
file << "\n";
|
||||||
|
|
||||||
file << "game.language=" + std::to_string(static_cast<int>(options.game.language)) + "\n";
|
file << "game.language=" << static_cast<int>(options.game.language) << "\n";
|
||||||
file << "game.difficulty=" + std::to_string(static_cast<int>(options.game.difficulty)) + "\n";
|
file << "game.difficulty=" << static_cast<int>(options.game.difficulty) << "\n";
|
||||||
file << "game.autofire=" + boolToString(options.game.autofire) + "\n";
|
file << "game.autofire=" << boolToString(options.game.autofire) << "\n";
|
||||||
|
|
||||||
// Opciones de mandos
|
// Opciones de mandos
|
||||||
file << "\n\n## CONTROLLERS\n";
|
file << "\n\n## CONTROLLERS\n";
|
||||||
file << "\n";
|
|
||||||
|
|
||||||
const int num_players = 2;
|
int controller_index = 0;
|
||||||
for (int index = 0; index < num_players; ++index)
|
for (const auto &controller : options.controllers)
|
||||||
{
|
|
||||||
const std::string joyIndex = std::to_string(index + 1);
|
|
||||||
file << "controller" + joyIndex + ".name=" + options.controller[index].name + "\n";
|
|
||||||
file << "controller" + joyIndex + ".player=" + std::to_string(options.controller[index].player_id) + "\n";
|
|
||||||
file << "controller" + joyIndex + ".button.fire_left=" + std::to_string((int)options.controller[index].buttons[0]) + "\n";
|
|
||||||
file << "controller" + joyIndex + ".button.fire_center=" + std::to_string((int)options.controller[index].buttons[1]) + "\n";
|
|
||||||
file << "controller" + joyIndex + ".button.fire_right=" + std::to_string((int)options.controller[index].buttons[2]) + "\n";
|
|
||||||
file << "controller" + joyIndex + ".button.start=" + std::to_string((int)options.controller[index].buttons[3]) + "\n";
|
|
||||||
file << "controller" + joyIndex + ".button.service=" + std::to_string((int)options.controller[index].buttons[4]) + "\n";
|
|
||||||
|
|
||||||
if (index < num_players - 1)
|
|
||||||
{
|
{
|
||||||
file << "\n";
|
file << "\n";
|
||||||
}
|
file << "controller." << controller_index << ".name=" << controller.name << "\n";
|
||||||
|
file << "controller." << controller_index << ".player=" << controller.player_id << "\n";
|
||||||
|
file << "controller." << controller_index << ".type=" << static_cast<int>(controller.type) << "\n";
|
||||||
|
file << "controller." << controller_index << ".button.fire_left=" << controller.buttons.at(0) << "\n";
|
||||||
|
file << "controller." << controller_index << ".button.fire_center=" << controller.buttons.at(1) << "\n";
|
||||||
|
file << "controller." << controller_index << ".button.fire_right=" << controller.buttons.at(2) << "\n";
|
||||||
|
file << "controller." << controller_index << ".button.start=" << controller.buttons.at(3) << "\n";
|
||||||
|
file << "controller." << controller_index << ".button.service=" << controller.buttons.at(4) << "\n";
|
||||||
|
|
||||||
|
// Incrementa el índice
|
||||||
|
++controller_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
@@ -242,7 +201,6 @@ bool setOptions(const std::string &var, const std::string &value)
|
|||||||
{
|
{
|
||||||
options.video.mode = static_cast<ScreenVideoMode>(std::stoi(value));
|
options.video.mode = static_cast<ScreenVideoMode>(std::stoi(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "video.window.size")
|
else if (var == "video.window.size")
|
||||||
{
|
{
|
||||||
options.video.window.size = std::stoi(value);
|
options.video.window.size = std::stoi(value);
|
||||||
@@ -251,22 +209,18 @@ bool setOptions(const std::string &var, const std::string &value)
|
|||||||
options.video.window.size = 3;
|
options.video.window.size = 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "video.filter")
|
else if (var == "video.filter")
|
||||||
{
|
{
|
||||||
options.video.filter = static_cast<ScreenFilter>(std::stoi(value));
|
options.video.filter = static_cast<ScreenFilter>(std::stoi(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "video.shaders")
|
else if (var == "video.shaders")
|
||||||
{
|
{
|
||||||
options.video.shaders = stringToBool(value);
|
options.video.shaders = stringToBool(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "video.integer_scale")
|
else if (var == "video.integer_scale")
|
||||||
{
|
{
|
||||||
options.video.integer_scale = stringToBool(value);
|
options.video.integer_scale = stringToBool(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "video.v_sync")
|
else if (var == "video.v_sync")
|
||||||
{
|
{
|
||||||
options.video.v_sync = stringToBool(value);
|
options.video.v_sync = stringToBool(value);
|
||||||
@@ -277,7 +231,6 @@ bool setOptions(const std::string &var, const std::string &value)
|
|||||||
{
|
{
|
||||||
options.audio.enabled = stringToBool(value);
|
options.audio.enabled = stringToBool(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "audio.volume")
|
else if (var == "audio.volume")
|
||||||
{
|
{
|
||||||
options.audio.volume = std::stoi(value);
|
options.audio.volume = std::stoi(value);
|
||||||
@@ -286,17 +239,14 @@ bool setOptions(const std::string &var, const std::string &value)
|
|||||||
{
|
{
|
||||||
options.audio.music.enabled = stringToBool(value);
|
options.audio.music.enabled = stringToBool(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "audio.music.volume")
|
else if (var == "audio.music.volume")
|
||||||
{
|
{
|
||||||
options.audio.music.volume = std::stoi(value);
|
options.audio.music.volume = std::stoi(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "audio.sound.enabled")
|
else if (var == "audio.sound.enabled")
|
||||||
{
|
{
|
||||||
options.audio.sound.enabled = stringToBool(value);
|
options.audio.sound.enabled = stringToBool(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "audio.sound.volume")
|
else if (var == "audio.sound.volume")
|
||||||
{
|
{
|
||||||
options.audio.sound.volume = std::stoi(value);
|
options.audio.sound.volume = std::stoi(value);
|
||||||
@@ -307,93 +257,85 @@ bool setOptions(const std::string &var, const std::string &value)
|
|||||||
{
|
{
|
||||||
options.game.language = static_cast<lang::Code>(std::stoi(value));
|
options.game.language = static_cast<lang::Code>(std::stoi(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "game.difficulty")
|
else if (var == "game.difficulty")
|
||||||
{
|
{
|
||||||
options.game.difficulty = static_cast<GameDifficulty>(std::stoi(value));
|
options.game.difficulty = static_cast<GameDifficulty>(std::stoi(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "game.autofire")
|
else if (var == "game.autofire")
|
||||||
{
|
{
|
||||||
options.game.autofire = stringToBool(value);
|
options.game.autofire = stringToBool(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opciones de mandos
|
// Opciones de mandos
|
||||||
else if (var == "controller1.name")
|
else if (var == "controller.0.name")
|
||||||
{
|
{
|
||||||
options.controller[0].name = value;
|
options.controllers.at(0).name = value;
|
||||||
}
|
}
|
||||||
|
else if (var == "controller.0.player")
|
||||||
else if (var == "controller1.player")
|
|
||||||
{
|
{
|
||||||
options.controller[0].player_id = std::max(1, std::min(2, std::stoi(value)));
|
options.controllers.at(0).player_id = std::clamp(std::stoi(value), 1, 2);
|
||||||
}
|
}
|
||||||
|
else if (var == "controller.0.type")
|
||||||
else if (var == "controller1.button.fire_left")
|
|
||||||
{
|
{
|
||||||
options.controller[0].buttons[0] = (SDL_GameControllerButton)std::stoi(value);
|
options.controllers.at(0).type = static_cast<InputDeviceToUse>(std::stoi(value));
|
||||||
}
|
}
|
||||||
|
else if (var == "controller.0.button.fire_left")
|
||||||
else if (var == "controller1.button.fire_center")
|
|
||||||
{
|
{
|
||||||
options.controller[0].buttons[1] = (SDL_GameControllerButton)std::stoi(value);
|
options.controllers.at(0).buttons.at(0) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||||
}
|
}
|
||||||
|
else if (var == "controller.0.button.fire_center")
|
||||||
else if (var == "controller1.button.fire_right")
|
|
||||||
{
|
{
|
||||||
options.controller[0].buttons[2] = (SDL_GameControllerButton)std::stoi(value);
|
options.controllers.at(0).buttons.at(1) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||||
}
|
}
|
||||||
|
else if (var == "controller.0.button.fire_right")
|
||||||
else if (var == "controller1.button.start")
|
|
||||||
{
|
{
|
||||||
options.controller[0].buttons[3] = (SDL_GameControllerButton)std::stoi(value);
|
options.controllers.at(0).buttons.at(2) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||||
}
|
}
|
||||||
|
else if (var == "controller.0.button.start")
|
||||||
else if (var == "controller1.button.service")
|
|
||||||
{
|
{
|
||||||
options.controller[0].buttons[4] = (SDL_GameControllerButton)std::stoi(value);
|
options.controllers.at(0).buttons.at(3) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||||
}
|
}
|
||||||
|
else if (var == "controller.0.button.service")
|
||||||
else if (var == "controller2.name")
|
|
||||||
{
|
{
|
||||||
options.controller[1].name = value;
|
options.controllers.at(0).buttons.at(4) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||||
}
|
}
|
||||||
|
else if (var == "controller.1.name")
|
||||||
else if (var == "controller2.player")
|
|
||||||
{
|
{
|
||||||
options.controller[1].player_id = std::max(1, std::min(2, std::stoi(value)));
|
options.controllers.at(1).name = value;
|
||||||
}
|
}
|
||||||
|
else if (var == "controller.1.player")
|
||||||
else if (var == "controller2.button.fire_left")
|
|
||||||
{
|
{
|
||||||
options.controller[1].buttons[0] = (SDL_GameControllerButton)std::stoi(value);
|
options.controllers.at(1).player_id = std::clamp(std::stoi(value), 1, 2);
|
||||||
}
|
}
|
||||||
|
else if (var == "controller.1.type")
|
||||||
else if (var == "controller2.button.fire_center")
|
|
||||||
{
|
{
|
||||||
options.controller[1].buttons[1] = (SDL_GameControllerButton)std::stoi(value);
|
options.controllers.at(1).type = static_cast<InputDeviceToUse>(std::stoi(value));
|
||||||
}
|
}
|
||||||
|
else if (var == "controller.1.button.fire_left")
|
||||||
else if (var == "controller2.button.fire_right")
|
|
||||||
{
|
{
|
||||||
options.controller[1].buttons[2] = (SDL_GameControllerButton)std::stoi(value);
|
options.controllers.at(1).buttons.at(0) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||||
}
|
}
|
||||||
|
else if (var == "controller.1.button.fire_center")
|
||||||
else if (var == "controller2.button.start")
|
|
||||||
{
|
{
|
||||||
options.controller[1].buttons[3] = (SDL_GameControllerButton)std::stoi(value);
|
options.controllers.at(1).buttons.at(1) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||||
}
|
}
|
||||||
|
else if (var == "controller.1.button.fire_right")
|
||||||
else if (var == "controller2.button.service")
|
|
||||||
{
|
{
|
||||||
options.controller[1].buttons[4] = (SDL_GameControllerButton)std::stoi(value);
|
options.controllers.at(1).buttons.at(2) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||||
|
}
|
||||||
|
else if (var == "controller.1.button.start")
|
||||||
|
{
|
||||||
|
options.controllers.at(1).buttons.at(3) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||||
|
}
|
||||||
|
else if (var == "controller.1.button.service")
|
||||||
|
{
|
||||||
|
options.controllers.at(1).buttons.at(4) = static_cast<SDL_GameControllerButton>(std::stoi(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lineas vacias o que empiezan por comentario
|
// Lineas vacias o que empiezan por comentario
|
||||||
else if (var.empty() || var.starts_with("#"))
|
else if (var.empty() || var.starts_with("#"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
success = false;
|
success = false;
|
||||||
@@ -408,3 +350,45 @@ int to_JA_volume(int vol)
|
|||||||
vol = vol * 1.28f;
|
vol = vol * 1.28f;
|
||||||
return std::clamp(vol, 0, 128);
|
return std::clamp(vol, 0, 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Asigna el teclado al jugador
|
||||||
|
void setKeyboardToPlayer(int player_id)
|
||||||
|
{
|
||||||
|
for (auto &controller : options.controllers)
|
||||||
|
{
|
||||||
|
if (controller.player_id == player_id)
|
||||||
|
{
|
||||||
|
controller.type = InputDeviceToUse::ANY;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
controller.type = InputDeviceToUse::CONTROLLER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercambia el teclado de jugador
|
||||||
|
void swapOptionsKeyboard()
|
||||||
|
{
|
||||||
|
std::swap(options.controllers.at(0).type, options.controllers.at(1).type);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercambia los jugadores asignados a los dos primeros mandos
|
||||||
|
void swapOptionsControllers()
|
||||||
|
{
|
||||||
|
std::swap(options.controllers.at(0).player_id, options.controllers.at(1).player_id);
|
||||||
|
std::swap(options.controllers.at(0).type, options.controllers.at(1).type);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Averigua quien está usando el teclado
|
||||||
|
int getPlayerWhoUsesKeyboard()
|
||||||
|
{
|
||||||
|
for (const auto &controller : options.controllers)
|
||||||
|
{
|
||||||
|
if (controller.type == InputDeviceToUse::ANY)
|
||||||
|
{
|
||||||
|
return controller.player_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -1,17 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_gamecontroller.h> // Para SDL_GameControllerButton
|
#include <SDL2/SDL_gamecontroller.h> // Para SDL_CONTROLLER_BUTTON_B, SDL_CO...
|
||||||
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
#include <string> // Para string
|
||||||
#include "manage_hiscore_table.h"
|
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
#include <string>
|
#include "input.h" // Para InputType, InputDeviceToUse
|
||||||
enum class InputType : int;
|
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
||||||
enum class ScreenFilter : int;
|
enum class ScreenFilter : int; // lines 10-10
|
||||||
enum class ScreenVideoMode : int;
|
enum class ScreenVideoMode : int; // lines 11-11
|
||||||
namespace lang
|
namespace lang
|
||||||
{
|
{
|
||||||
enum class Code : int;
|
enum class Code : int;
|
||||||
}
|
} // lines 14-14
|
||||||
|
|
||||||
// Dificultad del juego
|
// Dificultad del juego
|
||||||
enum class GameDifficulty
|
enum class GameDifficulty
|
||||||
@@ -75,11 +74,17 @@ struct OptionsController
|
|||||||
{
|
{
|
||||||
int index; // Indice en el vector de mandos
|
int index; // Indice en el vector de mandos
|
||||||
int player_id; // Jugador asociado al mando
|
int player_id; // Jugador asociado al mando
|
||||||
Uint8 device_type; // Indica si se utilizará teclado o mando o ambos
|
InputDeviceToUse type; // Indica si se utilizará teclado o mando o ambos
|
||||||
std::string name; // Nombre del dispositivo
|
std::string name; // Nombre del dispositivo
|
||||||
bool plugged; // Indica si el mando se encuentra conectado
|
bool plugged; // Indica si el mando se encuentra conectado
|
||||||
std::vector<InputType> inputs; // Listado de inputs
|
std::vector<InputType> inputs; // Listado de inputs
|
||||||
std::vector<SDL_GameControllerButton> buttons; // Listado de botones asignados a cada input
|
std::vector<SDL_GameControllerButton> buttons; // Listado de botones asignados a cada input
|
||||||
|
|
||||||
|
// Constructor por defecto
|
||||||
|
OptionsController()
|
||||||
|
: index(-1), player_id(-1), type(InputDeviceToUse::CONTROLLER), name(""), plugged(false),
|
||||||
|
inputs{InputType::FIRE_LEFT, InputType::FIRE_CENTER, InputType::FIRE_RIGHT, InputType::START, InputType::SERVICE},
|
||||||
|
buttons{SDL_CONTROLLER_BUTTON_X, SDL_CONTROLLER_BUTTON_Y, SDL_CONTROLLER_BUTTON_B, SDL_CONTROLLER_BUTTON_START, SDL_CONTROLLER_BUTTON_BACK} {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estructura con todas las opciones de configuración del programa
|
// Estructura con todas las opciones de configuración del programa
|
||||||
@@ -88,12 +93,14 @@ struct Options
|
|||||||
OptionsGame game; // Opciones para el propio juego
|
OptionsGame game; // Opciones para el propio juego
|
||||||
OptionsVideo video; // Opciones relativas a la clase screen
|
OptionsVideo video; // Opciones relativas a la clase screen
|
||||||
OptionsAudio audio; // Opciones para el audio
|
OptionsAudio audio; // Opciones para el audio
|
||||||
std::vector<OptionsController> controller; // Opciones con las asignaciones del mando para cada jugador
|
std::vector<OptionsController> controllers; // Opciones con las asignaciones del mando para cada jugador
|
||||||
};
|
};
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
extern Options options;
|
extern Options options;
|
||||||
|
|
||||||
|
void initOptions();
|
||||||
|
|
||||||
// Carga el fichero de configuración
|
// Carga el fichero de configuración
|
||||||
bool loadOptionsFile(std::string file_path);
|
bool loadOptionsFile(std::string file_path);
|
||||||
|
|
||||||
@@ -102,3 +109,15 @@ bool saveOptionsFile(std::string file_path);
|
|||||||
|
|
||||||
// Convierte valores de 0 a 100 en valores de 0 a 128
|
// Convierte valores de 0 a 100 en valores de 0 a 128
|
||||||
int to_JA_volume(int vol);
|
int to_JA_volume(int vol);
|
||||||
|
|
||||||
|
// Asigna el teclado al jugador
|
||||||
|
void setKeyboardToPlayer(int player_id);
|
||||||
|
|
||||||
|
// Intercambia el teclado de jugador
|
||||||
|
void swapOptionsKeyboard();
|
||||||
|
|
||||||
|
// Intercambia los jugadores asignados a los dos primeros mandos
|
||||||
|
void swapOptionsControllers();
|
||||||
|
|
||||||
|
// Averigua quien está usando el teclado
|
||||||
|
int getPlayerWhoUsesKeyboard();
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#include "path_sprite.h"
|
#include "path_sprite.h"
|
||||||
#include <cmath> // for abs
|
#include <cmath> // Para abs
|
||||||
#include <stdlib.h> // for abs
|
#include <stdlib.h> // Para abs
|
||||||
#include <functional> // for function
|
#include <functional> // Para function
|
||||||
#include <utility> // for move
|
#include <utility> // Para move
|
||||||
|
|
||||||
// Devuelve un vector con los puntos que conforman la ruta
|
// Devuelve un vector con los puntos que conforman la ruta
|
||||||
std::vector<SDL_Point> createPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easingFunction)
|
std::vector<SDL_Point> createPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easingFunction)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Point
|
#include <SDL2/SDL_rect.h> // Para SDL_Point
|
||||||
#include <functional> // for function
|
#include <functional> // Para function
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // Para shared_ptr
|
||||||
#include <vector> // for vector
|
#include <vector> // Para vector
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // Para Sprite
|
||||||
class Texture; // lines 8-8
|
class Texture; // lines 8-8
|
||||||
|
|
||||||
enum class PathType
|
enum class PathType
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // para SDL_Point, SDL_Rect
|
#include <SDL2/SDL_rect.h> // Para SDL_Point, SDL_Rect
|
||||||
#include <SDL2/SDL_render.h> // para SDL_Renderer, SDL_Texture
|
#include <SDL2/SDL_render.h> // Para SDL_Texture, SDL_Renderer
|
||||||
#include <SDL2/SDL_stdinc.h> // para Uint32
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
#include <SDL2/SDL_timer.h> // para SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <memory> // para unique_ptr, shared_ptr
|
#include <stddef.h> // Para size_t
|
||||||
#include <string> // para string
|
#include <memory> // Para unique_ptr, shared_ptr
|
||||||
#include <vector> // para vector
|
#include <string> // Para string
|
||||||
#include "utils.h" // para Color
|
#include <vector> // Para vector
|
||||||
class Sprite;
|
#include "utils.h" // Para Color
|
||||||
class Text;
|
class Sprite; // lines 11-11
|
||||||
class Texture;
|
class Text; // lines 12-12
|
||||||
|
class Texture; // lines 13-13
|
||||||
|
|
||||||
// Defines
|
// Defines
|
||||||
constexpr int SCOREBOARD_LEFT_PANEL = 0;
|
constexpr int SCOREBOARD_LEFT_PANEL = 0;
|
||||||
|
|||||||
@@ -6,12 +6,12 @@
|
|||||||
#include <algorithm> // Para clamp, max, min
|
#include <algorithm> // Para clamp, max, min
|
||||||
#include <fstream> // Para basic_ifstream, ifstream
|
#include <fstream> // Para basic_ifstream, ifstream
|
||||||
#include <iterator> // Para istreambuf_iterator, operator==
|
#include <iterator> // Para istreambuf_iterator, operator==
|
||||||
#include <string> // Para allocator, operator+, to_string, char_t...
|
#include <string> // Para allocator, operator+, char_traits, to_s...
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
#include "asset.h" // Para Asset
|
#include "asset.h" // Para Asset
|
||||||
#include "dbgtxt.h" // Para dbg_print
|
#include "dbgtxt.h" // Para dbg_print
|
||||||
#include "global_inputs.h" // Para service_pressed_counter
|
#include "global_inputs.h" // Para service_pressed_counter
|
||||||
#include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_RE...
|
#include "jail_shader.h" // Para init, render
|
||||||
#include "notifier.h" // Para Notifier
|
#include "notifier.h" // Para Notifier
|
||||||
#include "on_screen_help.h" // Para OnScreenHelp
|
#include "on_screen_help.h" // Para OnScreenHelp
|
||||||
#include "options.h" // Para Options, OptionsVideo, options, Options...
|
#include "options.h" // Para Options, OptionsVideo, options, Options...
|
||||||
@@ -98,7 +98,7 @@ void Screen::blit()
|
|||||||
OnScreenHelp::get()->render();
|
OnScreenHelp::get()->render();
|
||||||
|
|
||||||
// Muestra información por pantalla
|
// Muestra información por pantalla
|
||||||
displayInfo();
|
renderInfo();
|
||||||
|
|
||||||
// Muestra las notificaciones
|
// Muestra las notificaciones
|
||||||
Notifier::get()->render();
|
Notifier::get()->render();
|
||||||
@@ -210,7 +210,7 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Camibia entre pantalla completa y ventana
|
// Camibia entre pantalla completa y ventana
|
||||||
void Screen::switchVideoMode()
|
void Screen::toggleVideoMode()
|
||||||
{
|
{
|
||||||
options.video.mode = options.video.mode == ScreenVideoMode::WINDOW ? ScreenVideoMode::FULLSCREEN : ScreenVideoMode::WINDOW;
|
options.video.mode = options.video.mode == ScreenVideoMode::WINDOW ? ScreenVideoMode::FULLSCREEN : ScreenVideoMode::WINDOW;
|
||||||
setVideoMode(options.video.mode);
|
setVideoMode(options.video.mode);
|
||||||
@@ -260,72 +260,6 @@ void Screen::update()
|
|||||||
OnScreenHelp::get()->update();
|
OnScreenHelp::get()->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las entradas
|
|
||||||
void Screen::checkInput()
|
|
||||||
{
|
|
||||||
#ifndef ARCADE
|
|
||||||
// Comprueba el teclado para cambiar entre pantalla completa y ventana
|
|
||||||
if (Input::get()->checkInput(InputType::WINDOW_FULLSCREEN, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
|
||||||
{
|
|
||||||
switchVideoMode();
|
|
||||||
const std::string mode = options.video.mode == ScreenVideoMode::WINDOW ? "Window" : "Fullscreen";
|
|
||||||
Notifier::get()->showText(mode + " mode");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba el teclado para decrementar el tamaño de la ventana
|
|
||||||
if (Input::get()->checkInput(InputType::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
|
||||||
{
|
|
||||||
decWindowSize();
|
|
||||||
const std::string size = std::to_string(options.video.window.size);
|
|
||||||
Notifier::get()->showText("Window size x" + size);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba el teclado para incrementar el tamaño de la ventana
|
|
||||||
if (Input::get()->checkInput(InputType::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
|
||||||
{
|
|
||||||
incWindowSize();
|
|
||||||
const std::string size = std::to_string(options.video.window.size);
|
|
||||||
Notifier::get()->showText("Window size x" + size);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Comprueba el teclado para activar o desactivar los shaders
|
|
||||||
if (Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
|
||||||
{
|
|
||||||
switchShaders();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
// Comprueba el teclado para mostrar la información de debug
|
|
||||||
if (Input::get()->checkInput(InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
|
||||||
{
|
|
||||||
show_info_ = !show_info_;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
|
||||||
{
|
|
||||||
// Comprueba los mandos para activar o desactivar los shaders
|
|
||||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
|
||||||
{
|
|
||||||
switchShaders();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba los mandos para mostrar la información de debug
|
|
||||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::SHOWINFO, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
|
||||||
{
|
|
||||||
show_info_ = !show_info_;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Agita la pantalla
|
// Agita la pantalla
|
||||||
void Screen::shake()
|
void Screen::shake()
|
||||||
{
|
{
|
||||||
@@ -384,11 +318,8 @@ void Screen::doFlash()
|
|||||||
if (flash_effect_.enabled)
|
if (flash_effect_.enabled)
|
||||||
{
|
{
|
||||||
// Dibuja el color del flash en la textura
|
// Dibuja el color del flash en la textura
|
||||||
//auto temp = SDL_GetRenderTarget(renderer_);
|
|
||||||
//SDL_SetRenderTarget(renderer_, game_canvas_);
|
|
||||||
SDL_SetRenderDrawColor(renderer_, flash_effect_.color.r, flash_effect_.color.g, flash_effect_.color.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, flash_effect_.color.r, flash_effect_.color.g, flash_effect_.color.b, 0xFF);
|
||||||
SDL_RenderClear(renderer_);
|
SDL_RenderClear(renderer_);
|
||||||
//SDL_SetRenderTarget(renderer_, temp);
|
|
||||||
|
|
||||||
// Actualiza la lógica del efecto
|
// Actualiza la lógica del efecto
|
||||||
flash_effect_.counter > 0 ? flash_effect_.counter-- : flash_effect_.enabled = false;
|
flash_effect_.counter > 0 ? flash_effect_.counter-- : flash_effect_.enabled = false;
|
||||||
@@ -400,21 +331,24 @@ void Screen::doAttenuate()
|
|||||||
{
|
{
|
||||||
if (attenuate_effect_)
|
if (attenuate_effect_)
|
||||||
{
|
{
|
||||||
//auto temp = SDL_GetRenderTarget(renderer_);
|
|
||||||
//SDL_SetRenderTarget(renderer_, game_canvas_);
|
|
||||||
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 64);
|
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 64);
|
||||||
SDL_RenderFillRect(renderer_, nullptr);
|
SDL_RenderFillRect(renderer_, nullptr);
|
||||||
//SDL_SetRenderTarget(renderer_, temp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activa / desactiva los shaders
|
// Activa / desactiva los shaders
|
||||||
void Screen::switchShaders()
|
void Screen::toggleShaders()
|
||||||
{
|
{
|
||||||
options.video.shaders = !options.video.shaders;
|
options.video.shaders = !options.video.shaders;
|
||||||
setVideoMode(options.video.mode);
|
setVideoMode(options.video.mode);
|
||||||
const std::string value = options.video.shaders ? "on" : "off";
|
const std::string value = options.video.shaders ? "on" : "off";
|
||||||
Notifier::get()->showText("Shaders " + value);
|
Notifier::get()->showText({"Shaders " + value});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activa / desactiva la información de debug
|
||||||
|
void Screen::toggleDebugInfo()
|
||||||
|
{
|
||||||
|
show_info_ = !show_info_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Atenua la pantalla
|
// Atenua la pantalla
|
||||||
@@ -441,7 +375,7 @@ void Screen::updateFPS()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Muestra información por pantalla
|
// Muestra información por pantalla
|
||||||
void Screen::displayInfo()
|
void Screen::renderInfo()
|
||||||
{
|
{
|
||||||
if (show_info_)
|
if (show_info_)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ private:
|
|||||||
void updateFPS();
|
void updateFPS();
|
||||||
|
|
||||||
// Muestra información por pantalla
|
// Muestra información por pantalla
|
||||||
void displayInfo();
|
void renderInfo();
|
||||||
|
|
||||||
// Calcula la nueva posición de la ventana a partir de la antigua al cambiarla de tamaño
|
// Calcula la nueva posición de la ventana a partir de la antigua al cambiarla de tamaño
|
||||||
SDL_Point getNewPosition();
|
SDL_Point getNewPosition();
|
||||||
@@ -118,9 +118,6 @@ public:
|
|||||||
// Actualiza la lógica de la clase
|
// Actualiza la lógica de la clase
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
// Comprueba las entradas
|
|
||||||
void checkInput();
|
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
void clean(Color color = Color(0x00, 0x00, 0x00));
|
void clean(Color color = Color(0x00, 0x00, 0x00));
|
||||||
|
|
||||||
@@ -133,8 +130,8 @@ public:
|
|||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
void setVideoMode(ScreenVideoMode video_mode);
|
void setVideoMode(ScreenVideoMode video_mode);
|
||||||
|
|
||||||
// Camibia entre pantalla completa y ventana
|
// Cambia entre pantalla completa y ventana
|
||||||
void switchVideoMode();
|
void toggleVideoMode();
|
||||||
|
|
||||||
// Cambia el tamaño de la ventana
|
// Cambia el tamaño de la ventana
|
||||||
void setWindowSize(int size);
|
void setWindowSize(int size);
|
||||||
@@ -158,7 +155,10 @@ public:
|
|||||||
void flash(Color color, int lenght);
|
void flash(Color color, int lenght);
|
||||||
|
|
||||||
// Activa / desactiva los shaders
|
// Activa / desactiva los shaders
|
||||||
void switchShaders();
|
void toggleShaders();
|
||||||
|
|
||||||
|
// Activa / desactiva la información de debug
|
||||||
|
void toggleDebugInfo();
|
||||||
|
|
||||||
// Atenua la pantalla
|
// Atenua la pantalla
|
||||||
void attenuate(bool value);
|
void attenuate(bool value);
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <SDL2/SDL_render.h> // for SDL_TEXTUREACCESS_TARGET
|
#include <SDL2/SDL_render.h> // Para SDL_TEXTUREACCESS_TARGET
|
||||||
#include <stddef.h> // for size_t
|
#include <stddef.h> // Para size_t
|
||||||
#include <fstream> // for basic_ifstream, basic_istream, basic...
|
#include <fstream> // Para basic_ifstream, basic_istream, basic...
|
||||||
#include <iostream> // for cerr
|
#include <iostream> // Para cerr
|
||||||
#include <stdexcept> // for runtime_error
|
#include <stdexcept> // Para runtime_error
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // Para Screen
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // Para Sprite
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // Para Texture
|
||||||
#include "utils.h" // for Color, getFileName, printWithDots
|
#include "utils.h" // Para Color, getFileName, printWithDots
|
||||||
|
|
||||||
// Llena una estructuta TextFile desde un fichero
|
// Llena una estructuta TextFile desde un fichero
|
||||||
std::shared_ptr<TextFile> loadTextFile(const std::string &file_path)
|
std::shared_ptr<TextFile> loadTextFile(const std::string &file_path)
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||||
#include <SDL2/SDL_surface.h> // Para SDL_CreateRGBSurfaceWithFormatFrom
|
#include <SDL2/SDL_surface.h> // Para SDL_CreateRGBSurfaceWithFormatFrom
|
||||||
#include <fcntl.h> // Para SEEK_END, SEEK_SET
|
|
||||||
#include <stdio.h> // Para fseek, fclose, fopen, fread, ftell, FILE
|
|
||||||
#include <stdlib.h> // Para free, malloc
|
|
||||||
#include <fstream> // Para basic_ostream, operator<<, basic_ifstream
|
#include <fstream> // Para basic_ostream, operator<<, basic_ifstream
|
||||||
#include <iostream> // Para cerr, cout
|
#include <iostream> // Para cerr, cout
|
||||||
#include <stdexcept> // Para runtime_error
|
#include <stdexcept> // Para runtime_error
|
||||||
|
#include <string> // Para char_traits, operator<<, operator+
|
||||||
|
#include <vector> // Para vector
|
||||||
#include "gif.c" // Para LoadGif, LoadPalette
|
#include "gif.c" // Para LoadGif, LoadPalette
|
||||||
|
#include "stb_image.h" // Para stbi_image_free, stbi_load, STBI_rgb_a...
|
||||||
#include "utils.h" // Para getFileName, printWithDots
|
#include "utils.h" // Para getFileName, printWithDots
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
@@ -315,8 +315,8 @@ std::vector<Uint32> Texture::loadPaletteFromFile(const std::string &file_path)
|
|||||||
{
|
{
|
||||||
std::vector<Uint32> palette;
|
std::vector<Uint32> palette;
|
||||||
|
|
||||||
FILE *f = fopen(file_path.c_str(), "rb");
|
std::ifstream file(file_path, std::ios::binary | std::ios::ate);
|
||||||
if (!f)
|
if (!file)
|
||||||
{
|
{
|
||||||
std::cerr << "Error: Fichero no encontrado " << getFileName(file_path) << std::endl;
|
std::cerr << "Error: Fichero no encontrado " << getFileName(file_path) << std::endl;
|
||||||
throw std::runtime_error("Fichero no encontrado: " + getFileName(file_path));
|
throw std::runtime_error("Fichero no encontrado: " + getFileName(file_path));
|
||||||
@@ -326,21 +326,22 @@ std::vector<Uint32> Texture::loadPaletteFromFile(const std::string &file_path)
|
|||||||
printWithDots("Image : ", getFileName(file_path), "[ LOADED ]");
|
printWithDots("Image : ", getFileName(file_path), "[ LOADED ]");
|
||||||
}
|
}
|
||||||
|
|
||||||
fseek(f, 0, SEEK_END);
|
auto size = file.tellg();
|
||||||
long size = ftell(f);
|
file.seekg(0, std::ios::beg);
|
||||||
fseek(f, 0, SEEK_SET);
|
|
||||||
Uint8 *buffer = static_cast<Uint8 *>(malloc(size));
|
|
||||||
fread(buffer, size, 1, f);
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
const auto *pal = LoadPalette(buffer);
|
std::vector<Uint8> buffer(size);
|
||||||
|
if (!file.read(reinterpret_cast<char *>(buffer.data()), size))
|
||||||
|
{
|
||||||
|
std::cerr << "Error: No se pudo leer completamente el fichero " << getFileName(file_path) << std::endl;
|
||||||
|
throw std::runtime_error("Error al leer el fichero: " + getFileName(file_path));
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto pal = LoadPalette(buffer.data());
|
||||||
if (!pal)
|
if (!pal)
|
||||||
{
|
{
|
||||||
return palette;
|
return palette;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buffer);
|
|
||||||
|
|
||||||
for (int i = 0; i < 256; ++i)
|
for (int i = 0; i < 256; ++i)
|
||||||
{
|
{
|
||||||
palette.push_back((pal[i] << 8) + 255);
|
palette.push_back((pal[i] << 8) + 255);
|
||||||
|
|||||||
114
source/title.cpp
114
source/title.cpp
@@ -1,9 +1,10 @@
|
|||||||
#include "title.h"
|
#include "title.h"
|
||||||
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
||||||
#include <SDL2/SDL_keycode.h> // Para SDLK_1, SDLK_2, SDLK_3
|
#include <SDL2/SDL_keycode.h> // Para SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5
|
||||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <string> // Para char_traits, operator+, to_string, bas...
|
#include <stddef.h> // Para size_t
|
||||||
|
#include <string> // Para char_traits, operator+, basic_string
|
||||||
#include <utility> // Para move
|
#include <utility> // Para move
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
#include "define_buttons.h" // Para DefineButtons
|
#include "define_buttons.h" // Para DefineButtons
|
||||||
@@ -18,7 +19,7 @@
|
|||||||
#include "param.h" // Para Param, param, ParamGame, ParamTitle
|
#include "param.h" // Para Param, param, ParamGame, ParamTitle
|
||||||
#include "resource.h" // Para Resource
|
#include "resource.h" // Para Resource
|
||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
#include "section.h" // Para Options, options, name, Name
|
#include "section.h" // Para Options, options, Name, name, AttractMode
|
||||||
#include "sprite.h" // Para Sprite
|
#include "sprite.h" // Para Sprite
|
||||||
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
|
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
|
||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
@@ -171,11 +172,13 @@ void Title::render()
|
|||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
void Title::checkEvents()
|
void Title::checkEvents()
|
||||||
{
|
{
|
||||||
|
// Comprueba el input para el resto de objetos
|
||||||
|
define_buttons_->checkEvents();
|
||||||
|
|
||||||
// Si define_buttons_ está habilitado, es él quien gestiona los eventos
|
// Si define_buttons_ está habilitado, es él quien gestiona los eventos
|
||||||
if (!define_buttons_->isEnabled())
|
if (!define_buttons_->isEnabled())
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
// Comprueba los eventos que hay en la cola
|
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
// Evento de salida de la aplicación
|
||||||
@@ -196,32 +199,36 @@ void Title::checkEvents()
|
|||||||
{
|
{
|
||||||
switch (event.key.keysym.sym)
|
switch (event.key.keysym.sym)
|
||||||
{
|
{
|
||||||
case SDLK_1:
|
case SDLK_1: // Redefine los botones del mando #0
|
||||||
{
|
{
|
||||||
if (define_buttons_->enable(0))
|
if (define_buttons_->enable(0))
|
||||||
resetCounter();
|
resetCounter();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SDLK_2: // Redefine los botones del mando #1
|
||||||
case SDLK_2:
|
|
||||||
{
|
{
|
||||||
if (define_buttons_->enable(1))
|
if (define_buttons_->enable(1))
|
||||||
resetCounter();
|
resetCounter();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SDLK_3: // Intercambia los mandos entre los dos jugadores
|
||||||
case SDLK_3:
|
|
||||||
{
|
{
|
||||||
swapControllers();
|
swapControllers();
|
||||||
|
resetCounter();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SDLK_4: // Intercambia la asignación del teclado
|
||||||
case SDLK_4:
|
{
|
||||||
|
swapKeyboard();
|
||||||
|
resetCounter();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SDLK_5: // Muestra la asignacion de mandos y teclado
|
||||||
{
|
{
|
||||||
showControllers();
|
showControllers();
|
||||||
|
resetCounter();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -236,53 +243,37 @@ void Title::checkInput()
|
|||||||
// Comprueba los controladores solo si no se estan definiendo los botones
|
// Comprueba los controladores solo si no se estan definiendo los botones
|
||||||
if (!define_buttons_->isEnabled())
|
if (!define_buttons_->isEnabled())
|
||||||
{
|
{
|
||||||
// Comprueba el teclado para empezar a jugar
|
// Comprueba los métodos de control
|
||||||
if (Input::get()->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
for (const auto &controller : options.controllers)
|
||||||
|
{
|
||||||
|
if (Input::get()->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index) &&
|
||||||
|
!Input::get()->checkInput(InputType::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index))
|
||||||
{
|
{
|
||||||
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
||||||
{
|
{
|
||||||
fade_->activate();
|
fade_->activate();
|
||||||
post_fade_ = options.controller[0].player_id;
|
post_fade_ = controller.player_id;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los mandos
|
|
||||||
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
|
||||||
{
|
|
||||||
// Comprueba si se va a intercambiar la asignación de mandos a jugadores
|
// Comprueba si se va a intercambiar la asignación de mandos a jugadores
|
||||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, controller.type, controller.index) &&
|
||||||
|
Input::get()->checkInput(InputType::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index))
|
||||||
{
|
{
|
||||||
swapControllers();
|
swapControllers();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si algun mando quiere ser configurado
|
// Comprueba si algun mando quiere ser configurado
|
||||||
if (Input::get()->checkModInput(InputType::SERVICE, InputType::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, controller.type, controller.index) &&
|
||||||
|
Input::get()->checkInput(InputType::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index))
|
||||||
{
|
{
|
||||||
define_buttons_->enable(i);
|
define_buttons_->enable(controller.index);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba el botón de START de los mandos
|
|
||||||
if (Input::get()->checkInput(InputType::START, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
|
||||||
{
|
|
||||||
// Si no está el botón de servicio activo
|
|
||||||
if (!Input::get()->checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
|
||||||
{
|
|
||||||
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
|
||||||
{
|
|
||||||
fade_->activate();
|
|
||||||
post_fade_ = options.controller[i].player_id;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba el input para el resto de objetos
|
|
||||||
Screen::get()->checkInput();
|
|
||||||
define_buttons_->checkInput();
|
|
||||||
|
|
||||||
// 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
|
||||||
globalInputs::check();
|
globalInputs::check();
|
||||||
@@ -316,39 +307,44 @@ void Title::swapControllers()
|
|||||||
if (Input::get()->getNumControllers() == 0)
|
if (Input::get()->getNumControllers() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
define_buttons_->swapControllers();
|
swapOptionsControllers();
|
||||||
showControllers();
|
showControllers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Intercambia el teclado de jugador
|
||||||
|
void Title::swapKeyboard()
|
||||||
|
{
|
||||||
|
swapOptionsKeyboard();
|
||||||
|
std::string text = lang::getText(100) + std::to_string(getPlayerWhoUsesKeyboard()) + ": " + lang::getText(69);
|
||||||
|
Notifier::get()->showText({text});
|
||||||
|
}
|
||||||
|
|
||||||
// Muestra información sobre los controles y los jugadores
|
// Muestra información sobre los controles y los jugadores
|
||||||
void Title::showControllers()
|
void Title::showControllers()
|
||||||
{
|
{
|
||||||
// Crea cadenas de texto vacias para un numero máximo de mandos
|
// Crea vectores de texto vacíos para un número máximo de mandos
|
||||||
constexpr int MAX_CONTROLLERS = 2;
|
constexpr size_t NUM_CONTROLLERS = 2;
|
||||||
std::string text[MAX_CONTROLLERS];
|
std::vector<std::string> text(NUM_CONTROLLERS);
|
||||||
int playerControllerIndex[MAX_CONTROLLERS];
|
std::vector<int> playerControllerIndex(NUM_CONTROLLERS, -1);
|
||||||
for (int i = 0; i < MAX_CONTROLLERS; ++i)
|
|
||||||
{
|
|
||||||
text[i].clear();
|
|
||||||
playerControllerIndex[i] = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene para cada jugador el índice del mando correspondiente
|
// Obtiene de cada jugador el índice del mando que tiene asignado
|
||||||
for (int i = 0; i < MAX_CONTROLLERS; ++i)
|
for (size_t i = 0; i < NUM_CONTROLLERS; ++i)
|
||||||
{
|
{
|
||||||
playerControllerIndex[options.controller[i].player_id - 1] = i;
|
// Ejemplo: el jugador 1 tiene el mando 2
|
||||||
|
playerControllerIndex.at(options.controllers.at(i).player_id - 1) = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Genera el texto correspondiente
|
// Genera el texto correspondiente
|
||||||
for (int i = 0; i < MAX_CONTROLLERS; ++i)
|
for (size_t i = 0; i < NUM_CONTROLLERS; ++i)
|
||||||
{
|
{
|
||||||
const int index = playerControllerIndex[i];
|
const size_t index = playerControllerIndex.at(i);
|
||||||
if (options.controller[index].plugged)
|
if (options.controllers.at(index).plugged)
|
||||||
{
|
{
|
||||||
text[i] = lang::getText(100) + std::to_string(i + 1) + ": " + options.controller[index].name;
|
text.at(i) = lang::getText(100) + std::to_string(i + 1) + ": " + options.controllers.at(index).name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Notifier::get()->showText(text[0], text[1]);
|
// std::string spaces(lang::getText(100).length() + 3, ' ');
|
||||||
resetCounter();
|
// std::string kb_text = spaces + lang::getText(69);
|
||||||
|
Notifier::get()->showText({text.at(0), text.at(1)});
|
||||||
}
|
}
|
||||||
@@ -2,14 +2,17 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
#include <memory> // Para unique_ptr, shared_ptr
|
#include <memory> // Para unique_ptr, shared_ptr
|
||||||
#include "section.h" // Para Name
|
class DefineButtons; // lines 6-6
|
||||||
class DefineButtons;
|
class Fade; // lines 7-7
|
||||||
class Fade;
|
class GameLogo; // lines 8-8
|
||||||
class GameLogo;
|
class Sprite; // lines 9-9
|
||||||
class Sprite;
|
class Text; // lines 10-10
|
||||||
class Text;
|
class Texture; // lines 11-11
|
||||||
class Texture; // lines 14-14
|
class TiledBG; // lines 12-12
|
||||||
class TiledBG;
|
namespace section
|
||||||
|
{
|
||||||
|
enum class Name;
|
||||||
|
}
|
||||||
|
|
||||||
// Textos
|
// Textos
|
||||||
constexpr const char TEXT_COPYRIGHT[] = "@2020,2024 JailDesigner";
|
constexpr const char TEXT_COPYRIGHT[] = "@2020,2024 JailDesigner";
|
||||||
@@ -74,6 +77,9 @@ private:
|
|||||||
// Intercambia la asignación de mandos a los jugadores
|
// Intercambia la asignación de mandos a los jugadores
|
||||||
void swapControllers();
|
void swapControllers();
|
||||||
|
|
||||||
|
// Intercambia el teclado de jugador
|
||||||
|
void swapKeyboard();
|
||||||
|
|
||||||
// Muestra información sobre los controles y los jugadores
|
// Muestra información sobre los controles y los jugadores
|
||||||
void showControllers();
|
void showControllers();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user