gMaxParticles = 6;
gPPS = 12;
gActiveParticles = -1;
gColor = GUI_Graph(
   {
      Color(1.00,1.00,1.00,1.00),749,
      Color(1.00,1.00,1.00,1.00)
   },
   Color(0,0,0,0),
   Color(1,1,1,1),
   {
      {1.00,1.00,1.00,1.00,time=0.00},
      {1.00,1.00,1.00,1.00,time=749.57},
   },
   "Color");

gBlend = GUI_Select(
   kBlendNormal,
   "Blend Mode",
   {
      { description="Normal", value=kBlendNormal},
      { description="Additive Alpha", value=kBlendAdditiveAlpha},
      { description="Multiplicative", value=kBlendMultiplicative},
      { description="Subtractive", value=kBlendSubtractive},
      { description="Opaque", value=kBlendOpaque},

   }
);

gTexture = GUI_PickTexture("images/minigame/match3/coin","Texture");

-- ------------------------------------------------------------
-- 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

-- Set the particle texture
SetTexture(gTexture);
SetBlendMode(gBlend);

SetNumParticles(gMaxParticles);

-- ------------------------------------------------------------
-- Initialization rules.
-- 
-- The following rules define how particles are created.
--
-- Any parameter below in initialization or animation rules that 
-- is a scalar, Color(), or Vec2() can alternaly take a function 
-- that returns the same type--and most functions can take any type
-- and will return that same type. The exception is any function
-- that's expecting a scalar in certain parameter positions.

-- Define dLocus for FluidFX; in the game it's defined in 
-- swarm.cpp as a data source, and it gets the mouse position.
if not dLocus then
   dLocus= Vec2(0,0) ; 
end

-- Pick a position randomly, within a range of values.
-- dLocus is defined in swarm.cpp and added to the random
-- range
pPosition:Init( fRange( Vec2(-25,-25), Vec2(25,25) )+dLocus );

-- Pick a velocity within a range
pVelocity:Init( fRange( Vec2(-20,-20), Vec2(20,20) ) );

-- Start scale at 0.5
pScale:Init(1);

-- Start age as 0 milliseconds
pAge:Init(0);

pColor:Init(Color(0.5,0,0,1));
pColor:Anim(fFade(pAge,Color(1.00,1.00,1.00,0.99),549,
      Color(1.00,1.00,1.00,0.08)));

--pScale:Anim(fRange(3.0,4.0));

-- Start initial rotation as a random angle
----pSpin:Init( fRange( 0, 2*3.1415927 ) );

-- Start spin velocity random from -10 to 10
pSpinSpeed:Init( fRange( -3, 3 ) );

-- Spin by pSpinSpeed scaled by time
--pSpin:Anim( pSpin + fTimeScale( pSpinSpeed ) );

pPosition:Anim( pPosition + fTimeScale(pVelocity) );

-- Add 1/second to scale
pScale:Anim( fFade(pAge,1.0,1000,1.0) );

-- Add gravity scaled by time to velocity
--pVelocity:Anim( pVelocity + fTimeScale(Vec2(0,250)) );


-- Set the particle's "Up" vector to the current user variable
-- "pSpin"
--pUp:Anim( f2dRotation( pSpin ) );

-- Age the particle using age function
pAge:Anim( pAge+fAge() );

-- General Anim functions
-- Expire particles over 700 ms old
Anim( fExpire( fGreater(pAge,200) ) );

-- expire after N seconds
expired = NewTimeout(0.3);

function Update(seconds)
   if not expired(seconds) then
      CreateParticles( seconds * gPPS );
   elseif GetParticleCount() <= 0 then
      gActiveParticles = -2;
      Done();      
   end
end

