#include "cObject.h"
#include "cGame.h"
#ifdef WIN32
#include <Windows.h>
#endif
#include <vector>
using namespace std;

cObject::cObject()
{
	game = NULL;
	depth = 0;
	collide.SetPosition(0,0);
	collide.SetLeft(0);
	collide.SetTop(0);
	collide.SetRight(0);
	collide.SetBottom(0);
	objectType = EMPTY;
}
cObject::cObject(cGame *g)
{
	game = g;
	depth = 0;
	collide.SetPosition(0,0);
	collide.SetLeft(0);
	collide.SetTop(0);
	collide.SetRight(0);
	collide.SetBottom(0);
	objectType = EMPTY;
}
void cObject::Update()
{
	// nothing
}
void cObject::Draw()
{
	// nothing
}
cCollRect *cObject::GetCollide()
{
	return &collide;
}
cObject *cObject::GetObjectAt(double xx, double yy, OBJTYPE type)
{
	cObject *toReturn = NULL;
	double oldX = collide.GetX();
	double oldY = collide.GetY();
	collide.SetPosition(xx,yy);
	vector<cObject*> *vctr = game->GetObjectVector();
	if (type == ALL)
	{
		for(unsigned int i=0;i<vctr->size();i++)
		{
			if (collide.CollidesWidth(vctr->at(i)->GetCollide()))
			{
				toReturn = vctr->at(i);
				break;
			}
		}
	}
	else
	{
		for(unsigned int i=0;i<vctr->size();i++)
		{
			if (collide.CollidesWidth(vctr->at(i)->GetCollide()) && vctr->at(i)->GetType() == type)
			{
				toReturn = vctr->at(i);
				break;
			}
		}
	}
	collide.SetPosition(oldX,oldY);
	return toReturn;
}

bool cObject::IsObjectAt(double xx, double yy, OBJTYPE type)
{
	return (GetObjectAt(xx,yy,type) != NULL);
}

OBJTYPE cObject::GetType()
{
	return objectType;
}

double cObject::GetDepth()
{
	return depth;
}
double cObject::GetX()
{
	return x;
}
double cObject::GetY()
{
	return y;
}
void cObject::Destroy()
{
	destroyed = true;
}
bool cObject::IsDestroyed()
{
	return destroyed;
}