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

pVelocity = Allocate(2) ; -- Allocate a Vec2 velocity member
pAge = Allocate(1) ; -- Allocate a TReal age member
pSpin = Allocate(1); -- Allocate a TReal spin member
pSpinSpeed = Allocate(1); -- Allocate a TReal spin member
pOrigPosition = Allocate(2);
pSin = Allocate(1);
pLifeSpan = Allocate(1);

SetTexture( "particles/smoke" );
SetBlendMode( kBlendAdditiveAlpha );	-- kBlendNormal, kBlendAdditiveAlpha
SetNumParticles( 500 );

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

if( not dPosition ) then
	dPosition = Vec2( 0, 0 );
end

if( not dRed ) then
	dRed = 1;
end

if( not dBlue ) then
	dBlue = 1;
end

if( not dGreen ) then
	dGreen = 1;
end

pPosition:Init( dPosition );
pOrigPosition:Init( pPosition );
pVelocity:Init( fRange( Vec2(-10,-30), Vec2(10,-50) ) );
pScale:Init( 0.5 );
pAge:Init( 0 );
pSpin:Init( fRange( 0, 2*3.1415927 ) );
pSpinSpeed:Init( fRange( -3, 3 ) );
pSin:Init( fRange( 0, 1 ) );
pLifeSpan:Init( fRange( 7000, 14000 ) );

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

pSin:Anim( pSin + fTimeScale( 1 ) );
pOrigPosition:Anim( pOrigPosition + fTimeScale( pVelocity ) );
pPosition:Anim( Vec2( pOrigPosition[1] + ( fSin( pSin * 3.1415926 ) * ( pSin + -10 ) ), pOrigPosition[2] ) );
pScale:Anim( pScale + fTimeScale( 0.2 ) );

pColor:Anim( 
   fFade( pAge,
	  Color( dRed, dGreen, dBlue, 0 ), 500,
      Color( dRed, dGreen, dBlue, 0.1 ), pLifeSpan,
      Color( dRed, dGreen, dBlue, 0 ) )
   );

pSpin:Anim( pSpin + fTimeScale( pSpinSpeed ) );
pAge:Anim( pAge+fAge() );

Anim( fExpire( fGreater( pAge,pLifeSpan ) ) );

gActive = 0;

-- ------------------------------------------------------------
-- A function to run as we're executing
-- seconds - how many seconds have elapsed
function Update( seconds )
	if( gActive > 0 ) then
		CreateParticles( 100 );
		gActive = 0;
	end
end
