
-- ALLOC

pVelocity = Allocate(2)
pSpin = Allocate(1)
pSpinSpeed = Allocate(1)
pAge = Allocate(1)

-- INIT

if not dLocus then
   dLocus = Vec2(0, 0)
end

if not dRect then
   dRect = Allocate(4)
end

SetTexture("gfx/circle")
SetBlendMode(kBlendAdditiveAlpha)
SetNumParticles(400)

pScale:Init(0.05)
pColor:Init(Color(1, 1, 1, 0))

pPosition:Init(fRange(Vec2(dRect[1], dRect[2]), Vec2(dRect[3], dRect[4])) + dLocus)
--pPosition:Init(fRange(Vec2(0, 0), Vec2(0, 0)) + dLocus)

local vx = 20
local vy = 20
pVelocity:Init(fRange(Vec2(-vx, -vy), Vec2(vx, vy)))

pSpin:Init(fRange(0, 2 * 3.1415927))
pSpinSpeed:Init(fRange(-10, 10))
pAge:Init(0)

-- ANIM

--pScale:Anim(pScale + fTimeScale(0.1))
pColor:Anim(fFade(pAge, 
   Color(1, 1, 1, 0.1), 
   1000, Color(1, 1, 1, 0.2), 
   4000, Color(1, 1, 1, 0.2), 
   4000, Color(1, 1, 1, 0)
))

pPosition:Anim(pPosition + fTimeScale(pVelocity))
pVelocity:Anim(pVelocity + fTimeScale(Vec2(0, 0)))
pSpin:Anim(pSpin + fTimeScale(pSpinSpeed))
pUp:Anim(f2dRotation(pSpin))
pAge:Anim(pAge + fAge())

Anim(fExpire(fGreater(pAge, 15000)))

gActive = true
function Update(seconds)
   if gActive then
      CreateParticles(seconds * 20)
   end
end
