---------------------------------------------------------------------
--   Author: Xavier Richter
--   Copyright (c) GIMAGIN 2009, All Rights Reserved.
--   mColorSmoke->GetLPS()->GetScript()->DoLuaString("gActive = not gActive;");
---------------------------------------------------------------------

gExplosion = false ;


function myFunction()

	pAge:Anim( pAge+fAge() );
	
	--Anim(fGreater()) ;
	
	Anim(fExpire(fGreater(fInScore(40,75,75,25,pX,pY),0)));

	pX0:Anim(fFade(pAge,pX,pStart,pX,1,pX0));
	pY0:Anim(fFade(pAge,pY,pStart,pY,1,pY0));

	pT:Anim(fFade(pAge,0,pStart-1,0,1,fClosedCycle(0,1,pStart+1300))); -- cycle execute when start this script with the fade. Time Fade must be equal to time cycle
	pX:Anim(fFade(pAge,fCloud(2) ,pStart-1,fCloud(2),1,fSpline(pT+pTAdvance,pX0,pX1,pMX0,pMX1)+fRange(-10,10)));
	pY:Anim(fFade(pAge,fCloud(4) ,pStart-1,fCloud(4),1,fSpline(pT+pTAdvance,pY0,pY1,pMY0,pMY1)+fRange(-10,10)));

	pPosition:Anim(fFade(pAge,f2dRotation(pSpin)*pRadius + Vec2(pX,pY),pStart,Vec2(pX,pY)));
	--Anim(fExpire(fLessEqual(pPosition,Vec2(pX1,pY1))));
	

	
end


-- 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]
---------------------------------------------------------------

-- Define our particle characteristics
pAge = Allocate(1) ; -- Allocate a TReal age member
pSpin = Allocate(1); -- Allocate a TReal spin member
pRadius = Allocate(1); -- Allocate a TReal radius member
pSpinSpeed = Allocate(1); -- Allocate a TReal spin member
pParticule = Allocate(40);

pX0 = Allocate(1);
pX1 = Allocate(1);
pY0 = Allocate(1);
pY1 = Allocate(1);
pMX0 = Allocate(1);
pMX1 = Allocate(1);
pMY0 = Allocate(1);
pMY1 = Allocate(1);
pT  = Allocate(1);
pTAdvance = Allocate(1);

pHandicap = Allocate(1);

pX = Allocate(1);
pY = Allocate(1);

pD = Allocate(1);

--Timer
pStart = Allocate(1);
pSpline = Allocate(1);


-- ------------------------------------------------------------
-- Phase 2 & 3 : Setting 
---------------------------------------------------------------
-- Set the particle texture
SetTexture("FeuFolet");
SetBlendMode(kBlendNormal);
SetNumParticles(20);    -- Create some particles

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

pRadius:Init( fRange( 20,120 ) ); --20/80
pColor:Init( Color(1,1,1,1) );
pScale:Init(1);
pAge:Init(0);
pSpin:Init( fRange( 0, 2*3.1415927 ) );
pSpinSpeed:Init( fRange( -10, 10 ) );

--pPosition:Init( f2dRotation(pSpin)*pRadius + Vec2(800,500)); 
pParticule:Init(1);
pD:Init(200);
pStart:Init(1000);
pSpline:Init(1000);

pX0:Init(fCloud(2)); -- center position registred into fCloud
pY0:Init(fCloud(4));
pX1:Init(70); -- score
pY1:Init(65);

pMX0:Init(fCos((3.14/4)) * pD);
pMY0:Init(fSin((-3.14/4)) * pD);
pMX1:Init(fCos((3.14/4)) * pD*3);
pMY1:Init(fSin((-3.14/4)) * pD*3);

pT:Init(0.0);
pTAdvance:Init(fRange(-0.50,0));


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

-- When you put a particle property in an equation, it returns an object 
-- that references the particle property that it represents.
-- Here it's pVelocity

pSpin:Anim( pSpin + fTimeScale( pSpinSpeed ) );
pScale:Anim( fRange(0.1,0.9) );
pColor:Anim( fFade( pAge,Color(1,1,1,0), 100, Color(1,1,1,0),2500, fPick(Color(1,1,1,1),Color(1,1,1,0.4)) ) );
pRadius:Anim(pRadius); --fFade( pAge,pRadius,pStart,pRadius - fTimeScale(1),1,pRadius));
Anim(myFunction());


--pPosition:Anim( pPosition );


pUp:Anim( f2dRotation( pSpin ) );
-- Add time to the age


-- Expire particles over 1500 ms old

--Anim( fExpire(fGreater(pAge,2500) ));


-- Create an initial particle
CreateParticles(20);

-- ------------------------------------------------------------
-- Phase 6 : Definition of an Update function that creates 
-- particles.
---------------------------------------------------------------

-- A function to run as we're executing
-- seconds - how many seconds have elapsed
function Update(seconds)
   -- Create 10 particles per second
   --CreateParticles( seconds * 0 );
end

