Global totalparticles;Total number of particles ever created
Type emitter
Field pt
Field mx#,my#,mz#
Field rmx#,rmy#,rmz#
Field pitch#,yaw#,roll#
Field rpitch#,ryaw#,rroll#
Field fade
End Type
Type particle
Field sprite
Field emitter
Field mx#,my#,mz#
Field pitch#,yaw#,roll#
Field alpha#
Field fade
Field life
Field ctime
Field id
End Type
Function createemitter(mx#,my#,mz#,pitch#,yaw#,roll#,rm#=0,rr#=0,fade=True);Create an emitter
e.emitter=New emitter
ept=CreatePivot();emitter entity
;particle motion and rotation(including random amounts)
emx=mx
emy=my
emz=mz
e
mx=rm
e
my=rm
e
mz=rm
epitch=pitch
eyaw=yaw
e
oll=roll
e
pitch=rr
e
yaw=rr
e
roll=rr
efade=fade;particle fading
Return ept
End Function
Function createparticle(emitter,life#);Create a particle
;get the emitter
For e.emitter=Each emitter
If ept=emitter
a=Handle(e.emitter)
EndIf
Next
emtr.emitter=Object.emitter(a)
If emtr.emitter=Null RuntimeError "Emitter doesn't exist";stop the program if the emitter doesn't exist
totalparticles=totalparticles+1;update the particle count
TFormVector emtrmx,emtrmy,emtrmz,emtrpt,0;keep the particle on track no matter what the emitter's rotation
p.particle=New particle
psprite=CreateSprite()
pemitter=emitter
;particle movement and rotation values
pmx=TFormedX()+Rnd(-(emtr
mx),emtr
mx)
pmy=TFormedY()+Rnd(-(emtr
my),emtr
my)
pmz=TFormedZ()+Rnd(-(emtr
mz),emtr
mz)
ppitch=emtrpitch+Rnd(-(emtr
pitch),emtr
pitch)
pyaw=emtryaw+Rnd(-(emtr
yaw),emtr
yaw)
p
oll=emtr
oll+Rnd(-(emtr
roll),emtr
roll)
palpha=1
;particle fading and life values
pfade=emtrfade
plife=life
pctime=MilliSecs()
pid=totalparticles;used for getparticle
PositionEntity psprite,EntityX(emtrpt),EntityY(emtrpt),EntityZ(emtrpt)
Return psprite
End Function
Function particlealpha(particle,alpha#);changes the particles base alpha (required for proper fading)
For p.particle=Each particle
If psprite=particle palpha=alpha;set the particle's base alpha to alpha
Next
End Function
Function updateparticles();update every particle's movement, rotation, and fading
For p.particle=Each particle
If p.particle<>Null
TranslateEntity psprite,pmx,pmy,pmz
TurnEntity psprite,ppitch,pyaw,p
oll
If pfade=True;if the particle is supposed to fade out of existence
alpha#=palpha-(palpha*(MilliSecs()-pctime)/plife)
EndIf
EntityAlpha psprite,alpha
If alpha<=0;if the particle's alpha is zero or less
freeparticle(psprite)
EndIf
EndIf
Next
End Function
Function countparticles(emitter);returns the number of particles produced by an emitter currently in existence
For p.particle=Each particle
If pemitter=emitter;if emitter is the particle's emitter
cnt=cnt+1
EndIf
Next
Return cnt
End Function
Function getparticle(id);
For p.particle=Each particle
If p.particle<>Null And pid=id;if the particle exists and it's id equals id
Return psprite
EndIf
Next
End Function
Function partmovex#(particle);returns a particle's x movement
For p.particle=Each particle
If p.particle<>Null And psprite=particle;if the particle exists and it's sprite is the supplied particle
Return pmx
EndIf
Next
End Function
Function partmovey#(particle);returns a particle's y movement
For p.particle=Each particle
If p.particle<>Null And psprite=particle;if the particle exists and it's sprite is the supplied particle
Return pmy
EndIf
Next
End Function
Function partmovez#(particle);returns a particle's z movement
For p.particle=Each particle
If p.particle<>Null And psprite=particle;if the particle exists and it's sprite is the supplied particle
Return pmz
EndIf
Next
End Function
Function partpitch#(particle);returns a particle's pitch rotation
For p.particle=Each particle
If p.particle<>Null And psprite=particle;if the particle exists and it's sprite is the supplied particle
Return ppitch
EndIf
Next
End Function
Function partyaw#(particle);returns a particle's yaw rotation
For p.particle=Each particle
If p.particle<>Null And psprite=particle;if the particle exists and it's sprite is the supplied particle
Return pyaw
EndIf
Next
End Function
Function partroll#(particle);returns a particle's roll rotation
For p.particle=Each particle
If p.particle<>Null And psprite=particle;if the particle exists and it's sprite is the supplied particle
Return p
oll
EndIf
Next
End Function
Function modifyparticle(particle,mx#,my#,mz#,pitch#=0,yaw#=0,roll#=0,life=1000,fade=True,rel=False);changes a particle after it's created
For p.particle=Each particle
If p.particle<>Null And psprite=particle;if the particle exists and it's sprite is the supplied particle
If rel=False;if the change isn't relative
pmx=mx
pmy=my
pmz=mz
ppitch=pitch
pyaw=yaw
p
oll=roll
plife=life
pfade=fade
Else;if it is
pmx=pmx+mx
pmy=pmy+my
pmz=pmz+mz
ppitch=ppitch+pitch
pyaw=pyaw+yaw
p
oll=p
oll+roll
plife=plife+life
If fade=False pfade=Not pfade
EndIf
EndIf
Next
End Function
Function freeparticle(particle);removes a particle
For p.particle=Each particle
If psprite=particle
FreeEntity psprite
Delete p
EndIf
Next
End Function
Function modifyemitter(emitter,mx#,my#,mz#,pitch#=0,yaw#=0,roll#=0,rm#=0,rr#=0,fade=True,rel=False);changes an emitter after it's created
;get the emitter
For e.emitter=Each emitter
If ept=emitter
a=Handle(e.emitter)
EndIf
Next
emtr.emitter=Object.emitter(a)
If emtr.emitter=Null RuntimeError "Emitter doesn't exist";stop the program if the emitter doesn't exist
If rel=False;if the change isn't relative
emtrmx=mx
emtrmy=my
emtrmz=mz
emtr
mx=rm
emtr
my=rm
emtr
mz=rm
emtrpitch=pitch
emtryaw=yaw
emtr
oll=roll
emtr
pitch=rr
emtr
yaw=rr
emtr
roll=rr
emtrfade=fade
Else;if it is
emtrmx=emtrmx+mx
emtrmy=emtrmy+my
emtrmz=emtrmz+mz
emtr
mx=emtr
mx+rm
emtr
my=emtr
my+rm
emtr
mz=emtr
mz+rm
emtrpitch=emtrpitch+pitch
emtryaw=emtryaw+yaw
emtr
oll=emtr
oll+roll
emtr
pitch=emtr
pitch+rr
emtr
yaw=emtr
yaw+rr
emtr
roll=emtr
roll+rr
If fade=True emtrfade=Not emtrfade
EndIf
End Function
Function modifyemitterrnd(emitter,rmx#,rmy#,rmz#,rpitch#,ryaw#,rroll#);change an emitter's random values in depth
;get the emitter
For e.emitter=Each emitter
If ept=emitter
a=Handle(e.emitter)
EndIf
Next
emtr.emitter=Object.emitter(a)
emtr
mx=rmx
emtr
my=rmy
emtr
mz=rmz
emtr
pitch=rpitch
emtr
yaw=ryaw
emtr
roll=rroll
End Function
Function freeemitter(emitter);removes an emitter
For e.emitter=Each emitter
If ept=emitter
FreeEntity ept
Delete e
EndIf
Next
End Function
Function clearparticlesystem();removes the entire particle system
For e.emitter=Each emitter
If e<>Null
If ept=True FreeEntity ept
Delete e
EndIf
Next
For p.particle=Each particle
If p<>Null
If psprite=True FreeEntity psprite
Delete p
EndIf
Next
End Function