-- GLOBAL PARAMETERS THAT CAN BE USED TO ADJUST THIS PARTICLES
par_scale = 1; -- this parameter sets size of the flames
par_per_second = 4; -- this parameter controls how many particles is created per second
-- THIS PARAMETER CONTROLS BEHAVIOUR
bActive = true; -- this turns on and off creating particles
-- THIS PARAMETER IS USED AS DATA SOURCE


pAge = Allocate(1) ; -- Allocate a parameter representing age and length of life
pLifeLen = Allocate( 1 ) ;
pVelocity = Allocate( 2 ) ;
pInitFrame = Allocate( 1 ); 

-- Set the particle texture
SetTexture("candle_fire_small.xml");
SetBlendMode(kBlendAdditiveAlpha );

SetNumParticles(15); 

pPosition:Init( Vec2(1,-5 ) );
pColor:Init( Color(1,1,1,1) );
pScale:Init( par_scale );
pUp:Init( Vec2( 0, -1 )  ) ;
pAge:Init( fRange(0, 300) ) ;
pLifeLen:Init( fRange( 1500, 2000 ) ) ;
pInitFrame:Init( fPick(0,1,2) ) ;
pVelocity:Init( fRange( Vec2( 0, 0 ), Vec2( 0, 00 ) ) ) ;

-- Fade the particles.

pAge:Anim( pAge+fAge() );
pColor:Anim( fFade( pAge, Color(1,1,1,0.9), pLifeLen, Color(1, 1, 1, 0 ) ) );
pFrame:Anim( fFade( pAge, pInitFrame, pLifeLen/2, 3, pLifeLen, 4) );
pVelocity:Anim( fFade( pAge, Vec2( 0, 0),  pLifeLen/3, Vec2( 0, -10),  pLifeLen, fRange( Vec2( 0, -40), Vec2( 0, -60) ) ) );



-- Expire particles which faded out completelly.

pPosition:Anim( pPosition + fTimeScale( pVelocity ) );
Anim(  fExpire(  fGreater( pAge, pLifeLen ) )  ) ;

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

