-- ------------------------------------------------------------
-- 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( 150 );

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

if not dStartPosition then
	dStartPosition = Vec2( 153, 333 );
end

if not dEndPosition then
	dEndPosition = Vec2( 280, 322 );
end

pPosition:Init( fRange( dStartPosition, dEndPosition ) );
pOrigPosition:Init( pPosition );
pVelocity:Init( fRange( Vec2(-0.75,-10), Vec2(0.75,-10) ) );
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 + -5 ) ), pOrigPosition[2] ) );
pScale:Anim( pScale + fTimeScale(0.2) );

pColor:Anim( 
   fFade( pAge,
	  Color(1,1,1,0),500,
      Color(1,1,1,0.1),pLifeSpan,
      Color(1,1,1,0) )
   );

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

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

-- ------------------------------------------------------------
-- A function to run as we're executing
-- seconds - how many seconds have elapsed
function Update(seconds)
   CreateParticles( seconds * 11 );
end
