#include “XInputHandler.h”
XInputHandler::XInputHandler(PlayerIndex playerIndex)
{
this->playerNum = playerIndex;
}
XInputHandler::~XInputHandler()
{
}
bool XInputHandler::isControllerConnected()
{
DWORD error = XInputGetState(playerNum, &xInputControllerState);
if (error == ERROR_DEVICE_NOT_CONNECTED) return false;
else return true;
}
bool XInputHandler::Update(float fDT)
{
//Return false if no longer connected.
DWORD error = XInputGetState(playerNum, &xInputControllerState);
if (error == ERROR_DEVICE_NOT_CONNECTED) return false;
else return true;
}
float XInputHandler::getLeftTrigger()
{
return xInputControllerState.Gamepad.bLeftTrigger / MAX_BYTE_SIZE;
}
float XInputHandler::getRightTrigger()
{
return xInputControllerState.Gamepad.bRightTrigger / MAX_BYTE_SIZE;
}
float XInputHandler::getLeftStickX()
{
if (xInputControllerState.Gamepad.sThumbLX == 32767) return 1.0f;
return (float)xInputControllerState.Gamepad.sThumbLX / MAX_INT_SIZE;
}
float XInputHandler::getLeftStickY()
{
if (xInputControllerState.Gamepad.sThumbLY == 32767) return 1.0f;
return (float)xInputControllerState.Gamepad.sThumbLY / MAX_INT_SIZE;
}
float XInputHandler::getRightStickX()
{
if (xInputControllerState.Gamepad.sThumbRX == 32767) return 1.0f;
return (float)xInputControllerState.Gamepad.sThumbRX / MAX_INT_SIZE;
}
float XInputHandler::getRightStickY()
{
if (xInputControllerState.Gamepad.sThumbRY == 32767) return 1.0f;
return (float) xInputControllerState.Gamepad.sThumbRY / MAX_INT_SIZE;
}
Vector2 XInputHandler::getLeftStickVector()
{
return Vector2(getLeftStickX(), getLeftStickY());
}
Vector2 XInputHandler::getRightStickVector()
{
return Vector2(getRightStickX(), getRightStickY());
}
float XInputHandler::getButtonDownA()
{
if (xInputControllerState.Gamepad.wButtons & XINPUT_GAMEPAD_A) return 1.0f;
else return 0.0f;
}
float XInputHandler::getButtonDownB()
{
if (xInputControllerState.Gamepad.wButtons & XINPUT_GAMEPAD_B) return 1.0f;
else return 0.0f;
}
float XInputHandler::getButtonDownX()
{
if (xInputControllerState.Gamepad.wButtons & XINPUT_GAMEPAD_X) return 1.0f;
else return 0.0f;
}
float XInputHandler::getButtonDownY()
{
if (xInputControllerState.Gamepad.wButtons & XINPUT_GAMEPAD_Y) return 1.0f;
else return 0.0f;
}
float XInputHandler::getButtonDownStart()
{
if (xInputControllerState.Gamepad.wButtons & XINPUT_GAMEPAD_START) return 1.0f;
else return 0.0f;
}
float XInputHandler::getButtonDownBack()
{
if (xInputControllerState.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) return 1.0f;
else return 0.0f;
}
float XInputHandler::getButtonDownLeftBumper()
{
if (xInputControllerState.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) return 1.0f;
else return 0.0f;
}
float XInputHandler::getButtonDownRightBumper()
{
if (xInputControllerState.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) return 1.0f;
else return 0.0f;
}