/******************************************************************************
*******************************************************************************

	Bubble Fight EX
	relminator
	http://rel.betterwebber.com


	Singleton Explosion class


*******************************************************************************
******************************************************************************/

#include <nds.h>
#include <gl2d.h>
#include <vector>

#ifndef EXPLOSION_H
#define EXPLOSION_H

enum E_EXPLOSION   //DEATH ID
{
	EX_NONE	= 0,
	EX_SMALL_1,
	EX_SMALL_2,
	EX_SMALL_3,
	EX_SMALL_4,
	EX_MEDIUM_1,
	EX_MEDIUM_2,
	EX_MEDIUM_3,
	EX_MEDIUM_4,
	EX_MEDIUM_5
};


class Explode
{
public:
	friend class Explosion;

	Explode()
	{
		Frame = -1;
		BaseFrame = 0;
		NumFrames = 1;
		Counter = 0;
		Active = false;
		x = 300 << 12;
		y = 96 << 12;
		Dx = 0;
		Dy = 0;
	}
	
	~Explode()
	{
		
	}
	
	void Init( s32 _x, s32 _y, s32 _dx, s32 _dy, int StartFrame, int Numframe )
	{
		
		x = _x;
		y = _y;
		Dx = _dx;
		Dy = _dy;
		
		Frame = -1;
		BaseFrame = StartFrame;
		NumFrames = Numframe;
		
		Counter = 0;
		Active = true;
		
	}
	
	void Update()
	{
		
		Counter++;
		
		x += Dx;
		y += Dy;
		
		if( (Counter & 3) == 0 )
		{
			Frame++;
			if( Frame >= NumFrames ) Active = false;
		}
		
	}
	
	
private:
	s32		x;
	s32		y;
	s32		Dx;
	s32		Dy;
	int		Counter;
	int		Frame;
	int		NumFrames;
	int		BaseFrame;
	bool	Active;
};


//------------------------------------------------------------------------------
//	Explosion Container
//------------------------------------------------------------------------------

class Explosion 
{

	static Explosion* ms_instance;

public:
	
	static Explosion* Instance();
	static void Release();

	void Init( int Palette, glImage* const Sprites );
	void Update();
	void Draw();
	void Spawn(  int _x, int _y, s32 _dx, s32 _dy, int ID );
	
	virtual int NumExplosions() 
	{
		return numExplosions;
	}
private:
	Explosion();
	~Explosion();

	int numExplosions;
	
	glImage *Images;
	int ColorTable;
	
	std::vector<Explode>  Explosions;
};




#endif // EXPLOSION_H
