Añadido soporte para ejes en la clase Input

This commit is contained in:
2024-09-02 10:19:28 +02:00
parent 4f6c92c8d1
commit f57a307991
2 changed files with 67 additions and 18 deletions

View File

@@ -134,6 +134,9 @@ bool Input::checkInput(inputs_e input, bool repeat, int device, int index)
if (gameControllerFound() && index < numGamepads)
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
{
successGameController = checkAxisInput(input, index);
if (!successGameController)
{
if (repeat)
{
@@ -174,6 +177,7 @@ bool Input::checkInput(inputs_e input, bool repeat, int device, int index)
}
}
}
}
return (successKeyboard || successGameController);
}
@@ -494,3 +498,45 @@ void Input::allActive(int index)
gameControllerBindings[index][i].active = true;
}
}
// Comprueba el eje del mando
bool Input::checkAxisInput(inputs_e input, int index)
{
bool success = false;
switch (input)
{
case input_left:
if (SDL_GameControllerGetAxis(connectedControllers[index], SDL_CONTROLLER_AXIS_LEFTX) < -30000)
{
success = true;
}
break;
case input_right:
if (SDL_GameControllerGetAxis(connectedControllers[index], SDL_CONTROLLER_AXIS_LEFTX) > 30000)
{
success = true;
}
break;
case input_up:
if (SDL_GameControllerGetAxis(connectedControllers[index], SDL_CONTROLLER_AXIS_LEFTY) < -30000)
{
success = true;
}
break;
case input_down:
if (SDL_GameControllerGetAxis(connectedControllers[index], SDL_CONTROLLER_AXIS_LEFTY) > 30000)
{
success = true;
}
break;
default:
break;
}
return success;
}

View File

@@ -89,6 +89,9 @@ private:
i_disable_e disabledUntil; // Tiempo que esta deshabilitado
bool enabled; // Indica si está habilitado
// Comprueba el eje del mando
bool checkAxisInput(inputs_e input, int index = 0);
public:
// Constructor
Input(std::string file);