Xander posted another version that fixed the smoke problem, but I couldn't find the new version.
[edit] Actually he just left off the disable object zwrite on the ghosted objects. This code works just like the DBC version:
`********* EXPLOSION EXAMPLE ************
` CREATED BY XANDER MOSER OF BOLT SOFTWARE IN DB CLASSIC 1.13
` JANUARY 23, 2004, YOU MAY USE ANY CODE FROM THIS EXAMPLE
` NOT ALL MEDIA IS MINE, THE SHIP IS FROM BANSHEE STUDIOS,
` THE LIGHT SHOCKWAVE IS FROM A COMPANY THAT QUIT MAKING
` A GAME IN MID-PROGRESS, THE EXPLOSION TEXTURES ARE
` FROM THE EXPLOSION GENERATOR WEBSITE
set display mode 800,600,16
autocam off
sync on
` Using a sync rate of 0 is okay because I always use speed modifiers in my code
` that use the framerate to keep the program running at the same speed at all times
sync rate 0
set camera range 1,4000
disable escapekey
`remove ambient lighting so that objects can fade out
set ambient light 0
`create a directional light coming from above
set directional light 0,0,-1,0
color light 0,rgb(255,255,255)
`fog setup
fog on
fog color rgb(230,140,30)
fog distance 1500.0
`smoke flag 1 for smoke 0 for no smoke
smokeon=1
numobject=0
numimage=0
`create skysphere
inc numimage:skytex=numimage:load image "Data\Textures\Sky.jpg",numimage,1
inc numobject:sky=numobject:make object sphere sky,2500
texture object sky,skytex
scale object texture sky,2,2
set object sky,1,1,0,1,0,0,0
set object texture sky,2,2
position object sky,1000,-100,1000
`create simple ground matrix
make matrix 1,3000.0,3000.0,10,10
inc numimage:graveltex=numimage:load image "Data\Textures\Grass.jpg",numimage
prepare matrix texture 1,graveltex,1,1
fill matrix 1,0,1
randomize matrix 1,50
update matrix 1
`create all four ship objects and variables
numship=4:dim ship(numship):dim shipa#(numship):dim shipalive(numship):dim shipsmoketime(numship)
for a=1 to numship
inc numobject:ship(a)=numobject:load object "Data\Ship\Storm.3ds",numobject
shipa#(a)=(a-1)*90:shipalive(a)=1
yrotate object ship(a),270:fix object pivot ship(a)
position object ship(a),1000.0+cos(shipa#(a))*200.0,50.0*a+50.0,1000.0+sin(shipa#(a))*200.0
scale object ship(a),20,20,20
set object ship(a),1,1,1,1,1,0,1
next a
`Create all 4 explosion, shockwave, and light objects
numex=4:dim exobject(numex,3):dim exon(numex):dim exframe#(numex):dim extextype(numex)
numextex=6:dim extex(6,16)
`load explosion textures, 16 frames for each
for a=1 to numextex
load bitmap "Data\Textures\Ex"+str$(a)+".jpg",1
for y=1 to 4
for x=1 to 4
inc numimage:extex(a,(y-1)*4+x)=numimage
get image numimage,(x-1)*64,(y-1)*64,x*64,y*64
next x
next y
delete bitmap 1
next a
inc numimage:lightimage=numimage:load image "Data\Textures\light.jpg",numimage
inc numimage:shockimage=numimage:load image "Data\Textures\Shock.jpg",numimage
`create the explosion objects
for a=1 to numex
for i=1 to 3
inc numobject:exobject(a,i)=numobject
make object plain numobject,35,35
`there are three different objects for each explosion:
`object 1 is the explosion itself
`object 2 is the flare type object
`object 2 is the shockwave
if i<3 then set object rotation zyx numobject else xrotate object exobject(a,i),120:fix object pivot exobject(a,i)
hide object exobject(a,i):ghost object on exobject(a,i)
disable object zdepth exobject(a,i)
if i=1 then set object exobject(a,i),1,1,0,1,0,0,0 else set object exobject(a,i),1,1,0,1,1,0,0
if i=2 then texture object exobject(a,i),lightimage
if i=3 then texture object exobject(a,i),shockimage
next i
next a
for a=1 to 7
load sound "Data\Sounds\"+str$(a)+".wav",a
next a
`create debris objects which are just colored triangles
numdeb=100:dim debon(numdeb):dim debobject(numdeb):dim debr#(numdeb,3):dim debm#(numdeb,3):dim exon(numdeb)
inc numimage:debimage=numimage:load image "Data\Textures\Gray.jpg",numimage
for a=1 to numdeb
inc numobject:debobject(a)=numobject:make object triangle numobject,(-1)-rnd(2),0,0, 0,2+rnd(2),0, 1+rnd(2),0,0
rotate object debobject(a),rnd(360),rnd(360),rnd(360):fix object pivot debobject(a)
texture object debobject(a),debimage
hide object debobject(a)
next a
if smokeon=1
`create smoke objects with dark ghosting with special texture
numsmoke=50:dim smokeon(numsmoke):dim smoke(numsmoke):dim smokef#(numsmoke):dim smokeimage(14)
load bitmap "Data\Textures\smoke.jpg",1
for f=1 to 14
inc numimage:get image numimage,(f-1)*64,0,f*64,64,1:smokeimage(f)=numimage
next f
delete bitmap 1
for a=1 to numsmoke
inc numobject : smoke(a)=numobject
smokeon(a)=0
make object plain numobject,80,80
set object rotation zyx numobject
set object numobject,1,1,1,0,0,0,0
hide object numobject
set object texture numobject,2,2
ghost object on numobject, 1
disable object zwrite numobject
next a
endif
cama#=0.0:camy#=400.0:camd#=700.0
set current bitmap 0
do
`camera control
if keystate(12)=1 or keystate(74)=1 then camy#=camy#+2.0*speed#:if camy#>600.0 then camy#=600.0
if keystate(13)=1 or keystate(78)=1 then camy#=camy#-2.0*speed#:if camy#<200.0 then camy#=200.0
if rightkey()=1 then cama#=wrapvalue(cama#+2.0*speed#)
if leftkey()=1 then cama#=wrapvalue(cama#-2.0*speed#)
if upkey()=1 then camd#=camd#-1.0*speed#:if camd#<250.0 then camd#=250.0
if downkey()=1 then camd#=camd#+1.0*speed#:if camd#>700.0 then camd#=700.0
position camera 1000.0+cos(cama#)*camd#,camy#,1000.0+sin(cama#)*camd#
point camera 1000,camy#-200.0,1000
`Quit when escape is pressed
if escapekey()=1 then goto quit
`Save a screenshot if enter is pressed
if returnkey()=1
for a=1 to 100
if file exist("Screenshot"+str$(a)+".bmp")=0
hide mouse
save bitmap "Screenshot"+str$(a)+".bmp"
goto donesave
endif
next a
donesave:
show mouse
endif
`control ships
for a=1 to numship
shipa#(a)=wrapvalue(shipa#(a)+0.25*speed#)
if shipalive(a)=1
`make ships circle and come down if high in air
if object position y(ship(a))>100.0*a+50.0 then newy#=object position y(ship(a))-3.5*speed# else newy#=100.0*a+50.0
position object ship(a),1000.0+cos(shipa#(a))*200.0,newy#,1000.0+sin(shipa#(a))*200.0
rotate object ship(a),0,wrapvalue(90-shipa#(a)),0
`if ship is clicked on, blow it up
`This is a pretty poor routine, but it works. If the mouse on the screen is whithin
`20 pixels of the ship object's screen position, it blows it up
if timer()-clicktime>1000 and object in screen(ship(a))=1
if sqrt((object screen x(ship(a))-mousex())^2+(object screen y(ship(a))-mousey())^2)<20.0 and mouseclick()>0
clicktime=timer()
play sound 1+rnd(5)
gosub findex
shipalive(a)=0
endif
endif
else
`make ships fall and turn if dead
position object ship(a),1000.0+cos(shipa#(a))*200.0,object position y(ship(a))-1.0*speed#,1000.0+sin(shipa#(a))*200.0
yrotate object ship(a),wrapvalue(90-shipa#(a))
xrotate object ship(a),wrapvalue(object angle x(ship(a))+.2*speed#)
zrotate object ship(a),wrapvalue(object angle z(ship(a))+.1*speed#)
`release smoke and debris every 2/10 of a second
if timer()-shipsmoketime(a)>200
shipsmoketime(a)=timer()
if smokeon=1 then gosub findsmoke
gosub finddebris
endif
`reset ship and create another explosion if it hits the ground
if object position y(ship(a))<=get ground height(1,object position x(ship(a)),object position z(ship(a)))+10.0
gosub findex:play sound 1+rnd(5):play sound 7:shipalive(a)=1
position object ship(a),object position x(ship(a)),1000,object position z(ship(a))
endif
endif
next a
`go to special effect subroutines
gosub explosions
gosub debris
if smokeon=1 then gosub smoke
`frames per second and screen display
fps#=screen fps()
text 10,10,"FPS: "+str$(fps#)
center text screen width()/2,screen height()-40,"Use arrow keys and +/- to control camera"
center text screen width()/2,screen height()-20,"Click on a ship to make it explode"
`set up variable to control speeds of all objects
speed#=60.0/fps#
sync
loop
`find and setup and explosion object
findex:
fe=0
`find an explosion object not being used and set it up
for e=1 to numex
if exon(e)=0
exon(e)=1:fe=e:goto donefindex
endif
next e
donefindex:
if fe>0
for e=1 to 3
`show the explosion objects and position them where the ship is
show object exobject(fe,e)
position object exobject(fe,e),object position x(ship(a)),object position y(ship(a)),object position z(ship(a))
next e
yrotate object exobject(fe,3),rnd(360)
extextype(fe)=1+rnd(5)
exframe#(fe)=1.0
`find 20 debris objects
for e=1 to 20:gosub finddebris:next e
endif
return
`explosions, scale up and fade out
explosions:
for a=1 to numex
if exon(a)=1
for i=1 to 3
`point the explosion and flare objects to the camera so they appear 3D
if i<3
if i=1 and exframe#(a)<8.5 then texture object exobject(a,i),extex(extextype(a),int(exframe#(a)*2.0))
set object to camera orientation exobject(a,i)
endif
`scale the objects larger
scale object exobject(a,i),exframe#(a)*50.0,exframe#(a)*50.0,exframe#(a)*50.0
`fade the objects, the flare and shockwaves don't fade until later so they appear
`brighter initially
if i=1 then fade object exobject(a,i),200
if i>1
if exframe#(a)<10.0 then fade object exobject(a,i),200 else fade object exobject(a,i),(6.0-(exframe#(a)-10.0))*33
endif
next i
exframe#(a)=exframe#(a)+0.10*speed#
if exframe#(a)>8.0 then hide object exobject(a,1)
if exframe#(a)>=17.0
exon(a)=0:hide object exobject(a,2):hide object exobject(a,3)
endif
endif
next a
return
`find and setup debris objects
finddebris:
fd=0
`find a debris object not being used and set it up
for d=1 to numdeb
if debon(d)=0
debon(d)=1:fd=d:goto donefinddeb
endif
next d
donefinddeb:
if fd>0
`position the debris to the ships position
position object debobject(fd),object position x(ship(a)),object position y(ship(a)),object position z(ship(a))
show object debobject(fd)
`random rotation variables to spin the debris
debr#(fd,1)=-1.0+(rnd(20)/1.0):debr#(fd,2)=-1.0+(rnd(20)/1.0):debr#(fd,2)=-1.0+(rnd(20)/1.0)
`move the debris in the direction that the ship is facing
debm#(fd,1)=cos(((shipa#(a)+90)-10)+rnd(20))*(-0.5+(rnd(30)/10.0))
if object position y(ship(a))>get ground height(1,object position x(ship(a)),object position z(ship(a)))+10.0 then debm#(fd,2)=-1.0+(rnd(20)/10.0) else debm#(fd,2)=(1.0)+(rnd(10)/10.0)
debm#(fd,3)=sin(((shipa#(a)+90)-10)+rnd(20))*(-0.5+(rnd(30)/10.0))
rotate object debobject(a),rnd(360),rnd(360),rnd(360)
`make the debris larger if the ship has hit the ground
if shipalive(a)=0 then scale object debobject(fd),200,200,200 else scale object debobject(fd),100,100,100
endif
return
`debris objects
debris:
for a=1 to numdeb
if debon(a)=1
` Apply gravity to debris
debm#(a,2)=debm#(a,2)-.05*speed#
`reposition and move the debris objects
rotate object debobject(a),wrapvalue(object angle x(debobject(a))+debr#(a,1)),wrapvalue(object angle y(debobject(a))+debr#(a,2)),wrapvalue(object angle z(debobject(a))+debr#(a,3))
position object debobject(a),object position x(debobject(a))+debm#(a,1),object position y(debobject(a))+debm#(a,2),object position z(debobject(a))+debm#(a,3)
`hide the debris and turn it off if it hits the ground
if object position y(debobject(a))<0
debon(a)=0:hide object debobject(a)
endif
endif
next a
return
`find and setup smoke objects
findsmoke:
fs=0
`find a smoke object not being used and set it up
for s=1 to numsmoke
if smokeon(s)=0
smokeon(s)=1 : fs=s
goto donefindsmoke
endif
next s
donefindsmoke:
if fs>0
smokef#(fs)=1.0 : show object smoke(fs)
`position the smoke where the ship is
position object smoke(fs),object position x(ship(a)),object position y(ship(a)),object position z(ship(a))
endif
return
`smoke objects, fade out
smoke:
for a=1 to numsmoke
if smokeon(a)=1
`increase the smoke texture
texture object smoke(a),smokeimage(int(smokef#(a)))
`make the smoke larger
scale object smoke(a),smokef#(a)*10.0,smokef#(a)*10.0,smokef#(a)*10.0
`point the smoke to the camera so it appears 3D
set object to camera orientation smoke(a)
smokef#(a)=smokef#(a)+.24*speed#
if smokef#(a)>=15.0
smokeon(a)=0 : hide object smoke(a)
endif
endif
next a
return
quit:
for a=1 to numobject
if object exist(a)
delete object a
endif
next a
for a=1 to numimage
if image exist(a)
delete image a
endif
next a
delete matrix 1
end
Link above now has corrected code as well for future downloaders.