Añadida la función checkAnyButtonPressed a la clase input

This commit is contained in:
2024-07-05 14:25:24 +02:00
parent 62f3c42e7b
commit c3c33135a7
7 changed files with 43 additions and 5 deletions

View File

@@ -21,6 +21,7 @@ Input::Input(std::string file)
verbose = true;
enabled = true;
gameInputs.clear();
gameInputs.push_back(input_fire_left);
gameInputs.push_back(input_fire_center);
gameInputs.push_back(input_fire_right);
@@ -28,6 +29,12 @@ Input::Input(std::string file)
gameInputs.push_back(input_down);
gameInputs.push_back(input_left);
gameInputs.push_back(input_right);
buttonInputs.clear();
buttonInputs.push_back(input_fire_left);
buttonInputs.push_back(input_fire_center);
buttonInputs.push_back(input_fire_right);
buttonInputs.push_back(input_start);
}
// Actualiza el estado del objeto
@@ -195,6 +202,30 @@ bool Input::checkAnyInput(int device, int index)
return false;
}
// Comprueba si hay algún botón pulsado
bool Input::checkAnyButtonPressed()
{
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
for (auto bi : buttonInputs)
{
if (keyStates[keyBindings[bi].scancode] != 0)
{
return true;
}
for (int i = 0; i < numGamepads; ++i)
{
if (SDL_GameControllerGetButton(connectedControllers[i], gameControllerBindings[bi].button) != 0)
{
return true;
}
}
}
return false;
}
// Busca si hay un mando conectado
bool Input::discoverGameController()
{
@@ -244,7 +275,7 @@ bool Input::discoverGameController()
connectedControllers.push_back(pad);
const std::string separator(" #");
std::string name = SDL_GameControllerNameForIndex(i);
//name.resize(25);
// name.resize(25);
name = name + separator + std::to_string(i);
if (verbose)
{