
gTexture = GUI_PickTexture("fx/bubble","Texture");

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

gEmitSpeed = GUI_Slider(
	60.70,
   "Particles Per Second",
   1,300);

gLifetime = GUI_Slider(
	0.90,
   "Lifetime",
   0,20);

gStartScale = GUI_Slider(
	0.05,
   "StartScale",
   0,3);

gEndScale = GUI_Slider(
	0.10,
   "EndScale",
   0,5);


gNumParticles = GUI_Slider(
   299.40,
   "NumParticles",
   1,300);

gPosRange = GUI_Slider(
	30.00,
   "PositionRange",
   0,400);

gMinYVel = GUI_Slider(
	-58.80,
   "Min Start Y Velocity",
   -800,800);

gMaxYVel = GUI_Slider(
	-248.00,
   "Max Start Y Velocity",
   -800,800);

gMinXVel = GUI_Slider(
	0.00,
   "Min Start X Velocity",
   -800,800);

gMaxXVel = GUI_Slider(
	0.20,
   "Max Start X Velocity",
   -800,800);

gMinYAnimVel = GUI_Slider(
   440.00,
   "Min Y Gravity",
   -800,800);

gMaxYAnimVel = GUI_Slider(
   633.60,
   "Max Y Gravity",
   -800,800);

gMinXAnimVel = GUI_Slider(
   0.00,
   "Min X Gravity",
   -800,800);

gMaxXAnimVel = GUI_Slider(
   10.00,
   "Max X Gravity",
   -800,800);

gMinSpinSpeed = GUI_Slider(
   0.00,
   "Min Spin Speed",
   -50,50);

gMaxSpinSpeed = GUI_Slider(
   0.00,
   "Max Spin Speed",
   -50,50);


gFadeOutTime = GUI_Slider(
	0.50,
   "Fade Out Time",
   0,5);




-- SLIDERS



-- ------------------------------------------------------------
-- Initialization phase

-- Define our custom particle properties
pVelocity = Allocate(2) ; -- Allocate a Vec2 velocity member
pAnimVelocity = Allocate(1); -- Allocate animated velocity
pAge = Allocate(1) ; -- Allocate a TReal age member
pSpin = Allocate(1); -- Allocate a TReal spin member
pSpinSpeed = Allocate(1); -- Allocate a TReal spin member

-- dLocus is a data source: An external connection to the particle
-- system. Here we define dLocus for FluidFX, since FluidFX doesn't know
-- to provide the data source; 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
if not dUp then
   dUp= Vec2(0,-1) ; 
end


-- Set the particle texture
SetTexture(gTexture);

-- Set the blend mode
SetBlendMode(gBlendMode);

-- LAST, we set the total number of particles in the particle
-- system. This doesn't 'create' the particles, but rather
-- allocates a block of 'dead' particles that can be created
-- below.
SetNumParticles(gNumParticles);    

-- ------------------------------------------------------------
-- Action Phase

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

-- Pick one of two positions randomly, and add dLocus.
-- dLocus is defined in swarm.cpp and added to the random
-- range
pPosition:Init( dLocus+fRange(Vec2(-gPosRange,-gPosRange),Vec2(gPosRange,gPosRange)) );

if (gMaxSpinSpeed == 0 and gMinSpinSpeed == 0) then
   pUp:Init(dUp);
else

   pSpin:Init( fRange( 0, 2*3.1415927 ) );
   pSpinSpeed:Init( fRange( gMinSpinSpeed, gMaxSpinSpeed ) );
   pSpin:Anim( pSpin + fTimeScale( pSpinSpeed ) );
   pUp:Anim( f2dRotation( pSpin ) );         
   
end
-- Pick a velocity from a range
pVelocity:Init( fRange(Vec2(gMinXVel, gMinYVel), Vec2(gMaxXVel, gMaxYVel)) );

-- Start color (tint) off as white (natural color of image)
pColor:Init( Color(1,1,1,0.2) );

-- Start scale out as 0.5
pScale:Init( gStartScale );

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

if ((gMinXAnimVel ~= 0 and gMaxXAnimVel ~= 0) or
    (gMinYAnimVel ~= 0 and gMaxYAnimVel ~= 0)) then
   pAnimVelocity:Init( fRange(Vec2(gMinXAnimVel, gMinYAnimVel), Vec2(gMaxXAnimVel, gMaxYAnimVel)));
   pVelocity:Anim(pVelocity + fTimeScale(pAnimVelocity) );
end



-- ------------------------------------------------------------
-- Particle Parameter Animation Functions
--
-- The following rules define how particles animate.
-- Each rule is applied on each frame of animation.

-- Add velocity scaled by time to position

kPAge = gLifetime * 1000;

if (gEndScale ~= gStartScale) then
   pScale:Anim( fFade( pAge, gStartScale, kPAge, gEndScale) );
end

if (gFadeOutTime ~= 0) then
   pColor:Anim( fFade( 
      pAge,Color(1,1,1,1),
      kPAge-(gFadeOutTime*1000), Color(1,1,1,0.5), 
      gFadeOutTime*1000, Color(1,1,1,0) ) );
end

-- Add time to the age
pAge:Anim( pAge+fAge() );

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

-- Expire particles over 1500 ms old
Anim( fExpire( fGreater(pAge,kPAge) ) );

-- Create an initial particle (optional)
-- CreateParticles( 1 );


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