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

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

mEmitRadius = GUI_Slider(
   50.00,
      "Emitter Radius",
      0,200);

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

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

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

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

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

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

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

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

gActive = true;

gStartColor = Color(1, 1, 1, 0.3);
gEndColor = Color(1, 1, 1, 0.2);

PI = 3.1415926536;

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

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


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

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

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

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

pPosition:Init(f2dRadius(fRange(0, mEmitRadius)) + dLocus);

pVelocity:Init(fRange(Vec2(0, mMinSpeedY), Vec2(0, mMaxSpeedY)));

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

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

pColor:Init(gStartColor);

pAge:Init(0);

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

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

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

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

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

pColor:Anim(pColor + fTimeScale((gEndColor - gStartColor) / 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
