mLifetime = GUI_Slider(
   0.40,
      "Particle Lifetime",
      0.1,3.0);

mEmitSpeed = GUI_Slider(
   20.00,
      "Emitter Speed",
      0,200);

mMinPositionSpread = GUI_Slider(
   0.00,
      "Min Position Spread",
      0,100);

mMaxPositionSpread = GUI_Slider(
   0.00,
      "Max Position Spread",
      0,100);

mMinSpeed = GUI_Slider(
   71.00,
      "Min Speed",
      -500,500);

mMaxSpeed = GUI_Slider(
   310.00,
      "Max Speed",
      -500,500);

mDirection = GUI_Slider(
   270.88,
      "Direction Angle",
      0,360.0);

mAngleSpread = GUI_Slider(
   20.08,
      "Direction Spread",
      0,360.0);

mGravity = GUI_Slider(
   1500.00,
      "Gravity",
      -1500,1500);

mStartScale = GUI_Slider(
   1.00,
      "Start Scale",
      0,10.0);

mEndScale = GUI_Slider(
   0.50,
      "End Scale",
      0,10.0);

mStartAlpha = GUI_Slider(
   57.12,
      "Start Alpha",
      0,255);

mEndAlpha = GUI_Slider(
   52.78,
      "End Alpha",
      0,255);

mTextureName = GUI_PickTexture("fx/world1/water_dark","Particle Texture");

mBlendMode = GUI_Select(
   kBlendAdditiveAlpha,
      "Blend Mode",
      {
         { description="Normal", value=kBlendNormal},
         { description="Additive", value=kBlendAdditiveAlpha}
      }
);

-- ------------------------------------------------------------
-- Globals

gActive = true;
gStop = 0;

PI = 3.1415926536;

gStartColor = Color(1, 1, 1, mStartAlpha / 255);
gEndColor = Color(1, 1, 1, mEndAlpha / 255);

gMinAngle = (mDirection - mAngleSpread / 2) * PI / 180;
gMaxAngle = (mDirection + mAngleSpread / 2) * PI / 180;

-- ------------------------------------------------------------
-- Define our particle characteristics

pVelocity = Allocate(2) ; -- Allocate a Vec2 velocity member
pAge = Allocate(1) ; -- Allocate a TReal age member
pAlpha = Allocate(1);
pSpin = Allocate(1);
pSpinSpeed = Allocate(1);


-- Set the particle texture
SetTexture(mTextureName);

-- Set the blend mode
SetBlendMode(mBlendMode);

-- 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(mEmitSpeed * mLifetime + 1);
--SetNumParticles(mMaxParticles);

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


--pPosition:Init(Vec2(fRange(-5, 5), fRange(-5, 5)) + dLocus);
pPosition:Init(f2dRadius(fRange(mMinPositionSpread, mMaxPositionSpread)) + dLocus);

-- Pick a velocity within a range
pVelocity:Init(f2dRotation(fRange(gMinAngle, gMaxAngle)) * fRange(mMinSpeed, mMaxSpeed));

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

pSpin:Init(fRange(0, 2 * PI));
pSpinSpeed:Init(fRange(-PI, PI));

-- Start scale at 0.5
pColor:Init(gStartColor);

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

-- ------------------------------------------------------------
-- 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
pPosition:Anim( pPosition + fTimeScale(pVelocity) );

-- Add 1/second to scale
pScale:Anim(pScale + fTimeScale((mEndScale - mStartScale) / mLifetime));

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

pSpin:Anim(pSpin + fTimeScale(pSpinSpeed));
pUp:Anim(f2dRotation(pSpin));

--pAlpha:Anim(pAlpha + fTimeScale((mAlpha2 - mAlpha1) / mLifetime));
pColor:Anim(pColor + fTimeScale((gEndColor - gStartColor) / mLifetime));
--pColor:Anim(Color(1, 1, 1, pAlpha));

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

-- General Anim functions
Anim(fExpire(fGreater(pAge, mLifetime * 1000)));
-- ------------------------------------------------------------
-- Create initial particles (optional)
-- CreateParticles( 1 );

-- ------------------------------------------------------------

-- A function to run as we're executing
-- seconds - how many seconds have elapsed

function Update(seconds)
   if gActive  then
         CreateParticles(seconds * mEmitSpeed);
   end -- gActive
end
