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

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

mSectorWidth = GUI_Slider(
   120.00,
      "Emit Sector Width",
      0,360);

mMinSpeed = GUI_Slider(
   20.00,
      "Min Speed",
      0,200);

mMaxSpeed = GUI_Slider(
   30.00,
      "Max Speed",
      0,200);

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

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

mTextureName = GUI_PickTexture("fx/world3/bud_3_particle","Particle Texture");

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

-- ------------------------------------------------------------
-- Globals & constants

gActive = true;

PI = 3.1415926536;
mSectorHalfRad = (mSectorWidth / 2) / 180 * PI;

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

pDirection = Allocate(2) ; -- Allocate a Vec2 velocity member
pVelocity = Allocate(2) ; -- Allocate a Vec2 velocity member
pAge = Allocate(1) ; -- Allocate a TReal age member
pStartScale = Allocate(1);


-- Set the particle texture
SetTexture(mTextureName);

-- Set the blend mode
SetBlendMode(mBlendMode);

-- Set the total number of particles in the system.
SetNumParticles(mEmitSpeed * (mLifetime + 1));

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

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

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

pDirection:Init(f2dRotation(fRange(-mSectorHalfRad, mSectorHalfRad) + PI / 2));
pPosition:Init(pDirection * fRange(10, 20) + dLocus);
pVelocity:Init(pDirection * fRange(mMinSpeed, mMaxSpeed));

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

pAge:Init(0);

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

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

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
