#include "Explosion.h"

#include <Renderer/Billboard.h>

Explosion::Explosion( Renderer::PngImagePtr pImage0, Renderer::PngImagePtr pImage1, float Lifespan )
	: m_Lifespan( Lifespan )
	, m_TimeRemaining( Lifespan )
{
	m_pBillboard.reset( new Renderer::Billboard( pImage0 ) );
	Renderer::Billboard::Layer NewLayer;
	NewLayer.pImage = pImage1;
	m_pBillboard->Layers().push_back( NewLayer );
}

Explosion::~Explosion()
{
}

void Explosion::SetPosition( const Math::Vector& P )
{
	m_pBillboard->Layers()[0].CoordinateSpace.SetPosition( P );
}

void Explosion::Update( float Elapsed )
{
	m_TimeRemaining -= Elapsed;
	m_pBillboard->Size() = sin( ((m_Lifespan - m_TimeRemaining)/m_Lifespan) * 3.1415 ) * 5.0f;
	m_pBillboard->Layers()[0].CoordinateSpace.Rotate( Math::LocalRotation( Math::Vector(0, 0, 1), 0.05f ) );
	m_pBillboard->Layers()[1].CoordinateSpace.Rotate( Math::LocalRotation( Math::Vector(0, 0, -1), 0.1f ) );
}
