#include "BehaviourGamepad.h"
#include "XInput.h"
#pragma comment(lib, "XInput.lib")

BehaviourGamepad::BehaviourGamepad(void)
{
}

BehaviourGamepad::BehaviourGamepad(float weight)
{
	m_weight = weight;
}

BehaviourGamepad::~BehaviourGamepad(void)
{
}

void
BehaviourGamepad::Update(Actor* actor)
{
	DWORD dwResult;         // Used to store if a controller is connected
	XINPUT_STATE state;     // Data type that stores all the current states
                        // of a controller.
	MOUSESTATE perbens;
	XINPUT_STATE perbens2;
	

	ZeroMemory( &state, sizeof(XINPUT_STATE) ); // Zeros out the states of
											  // the controller.

	// Get all the current states of controller 1
	dwResult = XInputGetState( 0, &state );

	if( dwResult == ERROR_SUCCESS )
	{
		// Controller is connected.
		// -----------INSERT BUTTON CHECKS HERE----------
      float leftThumbY = state.Gamepad.sThumbLY;
	  float leftThumbX = state.Gamepad.sThumbLX;
      if(leftThumbY)
      {
		  actor->m_direction->y += -(leftThumbY / 500000.0f) * this->m_weight;
		  actor->m_direction->x += (leftThumbX / 500000.0f) * this->m_weight;
      }    
	}
	else
	{
	// Controller is disconnected.
	}
}
