//-----------------------------------------------------
// Name, first name: Hoet, Guntran
// Group: 1DAE3
//-----------------------------------------------------

//---------------------------
// Includes
//---------------------------
#include "Handy.h"

//---------------------------
// Defines
//---------------------------
#define GAME_ENGINE (GameEngine::GetSingleton())
#define MARIO		(Mario::GetSingleton())
Handy* Handy::m_HandyPtr = nullptr;
//---------------------------
// Constructor & Destructor
//---------------------------
Handy::Handy()
{
	// nothing to create
}

Handy::~Handy()
{
	// nothing to destroy
}

Handy* Handy::GetSingleton()
{
	if (m_HandyPtr == nullptr)
		m_HandyPtr = new Handy;		// if handy does not exist already, make one; otherwise just pass the pointer.

	return m_HandyPtr;
}

//---------------------------
// Methods - Member functions
//---------------------------

DOUBLE2 Handy::GetMarioPos()
{
	return MARIO->GetPosition();
}

bool Handy::RectIntersectTest(RECT2 r1, RECT2 r2)
{
	bool noIntersect =
		r1.right < r2.left || r1.left > r2.right ||
		r1.top > r2.bottom || r1.bottom < r2.top;

	return !noIntersect;
}

RECT2 Handy::RectIntersect(RECT2 r1, RECT2 r2)
{
	RECT2 r;
	if (RectIntersectTest(r1, r2))
	{
		r.top = max(r1.top, r2.top);
		r.bottom = min(r1.bottom, r2.bottom);
		r.left = max(r1.left, r2.left);
		r.right = min(r1.right, r2.right);
	}
	return r;
}

bool Handy::CheckIfInRange(DOUBLE2 obj1, DOUBLE2 obj2, int range)
{
	bool inRange = false;

	if (obj1.x > obj2.x - range && obj1.x < obj2.x + range && 
		obj1.y > obj2.y - range && obj1.y < obj2.y + range)
	{ inRange = true; }

	return inRange;
}


