-- GLOBAL PARAMETERS THAT CAN BE USED TO ADJUST THIS PARTICLES
par_scale = 1.0; -- this parameter sets size of the flames
par_range_x = 4; -- this parameter controls dithering among x
par_range_y = 4; -- this parameter controls dithering among y
par_per_second = 40; -- 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
if not par_position then
   par_position = Vec2(0,0);
end

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("fire.xml");
--SetBlendMode(kBlendNormal );
SetBlendMode( kBlendAdditiveAlpha );

SetNumParticles(45); 

pPosition:Init( fRange( Vec2( -par_range_x+5, -par_range_y -20), Vec2( par_range_x+5, par_range_y -20) ) );
pColor:Init( Color(1,1,1,0.35) );
pScale:Init( par_scale );
pUp:Init( Vec2( 0, -1 )  ) ;
pAge:Init( 0 ) ;
pLifeLen:Init( fRange( 1000, 2000 ) ) ;
pInitFrame:Init( 0 ) ;
pVelocity:Init( fRange( Vec2( 0, -10 ), Vec2( 0, -15 ) ) ) ;

-- Fade the particles.

pAge:Anim( pAge+fAge() );
pColor:Anim( fFade( pAge, Color(1,1,1,0.65), pLifeLen, Color(1, 1, 1, 0 ) ) );
pFrame:Anim( fFade( pAge, pInitFrame, pLifeLen/3, 3, pLifeLen, 5) );
pVelocity:Anim( fFade( pAge, fRange( Vec2( -3, -15), Vec2( 3, -25) ), pLifeLen/4, fRange( Vec2( 0, - 50), Vec2( 0, -200) ) ) );



-- 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)
   -- Create 50 particle per second
   if bActive then
      CreateParticles( seconds * par_per_second );
   end
end

