so I've been given some code to play with and it works great by itself but I need to convert it into a function to work in the game.
code in question is a particle system ( for fireworks effects )
code is using the blitz3d engine
I will supply full source code of the game and am usually online to answer questions.
## Deliverables
so I've been given some code to play with and it works great by itself but I need to convert it into a function to work in the game.
[code]
; lesson 8, random particle
Graphics3D 800,600,16,2
SetBuffer BackBuffer()
Rnd MilliSecs()
campivot=CreatePivot()
camera=CreateCamera(campivot)
MoveEntity camera,0,10,-30
ground=CreatePlane()
groundt=LoadTexture("[login to view URL]")
ScaleTexture groundt,20,20
EntityTexture ground,groundt
CameraClsColor camera,70,130,210
;====================================================
particle1=LoadSprite("World/Sprites/TFX/[login to view URL]",2)
EntityAlpha particle1,0
particle2=LoadSprite("World/Sprites/TFX/[login to view URL]",2)
EntityAlpha particle2,0
particle3=LoadSprite("World/Sprites/TFX/[login to view URL]",2)
EntityAlpha particle3,0
particle4=LoadSprite("World/Sprites/TFX/[login to view URL]",2)
EntityAlpha particle4,0
Type particle
Field physicalparticle
Field x,y,z
Field rp,ry,rr
Field speed#
Field life#
End Type
frametimer=CreateTimer(60)
;====================================================
; Main loop
While Not KeyHit(1)
WaitTimer(frametimer)
If KeyHit(57) cuepyro=1
If cuepyro=1 Then
For a=1 To 500
; Create
spark.particle=New particle
particlepick=Rnd(1,4) ; ranom pick of 4 types of particle
If particlepick=1 spark\physicalparticle=CopyEntity(particle1)
If particlepick=2 spark\physicalparticle=CopyEntity(particle2)
If particlepick=3 spark\physicalparticle=CopyEntity(particle3)
If particlepick=4 spark\physicalparticle=CopyEntity(particle4)
; Position
spark\x=0
spark\y=10
spark\z=0
PositionEntity spark\physicalparticle,spark\x,spark\y,spark\z
; Aim
spark\rp=Rnd(1,360)
spark\ry=Rnd(1,360)
spark\rr=Rnd(1,360)
RotateEntity spark\physicalparticle,spark\rp,spark\ry,spark\rr
; Life
spark\life#=Rnd(0.1,1.0) ; added variable life again to show the counter at work better
EntityAlpha spark\physicalparticle,spark\life#
; Speed
spark\speed#=Rnd(0.03,0.2)
;
particlecount=particlecount+1 ; each time it creates a particle we will increase the counter by 1
PlaySound "[login to view URL]"
Next
cuepyro=0
EndIf
For spark.particle=Each particle
spark\life#=spark\life#-0.01
MoveEntity spark\physicalparticle,0,spark\speed#,0
EntityAlpha spark\physicalparticle,spark\life#
If spark\life<0.01 Then
FreeEntity spark\physicalparticle
Delete spark
particlecount=particlecount-1 ; each time we kill a particle we will decrease the counter by 1
EndIf
Next
If particlecount <=0 And pyrun <=5
cuepyro=1
pyrun = pyrun +1
EndIf
UpdateWorld
RenderWorld
Text 20,20,"Active Particles= "+particlecount ; pretty sure there is a way to just count all active particles but for now this method will suffice
Text 35,35,"Run Count= "+pyrun
Flip
;TurnEntity campivot,0,1,0
Wend
End
[/code]
i tried this...
[code]
Function pyro()
;====================================================
particle1=LoadSprite("[login to view URL]",2)
EntityAlpha particle1,0
particle2=LoadSprite("[login to view URL]",2)
EntityAlpha particle2,0
particle3=LoadSprite("[login to view URL]",2)
EntityAlpha particle3,0
particle4=LoadSprite("[login to view URL]",2)
EntityAlpha particle4,0
End Function
Type particle
Field physicalparticle
Field x,y,z
Field rp,ry,rr
Field speed#
Field life#
End Type
Function pyro2()
If cuepyro=1 Then
For pyroa=1 To 500
; Create
spark.particle=New particle
particlepick=Rnd(1,4) ; ranom pick of 4 types of particle
If particlepick=1 spark\physicalparticle=CopyEntity(particle1)
If particlepick=2 spark\physicalparticle=CopyEntity(particle2)
If particlepick=3 spark\physicalparticle=CopyEntity(particle3)
If particlepick=4 spark\physicalparticle=CopyEntity(particle4)
; Position
spark\x=0
spark\y=10
spark\z=0
PositionEntity spark\physicalparticle,spark\x,spark\y,spark\z
; Aim
spark\rp=Rnd(1,360)
spark\ry=Rnd(1,360)
spark\rr=Rnd(1,360)
RotateEntity spark\physicalparticle,spark\rp,spark\ry,spark\rr
; Life
spark\life#=Rnd(0.1,1.0) ; added variable life again to show the counter at work better
EntityAlpha spark\physicalparticle,spark\life#
; Speed
spark\speed#=Rnd(0.03,0.2)
;
particlecount=particlecount+1 ; each time it creates a particle we will increase the counter by 1
PlaySound "[login to view URL]"
Next
cuepyro=0
EndIf
For spark.particle=Each particle
spark\life#=spark\life#-0.01
MoveEntity spark\physicalparticle,0,spark\speed#,0
EntityAlpha spark\physicalparticle,spark\life#
If spark\life<0.01 Then
FreeEntity spark\physicalparticle
Delete spark
particlecount=particlecount-1 ; each time we kill a particle we will decrease the counter by 1
EndIf
Next
If particlecount <=0 And pyrun <=5
cuepyro=1
pyrun = pyrun +1
EndIf
End Function
[/code]