---------------------------------------------------------------------
--	Author: Xavier Richter
--	Copyright (c) GIMAGIN 2009, All Rights Reserved.
---------------------------------------------------------------------



-- Phases to follow

-- 1) Create any custom particle properties.
-- 2) Set the particle texture and blend mode.
-- 3) Set the number of particles in the system.
-- 4) Set up the particle initializer functions.
-- 5) Set up the particle animation functions.
-- 6) Define an Update function that creates particles.

-- The order of the first three operations above is strict; 
-- the rest are just by convention

-- All functions accessible into this script are defined into
-- Lua Particle System Reference.

-- C++ is defined into <pf/luaparticlesystem.h> 

-- See the documentation for more information

-- ------------------------------------------------------------
-- Phase 1 : Initialization

-- Default particle property : 
   -- pPosition : A 2d Position TReal[2]
   -- pUp : A 2d Up-vector where 0,-1 make a particle "upright" TReal[2]
   -- pScale : A scale TReal[1]
   -- pColor : An RGBA color TReal[4] 
   -- pFrame : A frame for use with animated particles. TReal[1]
---------------------------------------------------------------


-- age is the life time
pAge = Allocate(1) ; -- Allocate a TReal age member


-- dLocus is a data source. The new FluidFX 2.0 defines dLocus for us,
-- but in case you want to load this particle system in a context
-- where you have no data source defined, this code will give dLocus
-- a default value.
-- dLocus represented a emission source
if not dLocus then
   dLocus= Vec2(0,0) ;
end



-- ------------------------------------------------------------
-- Phase 2 & 3 : Setting 
---------------------------------------------------------------
-- Set the particle texture
SetTexture("find");

-- Set the blend mode
SetBlendMode(kBlendNormal);

-- Set the size of the particle pool.
SetNumParticles(1);


-- ------------------------------------------------------------
-- Phase 4 : Action
---------------------------------------------------------------

-- Pick : select a point 10 pixels to the left(-10) or 10 pixels to the right(10) 
-- dLocus represented the emission source
pPosition:Init( Vec2(fCloud(2),fCloud(4)) );--dLocus  );

-- Start color (tint) off as white (natural color of image)
pColor:Init( Color(1,1,1,1) );

-- Start age as 0 milliseconds
pAge:Init(0);

-- Start animation as 0 frame
pFrame:Init(0);

pScale:Init(1);

-- ------------------------------------------------------------
-- Phase 5 : Particle Parameter Animation Functions
---------------------------------------------------------------

-- fTimeScale(Vec2(0,400) --> add a fractionnal velocity position 
-- which is stored in pixels/second 
pPosition:Anim( pPosition );
   

-- adjust particle age
pAge:Anim( pAge+fAge() );

-- Animation
	pFrame:Anim(fClosedCycle(1,15,70));

Anim(fExpire(fGreater(pAge,15*70)));

CreateParticles(1);
