Here's the code:
sync on : sync rate 60
disable escapekey : autocam off
randomize timer( )
color backdrop 0x001133
// Call this to initialize the fire plugin.
gosub initialization_Fire
// This is the image we will be using to represent the fire.
// You have to use the fire_IMG variable for the fire plugin to work.
fire_IMG = freeImage( )
load image "firespark.bmp",fire_IMG
// Now we can create a fire blaze.
// I will be using an integer.
global demo as integer
// The createFire( ) function returns an array index. If you have multiple blazes,
// then you could waste memory by making your own array, or you could
// access firepods() directly and point createFire( ) to NULL.
demo = createFire( 40.00,0.00,0.00, 10.00,2.00, 500,40.0, 2.00 )
// Just for added effect :D
make object sphere 1, 100, 12, 24
camang#=180.00
camrad#=160.00
fireang#=0.00
while escapekey( )=0
// Here are the two function calls that you're going to need in your game loop.
// You will have to call burnFire( ) for every blaze that you have created.
// Or you could just set up a for...next loop to go through all firepods() indices.
burnFire( demo )
// controlFires( ) on the other hand simply controls ALL fire particles in the scene.
// The only way not to control fire particles outside the viewing range is to not call
// burnFire( x ), and that will stop from creating fire particles for blaze x.
controlFires( )
// This demonstrates the ability to adjust blaze properties during runtime.
if mouseclick( )=1 or mouseclick( )=3
firepods(demo).avglife=600
firepods(demo).maxvelocity#=6.00
else
firepods(demo).avglife=500
firepods(demo).maxvelocity#=2.00
endif
if mouseclick( )<>2 and mouseclick( )<>3 then fireang#=wrapvalue( fireang#+1.00 )
firex#=sin(fireang#)*80.00
firey#=sin(fireang#)*50.00
firez#=cos(fireang#)*80.00
firepods(demo).pos.x#=firex#
firepods(demo).pos.y#=firey#
firepods(demo).pos.z#=firez#
camang#=wrapvalue( camang#+(mousemovex( )*0.2) )
camrad#=camrad#+(mousemovey( )*0.2)
camx#=sin(camang#)*camrad#
camz#=cos(camang#)*camrad#
position camera camx#, 0, camz#
point camera 0,0,0
text 5,5,"Fire polys on screen: "+str$((array count(fireParticles())*2))
text 5,screen height( )-25,"FPS: "+str$(screen fps( ))
text screen width( )-(text width("Leftclick to increase the blaze")+5),5,"Leftclick to increase the blaze"
text screen width( )-(text width("Rightclick to freeze the blaze")+5),25,"Rightclick to freeze the blaze"
sync
endwhile
end
// The end. :)
initialization_Fire:
type coord3d
x# as float
y# as float
z# as float
endtype
type fireparticle
id as integer
pos as coord3d
tpos as coord3d
velocity# as float
acvelocity# as float
acangle# as float
distrad# as float
radmag# as float
tstart as integer
life as integer
fade# as float
fadestamp as integer
endtype
type firepod
pos as coord3d
radius# as float
height# as float
avglife as integer
avgscale# as float
maxvelocity# as float
endtype
global dim fireParticles(0) as fireparticle
global dim firepods(0) as firepod
global totalpods as integer
global fire_IMG as integer
return
function createFire( x# as float,y# as float,z# as float, r# as float,h# as float, avglife as integer,avgscale# as float, maxvelocity# as float )
if firepodClear( totalpods )=0
array insert at bottom firepods()
inc totalpods, 1
endif
firepods(totalpods).pos.x#=x#
firepods(totalpods).pos.y#=y#
firepods(totalpods).pos.z#=z#
firepods(totalpods).radius#=r#
firepods(totalpods).height#=h#
firepods(totalpods).avglife=avglife
firepods(totalpods).avgscale#=avgscale#
firepods(totalpods).maxvelocity#=maxvelocity#
endfunction totalpods
function firepodClear( index as integer )
clear=1
if firepods(index).pos.x#<>0.00 then clear=0
if firepods(index).pos.y#<>0.00 then clear=0
if firepods(index).pos.z#<>0.00 then clear=0
if firepods(index).radius#<>0.00 then clear=0
if firepods(index).height#<>0.00 then clear=0
endfunction clear
function burnFire( fire as integer )
sparks=rnd(3)
if sparks=0 then exitfunction
for s=0 to sparks
createFireParticle( fire )
next s
endfunction
function controlFires( )
totalflames=array count(fireParticles())
for i=0 to totalflames
fireParticles(i).acangle#=wrapvalue(fireParticles(i).acangle#+fireParticles(i).acvelocity#)
fireParticles(i).distrad#=fireParticles(i).distrad#+fireParticles(i).radmag#
if fireParticles(i).distrad# <= 0.00
fireParticles(i).distrad#=abs(fireParticles(i).distrad#)
fireParticles(i).acangle#=wrapvalue(fireParticles(i).acangle#+180.00)
fireParticles(i).radmag#=abs(fireParticles(i).radmag#)
endif
dec fireParticles(i).radmag#, 0.001
inc fireParticles(i).pos.y#, fireParticles(i).velocity#
dec fireParticles(i).velocity#, 0.02
if fireParticles(i).velocity#<=0.00 then fireParticles(i).velocity#=0.125
fireParticles(i).pos.x#=(sin(fireParticles(i).acangle#)*fireParticles(i).distrad#)+fireParticles(i).tpos.x#
fireParticles(i).pos.z#=(cos(fireParticles(i).acangle#)*fireParticles(i).distrad#)+fireParticles(i).tpos.z#
if fireParticles(i).id>0
if object exist(fireParticles(i).id)=1
particleDeath=(fireParticles(i).tstart+fireParticles(i).life)
if abs(timer( )-particleDeath) <= 300
scale object fireParticles(i).id, (timer( )-particleDeath)/3,(timer( )-particleDeath)/3,(timer( )-particleDeath)/3
endif
position object fireParticles(i).id, fireParticles(i).pos.x#,fireParticles(i).pos.y#,fireParticles(i).pos.z#
point object fireParticles(i).id, camera position x( ), camera position y( ), camera position z( )
endif
else
array delete element fireParticles(), i
dec totalflames, 1
endif
if array index valid(fireParticles(i))=0 then exit
if timer( )-fireParticles(i).tstart >= fireParticles(i).life
delete object fireParticles(i).id
array delete element fireParticles(), i
dec totalflames,1
endif
next i
endfunction
function createFireParticle( pod as integer )
created=0
if array count(fireParticles())=-1
array insert at bottom fireParticles()
totalflames=array count(fireParticles())
created=1
else
if fireParticles(0).id<>0 and created=0
array insert at bottom fireParticles()
totalflames=array count(fireParticles())
endif
endif
fireParticles(totalflames).id=freeObject( )
make object plain fireParticles(totalflames).id, firepods(pod).avgscale#,firepods(pod).avgscale#
texture object fireParticles(totalflames).id, fire_IMG
set object transparency fireParticles(totalflames).id, 4
ghost object on fireParticles(totalflames).id, 0
set object emissive fireParticles(totalflames).id, 0xFFFFFF
ix#=firepods(pod).pos.x#
iy#=firepods(pod).pos.y#
iz#=firepods(pod).pos.z#
angle#=rnd(360000)
angle#=angle#/1000.00
rad#=rnd(firepods(pod).radius#)
fireParticles(totalflames).acangle#=angle#
fireParticles(totalflames).acvelocity#=rnd(8000)-2000
fireParticles(totalflames).acvelocity#=fireParticles(totalflames).acvelocity#/1000.00
fireParticles(totalflames).velocity#=rnd(firepods(pod).maxvelocity#*1000.00)
fireParticles(totalflames).velocity#=fireParticles(totalflames).velocity#/1000.00
fireParticles(totalflames).distrad#=rad#
fireParticles(totalflames).radmag#=rnd(500)
fireParticles(totalflames).radmag#=fireParticles(totalflames).radmag#/1000.00
fireParticles(totalflames).pos.x#=ix#
fireParticles(totalflames).pos.y#=iy#
fireParticles(totalflames).pos.z#=iz#
fireParticles(totalflames).tpos = fireParticles(totalflames).pos // Pretty crafty, aint it? :P
inc fireParticles(totalflames).pos.x#, (sin(angle#)*rad#)
inc fireParticles(totalflames).pos.y#, rnd(firepods(fire).height#)
inc fireParticles(totalflames).pos.z#, (cos(angle#)*rad#)
fireParticles(totalflames).tstart=timer( )
fireParticles(totalflames).life=(rnd(500)-250)+firepods(pod).avglife
endfunction
function freeObject( )
obj=0
repeat
inc obj,1
until object exist(obj)=0
endfunction obj
function freeImage( )
img=0
repeat
inc img, 1
until image exist(img)=0
endfunction img
Yup. That's very cool.
http://forum.thegamecreators.com/xt/xt_apollo_pic.php?i=1234759