Just like with the Enemy
class, we will create the emitter class in one batch:
ParticleEmitter
. Again, this one isn't extended from anything.Class ParticleEmitter
Field xp:Float Field yp:Float
Field timeLeft:Float
kind
field. Some particles will be colored, and so we need to tell the emitter to do that.Field kind:Int
New
constructor method will have the x
and y
positions as parameters. Also it will take the time
factor and the kind
flag as values.Method New(x:Float, y:Float, time:Int, knd:Int)
timeLeft = time xp = x yp = y kind = knd
STRICT
mode, our New
method doesn't need a return value:End
Update
method. The parameter will be a delta value, which will later be subtracted from the time that is left:Method Update:Bool(delta:Float)
timeLeft
. Then, check whether timeLeft
is still greater than 0
, which means that the emitter has to create a particle:timeLeft -= delta If timeLeft > 0 Then
Local obj:ftObject = g.eng.CreateImage(g.atlas,64,32,32,32,xp,yp)
obj.SetScale(Rnd(10,100)/100) obj.SetSpin(Rnd(-20,20))
Local vec:Float[] = obj.GetVector(Rnd(20,40),Rnd(360))
kind
flag is not 0
, set the color randomly:If kind <> 0 Then obj.SetColor(Rnd(255),Rnd(255),Rnd(255))
obj.SetLayer(g.layerGame)
obj.CreateTransPos(vec[0], vec[1], Rnd(1000,3000),False,g.tidParticle)
FALSE
so we can remove the particle emitter:Else Return False Endif
TRUE
so we know the emitter is still active, and close the method and the class:Return True End End
We created a class that lets us create an emitter with its own constructor method; we also created an update method that creates new particles, as long the emitter is active.
3.22.61.30