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

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

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

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

mAlpha = GUI_Graph(
	{
		0.00,100,
		0.25,650,
		0.25,250,
		0.00
	},
	0.00,
	1.00,
	{
		{0.00,time=0.00},
		{0.25,time=100.00},
		{0.25,time=750.00},
		{0.00,time=1000.00}
	},
	"Alpha");

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

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

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

gActive = true;
gStop = 0;

PI = 3.1415926536;

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

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

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

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

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

pPosition:Init(Vec2(fRange(-10, 10), 0) + dLocus);

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

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

pAge:Init(0);

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

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

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

pColor:Anim(fAlpha(pColor, fFade(pAge / mLifetime, toparams(mAlpha))));

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 or gStop > 0 then
      if gStop == 0 then
         CreateParticles(seconds * mEmitSpeed);
      else
         if GetParticleCount() == 0 then
            Done();
         end
      end
   end -- gActive
end
