pAge = Allocate(1) ; -- Allocate a parameter representing age.
pVelocity = Allocate( 2 );
-- Set the particle texture
SetTexture("blue_galaxy.png");
SetBlendMode(kBlendAdditiveAlpha);

SetNumParticles(800);    -- Create some particles
if not dPos then
  dPos = Vec2( 0, 0)
end
pPosition:Init( dPos + fRange( Vec2( 0, -3), Vec2( 40, 3) ) );
pColor:Init( Color(1,1,1,0.8) );
pScale:Init( fRange( 0.7, 1.0 ) );
pUp:Init( f2dRadius( 1 ) );   -- random radius
pAge:Init( 0 ) ;
pVelocity:Init( Vec2( -20, 0 ) );

-- Fade the particles.
pAge:Anim( pAge+fAge() );
pColor:Anim( fFade( pAge, Color(1,1,1,1), 1000, Color(0,0,0,0) ) );
pPosition:Anim( pPosition + fTimeScale( pVelocity) ) ;
pScale:Anim( fFade( pAge, 0.5, 1000, 1.0, 1500, 1.2) )
-- Expire particles which faded out completelly.

Anim(  fExpire(  fLess( pColor[ 3 ], 0.001 )  )  ) ;

-- A function to run as we're executing
-- seconds - how many seconds have elapsed
gActive = false;
function Update(seconds)
   -- Create 20 particle per second
   if gActive then
      CreateParticles( seconds * 400 );
   end
end

