-- ------------------------------------------------------------
-- Define our particle characteristics

pAge = Allocate( 1 );
pSpin = Allocate( 1 );
pRed = Allocate( 1 );
pGreen = Allocate( 1 );
pBlue = Allocate( 1 );
pLifeSpan = Allocate( 1 );
pUpInc = Allocate( 1 );
pVelocity = Allocate( 1 );
pOriginalPosition = Allocate( 2 );

SetTexture( "particles/particlespark" );
SetBlendMode( kBlendAdditiveAlpha );
SetNumParticles( 400 );

-- ------------------------------------------------------------
-- Initialization rules.

if not dLocus then
	dLocus = Vec2( 300, 300 ); 
end

if not dSize then
	dSize = Vec2( 200, 100 );
end

if not dAlpha then
	dAlpha = 1;
end

pPosition:Init( dLocus );
pOriginalPosition:Init( dLocus );
pScale:Init( 0 );
pAge:Init( 0 );
pSpin:Init( fRange( 0, 2 * 3.1415927 ) );
pRed:Init( fRange( 0.2, 1 ) );
pGreen:Init( fRange( 0.5, 1 ) );
pBlue:Init( fRange( 0.2, 1 ) );
pLifeSpan:Init( fRange( 750, 1000 ) );
pUp:Init( fRange( 0, 2 * 3.1415927 ) );
pUpInc:Init( fRange( 0, 2 * 3.1415927 ) );
pVelocity:Init( 0 );

-- ------------------------------------------------------------
-- Particle Parameter Animation Functions

pPosition:Anim( Vec2( pOriginalPosition[1] + fTimeScale( pVelocity ) + ( f2dRotation( pSpin )[1] * dSize[1] * pVelocity ),
					  pOriginalPosition[2] + fTimeScale( pVelocity ) + ( f2dRotation( pSpin )[2] * dSize[2] * pVelocity ) ) );
pColor:Anim( fFade( pAge,
					Color( pRed, pGreen, pBlue, 0 ), 100,
					Color( pRed, pGreen, pBlue, dAlpha ), pLifeSpan,
					Color( pRed, pGreen, pBlue, 0 ) ) );

pAge:Anim( pAge + fAge() );
pScale:Anim( pScale + fTimeScale( 2 ) );
pVelocity:Anim( pVelocity + fTimeScale( 1.5 ) );

-- General Anim functions
Anim( fExpire( fGreater( pAge, pLifeSpan ) ) );

-- ------------------------------------------------------------

gActive = 1;

function Update( seconds )
	if gActive > 0 then
		CreateParticles( seconds * 100 );
	end
end
