--------------------------------------------------------------------------------
-- Pedro Bolaņos - April 30, 2008
--
-- Particle system 1 for main menu.
--------------------------------------------------------------------------------

--[[ INITIALIZATION PHASE ]]

-- Create our custom variables
pVelocity = Allocate(2); 
pAge = Allocate(1);
pSpin = Allocate(1);
pSpinSpeed = Allocate(1);
lifetime = 5

-- Set the particles texture
SetTexture("level_select_particle")
SetBlendMode(kBlendNormal)

-- The maximun number of particles available
SetNumParticles(12);

--[[ ACTION PHASE ]]

-- Give initial values to some of the variables
fScale = 0.05;
-- The scale is initialized from C++
pScale:Init(fScale);
pPosition:Init(Vec2(620, 140));
pVelocity:Init(fRange(Vec2(-5, 45), Vec2(5, -0)));
pAge:Init(0)
pSpin:Init(0)
pSpinSpeed:Init(fRange(-2, 2));

-- Update the velocity and position
pVelocity:Anim(pVelocity + fTimeScale(fRange(Vec2(0, 0), Vec2(8, -50))));
pPosition:Anim(pPosition + fTimeScale(pVelocity));

-- Update the particles age
pAge:Anim(pAge + fAge());

-- Set the particles color according to their age
pColor:Anim(fFade(pAge, Color(0.5, 0.5, 0.5, 0), 2500, Color(1, 1, 1, 1.0), 2500, Color(1, 1, 1, 0.0)));

-- Make the particle bigger
pScale:Anim(pScale +  fTimeScale(0.07));

-- Update the rotation angle and make the particle rotate
pSpin:Anim(pSpin + fTimeScale(pSpinSpeed));
pUp:Anim(f2dRotation(fSpin));

-- Kill the particle if it's too old
Anim(fExpire(fGreater(pAge, lifetime * 1000)));

--[[ UPDATE FUNCTION ]]

CreateParticles(1);

function Update(seconds)
   CreateParticles(seconds * 4)
end
