-- Allocate Initial Variables
pAge = Allocate( 1 );
pVelocity = Allocate( 2 );

-- Set Texture/BlendMode
SetTexture( "particles/mouse" );
SetBlendMode( kBlendNormal );

-- Max Particle Count
SetNumParticles( 400 );

dVelocity = 50;
dMaxAge = 750;
dVarSize = 10;
dRed = 1;
dGreen = 0.9;
dBlue = 0.9;

if not dMouse then
   dMouse = Vec2( 300, 300 );
end

if not dMousePrevious then
   dMousePrevious = Vec2( 300, 300 );
end

-- Initial Values
pColor:Init( Color( dRed, dGreen, dBlue, 1 ) );
pAge:Init( 0 );
pPosition:Init( fRange( dMouse - dVarSize, dMouse + dVarSize ) );
pScale:Init( fRange( 0.25, 0.75 ) );
pVelocity:Init( Vec2( fRange( -dVelocity, dVelocity ), fRange( -dVelocity, dVelocity ) ) );

-- Animated Values
pScale:Anim( pScale + fRange( -0.05, 0.05 ) );
pColor:Anim( fFade( pAge, Color( dRed, dGreen, dBlue, 1 ), dMaxAge, Color( dRed, dGreen, dBlue, 0 ) ) );
pPosition:Anim( pPosition + fTimeScale( pVelocity ) );

-- Increment Age
pAge:Anim( pAge + fAge() );

Anim( fExpire( fGreater( pAge, dMaxAge ) ) );

-- Only fire if gActive is true ( can be set in code )
gActive = 0;
gDistance = 0;

function Update( seconds )
    if gActive > 0 then
    	if gDistance * seconds > 1.5 * 0.016 then
        	CreateParticles( gDistance * seconds * 4 );
        end
        
        gActive = 0;
    end
end