I just put this in the code base. I want to polish it up some more, but maybe it'll be a good start for someone. Any recommendations on how to improve would be welcome.
[Edit] updated with Jack's line.
Here's a full app
` This code was downloaded from The Game Creators
` It is reproduced here with full permission
` http://www.thegamecreators.com
`Fire particle effect (edited from smoke particle effect)
`By Joseph Thomson
`24/12/03
`Modified By Ankillito
`April 9, 2007
`The Typical Setup
sync on
sync rate 40
backdrop on
color backdrop rgb(0,0,0)
position camera 0,20,-50
autocam off
`Easy to put in your oun games.
GoSub _FlameSetup `Required Setup
do
GoSub _FlameLoop `Must to before each sync
if upkey() = 1 then move object FlameID, 1
if downKey() = 1 then move object FlameID,-1
if leftkey() = 1 then turn object left FlameID,1
if RightKey() = 1 then Turn object right FlameID, 1
sync
loop
_FlameSetup:
`The Setup for Ankillito's Flame System
`Tweak these Parameters to get a different flame
FlameCount = 50 `How many particles
FlameID = 1 `A free object ID #, each particle ID is above this: 1,1+1,1+2,1+3,1+4
`FlameID is an actuall object number that can be moved and rotated: it's actually a cube
`The Fire is attached to this object.
ImageID = 1 `A free ID for an Image AND a Bitmap
FlameSize# = 12 `Size of each particle
FlameRadius# = 10 `Maximum Radius of Flame
FlameHeight# = 40 `Maximum Height of Flame
FlameSpeed# = 1 `Speed of Flame
FlameTapper# = 0.97 `How fast tappers as it goes up
FlameDim# = 3 `How fast it dims as it goes up
FlameShrink# = 1.25 `How fast each particle shrinks as it goes up
`Type for Flame Array
Type Flame
ID
Radius#
Degree
Depth#
Size#
Fade#
EndType
`This the object with ID# of "FlameID" as set above
Make object cube FlameID,1
hide object FlameID
`Thanks to Joseph Thomson for this part
`Create fire image
create bitmap ImageID,50,50
ink rgb(200,130,30),0
`Draw random dots in a circle shape
for x=1 to 1000
ang=rnd(360)
rad=rnd(20)
dot 25+sin(ang)*rad,25+cos(ang)*rad
next x
`Blur fire image
blur bitmap ImageID,3
get image ImageID,0,0,50,50
delete bitmap ImageID
`Set up array type and put it's values in.
Dim Flame(FlameCount) as Flame
for i = 1 to FlameCount
Flame(i).Radius# = rnd(flameRadius# * 100)
Flame(i).Radius# = Flame(i).Radius# / 100
Flame(i).Degree = rnd(359)
Flame(i).Depth# = rnd(FlameHeight#)
Flame(i).ID = FlameID + i
make object plain Flame(i).ID, FlameSize#, FlameSize#
texture object Flame(i).ID,ImageID
set object ambient Flame(i).ID,0
set object transparency Flame(i).ID,1
Ghost Object on Flame(i).ID
Disable object zwrite Flame(i).ID
Next i
`End of setup
Return
_FlameLoop:
`The action of the Flame
for i = 1 to FlameCount `Loop through array
If Flame(i).Depth# > FlameHeight# `Reset particle if it reached the top
Flame(i).Radius# = rnd(flameRadius# * 100)
Flame(i).Radius# = Flame(i).Radius# / 100
Flame(i).Degree = rnd(359)
Flame(i).Depth# = 0
Flame(i).Fade# = 200
Flame(i).Size# = 100
endif
`Move Particle up
Flame(i).Depth# = Flame(i).Depth# + FlameSpeed#
`Fade particle value
Flame(i).Fade# = Flame(i).Fade# - FlameDim#
`Smaller radius at top
Flame(i).Radius# = Flame(i).Radius# * FlameTapper#
`Shrink Particles
Flame(i).Size# = Flame(i).Size# - FlameShrink#
`Set Position base on object FlameID
Position Object Flame(i).ID, object position x(FlameID),object position y(flameID),object position Z(FlameID)
Set object to object orientation Flame(i).ID, FlameID
Move object Right Flame(i).ID, cos(Flame(i).Degree) * Flame(i).Radius#
Move Object UP Flame(i).ID, Flame(i).Depth#
Move Object Flame(i).ID, Sin(Flame(i).Degree) * Flame(i).Radius#
`Scal object
scale object Flame(i).ID,flame(i).size#,Flame(i).size#,100
`Fade object
fade object Flame(i).ID,Flame(i).Fade#
`"Point at camera" this was Joseph Thomson's coment, but it actually points away from camera
`I tried actually pointing it at the camera, and it doesn't look too cool.
set object to camera orientation Flame(i).ID
next i
`End of Subroutine
Return
Here's just the setup subroutine:
_FlameSetup:
`The Setup for Ankillito's Flame System
`Tweak these Parameters to get a different flame
FlameCount = 50 `How many particles
FlameID = 1 `A free object ID #, each particle ID is above this: 1,1+1,1+2,1+3,1+4
`FlameID is an actuall object number that can be moved and rotated: it's actually a cube
`The Fire is attached to this object.
ImageID = 1 `A free ID for an Image AND a Bitmap
FlameSize# = 12 `Size of each particle
FlameRadius# = 10 `Maximum Radius of Flame
FlameHeight# = 40 `Maximum Height of Flame
FlameSpeed# = 1 `Speed of Flame
FlameTapper# = 0.97 `How fast tappers as it goes up
FlameDim# = 3 `How fast it dims as it goes up
FlameShrink# = 1.25 `How fast each particle shrinks as it goes up
`Type for Flame Array
Type Flame
ID
Radius#
Degree
Depth#
Size#
Fade#
EndType
`This the object with ID# of "FlameID" as set above
Make object cube FlameID,1
hide object FlameID
`Thanks to Joseph Thomson for this part
`Create fire image
create bitmap ImageID,50,50
ink rgb(200,130,30),0
`Draw random dots in a circle shape
for x=1 to 1000
ang=rnd(360)
rad=rnd(20)
dot 25+sin(ang)*rad,25+cos(ang)*rad
next x
`Blur fire image
blur bitmap ImageID,3
get image ImageID,0,0,50,50
delete bitmap ImageID
`Set up array type and put it's values in.
Dim Flame(FlameCount) as Flame
for i = 1 to FlameCount
Flame(i).Radius# = rnd(flameRadius# * 100)
Flame(i).Radius# = Flame(i).Radius# / 100
Flame(i).Degree = rnd(359)
Flame(i).Depth# = rnd(FlameHeight#)
Flame(i).ID = FlameID + i
make object plain Flame(i).ID, FlameSize#, FlameSize#
texture object Flame(i).ID,ImageID
set object ambient Flame(i).ID,0
set object transparency Flame(i).ID,1
Ghost Object on Flame(i).ID
Disable object zwrite Flame(i).ID
Next i
`End of setup
Return
Here's the sub for inside a loop:
_FlameLoop:
`The action of the Flame
for i = 1 to FlameCount `Loop through array
If Flame(i).Depth# > FlameHeight# `Reset particle if it reached the top
Flame(i).Radius# = rnd(flameRadius# * 100)
Flame(i).Radius# = Flame(i).Radius# / 100
Flame(i).Degree = rnd(359)
Flame(i).Depth# = 0
Flame(i).Fade# = 200
Flame(i).Size# = 100
endif
`Move Particle up
Flame(i).Depth# = Flame(i).Depth# + FlameSpeed#
`Fade particle value
Flame(i).Fade# = Flame(i).Fade# - FlameDim#
`Smaller radius at top
Flame(i).Radius# = Flame(i).Radius# * FlameTapper#
`Shrink Particles
Flame(i).Size# = Flame(i).Size# - FlameShrink#
`Set Position base on object FlameID
Position Object Flame(i).ID, object position x(FlameID),object position y(flameID),object position Z(FlameID)
Set object to object orientation Flame(i).ID, FlameID
Move object Right Flame(i).ID, cos(Flame(i).Degree) * Flame(i).Radius#
Move Object UP Flame(i).ID, Flame(i).Depth#
Move Object Flame(i).ID, Sin(Flame(i).Degree) * Flame(i).Radius#
`Scal object
scale object Flame(i).ID,flame(i).size#,Flame(i).size#,100
`Fade object
fade object Flame(i).ID,Flame(i).Fade#
`"Point at camera" this was Joseph Thomson's coment, but it actually points away from camera
`I tried actually pointing it at the camera, and it doesn't look too cool.
set object to camera orientation Flame(i).ID
next i
`End of Subroutine
Return
"There will always be evil, for, without evil, the good shall lose their virtue."