#include "CExplosionObject.h"
#include "CObjectManager.h"
#include "CParticleManager.h"

#include "CGame.h"

//----------------------------------------------------------------//
//	Constructor/Deconstructor
//----------------------------------------------------------------//

CExplosionObject::CExplosionObject()
{


}

CExplosionObject::~CExplosionObject()
{
	
}


void CExplosionObject::Init(int x, int y, int dx, int dy, int strength)
{
	this->typ=typExplosion;		//IMPORTANT!!!
	
	m_directionPoint.x = dx;	
	m_directionPoint.y = dy;	

	m_Position.x = x;
	m_Position.y = y;

	m_EnergyLeft = strength;

	SetRect(&m_boundingBox, 0, 0, g_Game.getTileSize(), g_Game.getTileSize());
	OffsetRect(&m_boundingBox, x, y);	
	
	
		
}

//----------------------------------------------------------------//
//	Draw/Update
//----------------------------------------------------------------//

void CExplosionObject::Draw()
{
	//drawBoundingBox();		

}

void CExplosionObject::Update()
{
	if(m_EnergyLeft <= 0)
	{		
		g_ObjectManager.RemoveObjectSafe(this->ID);		
		return;
	}
		


	int dx = g_Game.getTileSize() * m_directionPoint.x;
	int dy = g_Game.getTileSize() * m_directionPoint.y;

	if(dx > 0)
	{	
		m_boundingBox.right += dx;
		g_ParticleManager.CreateFizzle(m_boundingBox.right - dx, m_Position.y);
	}
	if(dx < 0)
	{	
		m_boundingBox.left += dx;
		g_ParticleManager.CreateFizzle(m_boundingBox.left, m_Position.y);
		
	}
	if(dy > 0)
	{	
		m_boundingBox.bottom += dy;
		g_ParticleManager.CreateFizzle(m_Position.x, m_boundingBox.bottom - dy);
	}	
	if(dy < 0)
	{	
		m_boundingBox.top += dy;
		g_ParticleManager.CreateFizzle(m_Position.x, m_boundingBox.top);
	}		

	m_EnergyLeft--;
	

}

void CExplosionObject::expand(int dx, int dy)
{


}


void CExplosionObject::Collision(CGameObject* obj)
{

	
	switch(obj->typ)
	{

	case typPlayer:
	
		
		break;

	case typBlock:


		//int dx = g_Game.getTileSize() * m_directionPoint.x;
		//int dy = g_Game.getTileSize() * m_directionPoint.y;

		m_EnergyLeft=0;

		break;

	default:

		break;

	}	

}



