racing_game/input.cpp

48 lines
942 B
C++

#include "libs/mainloop-api/mainloop.h"
#include "gamepad.h"
#include "input.h"
GAMEPAD_DEVICE dev = GAMEPAD_0;
void input_init()
{
// Initialise the gamepad
GamepadInit();
}
void input_check(int *args)
{
// Make this happen again
mainloopRegAction(input_check, 10, 0);
// Is the gamepad not connected
if(!GamepadIsConnected(dev)) return;
// Check for changes
GamepadUpdate();
}
bool gpad_button_pressed(GAMEPAD_BUTTON button)
{
// Return a boolean varible
return GamepadButtonDown(dev, button);
}
double gpad_trigger_length(GAMEPAD_TRIGGER trigger)
{
// Return the trigger value
return GamepadTriggerLength(dev, trigger);
}
double gpad_stick_length(GAMEPAD_STICK stick)
{
// Return the sticks angle in radians
return GamepadStickLength(dev, stick);
}
void gpad_stick_value(GAMEPAD_STICK stick, float &x, float &y)
{
// Return the x and y of the stick
return GamepadStickNormXY(dev, stick, &x, &y);
}