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

pPreviousPosition = Allocate( 2 );
pVelocity = Allocate( 2 );
pGravity = Allocate( 2 );
pAge = Allocate( 1 );
pLifeSpan = Allocate( 1 );
pRed = Allocate( 1 );
pGreen = Allocate( 1 );
pBlue = Allocate( 1 );

SetTexture( "particles/remotespark" );
SetBlendMode( kBlendNormal );   -- kBlendNormal, kBlendAdditiveAlpha
SetNumParticles( 100 );

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

if not dPosition then
   dPosition = Vec2( 570, 434 ); 
end

pRed:Init( fRange( 0.8, 1 ) );
pGreen:Init( fRange( 0.5, 1 ) );
pBlue:Init( 0 );
pGravity:Init( Vec2( 0, 200 ) );
pPosition:Init( dPosition );
pPreviousPosition:Init( pPosition );
pVelocity:Init( fRange( Vec2( -100, -0 ), Vec2( 100, -200 ) ) );
pScale:Init( 1 );
pAge:Init( 0 );
pUp:Init( Vec2( 1, 0 ) );
pLifeSpan:Init( fRange( 250, 500 ) );

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

pColor:Anim( 
   fFade( pAge,
      Color( pRed, pGreen, pBlue, 1 ), pLifeSpan,
      Color( pRed, pGreen, pBlue, 0 ) )
   );

pVelocity:Anim( pVelocity + fTimeScale( pGravity ) );
pPosition:Anim( pPosition + fTimeScale( pVelocity ) );
pUp:Anim( fNormalize( pPosition - pPreviousPosition ) );
pPreviousPosition:Anim( pPosition );
pAge:Anim( pAge + fAge() );

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

gActive = 1;
gTimeToBeActive = 3.5;
gTimeActive = 0;

-- ------------------------------------------------------------
-- A function to run as we're executing
-- seconds - how many seconds have elapsed
function Update( seconds )
	if( gActive > 0 ) then
		CreateParticles( seconds * 50 );
      
		gTimeActive = gTimeActive + seconds;
      
		if( gTimeActive >= gTimeToBeActive ) then
			gActive = 0;
		end
	else
		gTimeActive = 0;
	end
end
