bool Controller::Peripheral::checkAxes() { Sint16 x = SDL_JoystickGetAxis(getJoy(), SDL_CONTROLLER_AXIS_LEFTX); Sint16 y = SDL_JoystickGetAxis(getJoy(), SDL_CONTROLLER_AXIS_LEFTY); if (ABS(x) > static_cast<Sint16>(_sensi) || ABS(y) > static_cast<Sint16>(_sensi)) { _dir.xyToAngle(x, -y); _dir.setSpeed((ABS(x) > ABS(y) ? ABS(x) : ABS(y))); return (true); } return (false); }
Controller::Button Controller::Peripheral::retJoyButton() { SDL_Joystick * joy = getJoy(); for (register int i = static_cast<int>(BUTTON_MAX); i >= 0 ; i--) { if (SDL_JoystickGetButton(joy, static_cast<SDL_GameControllerButton>(i))) return (static_cast<Button>(i)); } return (BUTTON_INVALID); }
int Controller::Peripheral::checkJoyButton() { SDL_Joystick * joy = getJoy(); for (register int i = static_cast<int>(BUTTON_MAX); i >= 0 ; i--) { if (SDL_JoystickGetButton(joy, static_cast<SDL_GameControllerButton>(i))) { _but = static_cast<Button>(i); break ; } } return (-1); }
void Controller::Peripheral::checkHat() { Uint8 check[] = {SDL_HAT_CENTERED, SDL_HAT_LEFT, SDL_HAT_RIGHT, SDL_HAT_DOWN, SDL_HAT_UP}; double tabval[] = {0.0f, -90.0f, 90.0f, 0.0f, 180.0f}; Uint8 hatValue = SDL_JoystickGetHat(getJoy(), 0); for (register size_t test = sizeof(check) / sizeof(check[0]); test--;) { if (hatValue == check[test]) { _dir.setAngle(tabval[test]); _dir.setSpeed((test == 0 ? 0 : static_cast<int>(RAYON))); break ; } } }
bool Input::getJoyRelease(int joy, unsigned key) { INIT_ASSERT(Input); return !getJoy(joy, key) && joyState[joy][key]; }
bool Input::getJoyPress(int joy, unsigned key) { INIT_ASSERT(Input); return getJoy(joy, key) && !joyState[joy][key]; }