--------------------------------------------------------------------------------
-- Pedro Bolaņos - June 21, 2008
--
-- Particle system for the snow
--------------------------------------------------------------------------------

--[[ INITIALIZATION PHASE ]]

-- Create our custom variables
pVelocity = Allocate(2); 
pAge = Allocate(1);
lifetime = 4000

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

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

--[[ ACTION PHASE ]]

-- Give initial values to some of the variables
fScale = 0.04
-- The scale is initialized from C++
pScale:Init(fScale);
pPosition:Init(fRange(Vec2(-145, 0), Vec2(145, 10)));
pVelocity:Init(fRange(Vec2(0, 5), Vec2(0, 20)));
pAge:Init(0)

-- Update the velocity and position
pVelocity:Anim(pVelocity + fTimeScale(fRange(Vec2(-50, 1), Vec2(50, 5))));
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(1, 1, 1, 1), 3500, Color(1, 1, 1, 0.8), 500, Color(1, 1, 1.0, 0.0)));

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

--[[ UPDATE FUNCTION ]]
function Update(seconds)
   CreateParticles(seconds * 5)
end
