-- Additional parameters

pVelocity = Allocate( 2 ) ;
-- pSpin = Allocate( 1 );
-- pSpinSpeed = Allocate( 1 );
-- pSpinSpeed2 = Allocate( 1 );
-- pFallDirection = Allocate( 1 );
-- pFallDistance = Allocate( 2 );
-- pTimes = Allocate( 3 );
-- pDirections = Allocate( 3);
pAge = Allocate( 1 );
pAge2 = Allocate( 1 );
pSpinSpeed = Allocate( 1 );
-- pFadeOut = Allocate ( 2 );
-- pAge2 = Allocate( 1 );
-- Set the particle texture
SetTexture("leaves_small.xml");
SetBlendMode(kBlendNormal);

-- Create some particles
SetNumParticles(100);    -- Create some particles

-- Init Particles
pPosition:Init( fRange(Vec2(-50,-10), Vec2(50,10))); -- initial position
pColor:Init( Color(1,1,1,1) ); -- blending color
pScale:Init( 1.0); -- initial size
-- CHANGE THIS TO CHANGE THE DIRECTION
pVelocity:Init( fRange( Vec2( -10, 10 ), Vec2( 10, 15 ) ) ) ; -- random velocity
-- pSpin:Init( fRange( 0, 2*3.1415927 ) ); -- random orientation
pSpinSpeed:Init( fRange( 300, 400 ) ); -- random spin speed



-- Move the particles
-- define the movement
pAge:Anim(  pAge + fAge()  );
-- fade out particle
pColor:Anim( fFade( pAge, Color(1,1,1,1), 7000, Color(1,1,1,1), 8000, Color(1,1,1,0) ) );

-- update movement
pPosition:Anim( pPosition + fTimeScale( pVelocity )  ); -- position update  40 scale the speed
-- pSpin:Anim( pSpin + fTimeScale( pSpinSpeed) ); -- spin update
-- pUp:Anim( f2dRotation( pSpin) ); -- particle orientation
pAge2:Anim(  fLess( pAge2, pSpinSpeed ) * pAge2 + fAge());
pFrame:Anim( fFade( pAge2, 0, pSpinSpeed, 3 ) );
-- Expire particles older than 8sec
Anim( fExpire( fGreater(pAge,  8000) ) );

-- intial
CreateParticles( 1 );
-- A function to run as we're executing
-- seconds - how many seconds have elapsed


-- USE THIS TO CHANGE THE AMOUNT OF LEAVES
-- CAN BE DONE IN THE CODE !!
LeavesPerSecond = 0.5;

function Update(seconds)
   -- Create 10 particles per second
   CreateParticles( seconds * LeavesPerSecond );
end

