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

mEmitSpeed = GUI_Slider(
   100.00,
      "Emitter Speed",
      0,500);

mPath = GUI_Graph(
   {
      Vec2(338.00,176.00),285,
      Vec2(483.01,164.00),2,
      Vec2(484.00,164.02),387,
      Vec2(676.00,167.66),37,
      Vec2(689.68,168.00),290,
      Vec2(798.00,122.00)
   },
   Vec2(0.00,0.00),
   Vec2(1024.00,768.00),

   {
      {338.00,176.00,time=0.00},
      {nil,164.00,time=284.80},
      {484.00,nil,time=286.74},
      {676.00,nil,time=673.29},
      {nil,168.00,time=709.91},
      {798.00,122.00,time=1000.00}
   },
   "Path");

mPathWidth = GUI_Slider(
   8.00,
      "Path Width",
      0,50);

mMinSpeedY = GUI_Slider(
	-8.00,
      "Min Speed Y",
      -500,500);

mMaxSpeedY = GUI_Slider(
	8.00,
      "Max Speed Y",
      -500,500);

mGravity = GUI_Slider(
   0.00,
      "Gravity",
      -500,500);

mMinScale = GUI_Slider(
   0.70,
      "Min Scale",
      0,3.0);

mMaxScale = GUI_Slider(
   0.70,
      "Max Scale",
      0,3.0);

mTextureName = GUI_PickTexture("fx/map/path_particle","Particle Texture");

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

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

gActive = true;

PI = 3.1415926536;

gEmitSpeed = fDistance(gPathBegin, gPathEnd);

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

pVelocity = Allocate(2);
pAge = Allocate(1);
pStartScale = 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));

-- ------------------------------------------------------------
-- External params.

if not dLocus then
   dLocus = Vec2(0, 0);
end

-- ------------------------------------------------------------
-- Initialization

pPosition:Init(fFade(fRange(0, 1000), toparams(mPath)) + f2dRadius(fRange(0, mPathWidth)));
pVelocity:Init(Vec2(0, fRange(mMinSpeedY, mMaxSpeedY)));

pStartScale:Init(fRange(mMinScale, mMaxScale));
pScale:Init(pStartScale);

pAge:Init(0);

-- ------------------------------------------------------------
-- Animation

pPosition:Anim(pPosition + fTimeScale(pVelocity));
pVelocity:Anim(pVelocity + fTimeScale(Vec2(0, mGravity)));

pScale:Anim(pScale - fTimeScale(pStartScale / mLifetime));

pAge:Anim(pAge + fAge());
Anim(fExpire(fGreater(pAge, mLifetime * 1000)));

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