Thanks for posts Indi and BatVink. I have tried some of those ideas, even stopping some effects from running to see where the slow down is. I guess fault finding comes with experience.
I've included the rest of the code incase you have any ideas or have time to tell me where i'm going wrong. All comments will be most welcome.
Using DBPro
autocam off
hide mouse
sync on
sync rate 0
global smoke=1
land=2
make matrix land,5000,5000,10,10
position matrix land, 0,0,0
position camera 10,30,10
missile=10
for a=1 to 10
make object cube a+3,5
position object a+3,20*a,10,40
rotate object a+3,0,rnd(360),40
next a
Rem Smoke Vars - Object Num Reserved 4000-5000 - Uses 800
global SmokeTrailAmount=40
global SmokeTrailTotal=20
global smokerate=0
type smokeframe
smokeobj as integer
FollowObj as integer
fade# as float
size# as float
inuse as integer
SmokeCounter as integer
Loopreached as integer
ObjHide as integer
endtype
dim smoketrail(20,40) as smokeframe
load image "smoke3.bmp",smoke
Rem Explosion frag Vars - Object Num Reserved 3000-3500 - Uses 400
global FragAmount=20
global FragTotal=20
global grav#=0.5
type explodefx
x# as float
y# as float
z# as float
obj as integer
xx# as float
yy# as float
zz# as float
Force as integer
fade# as float
inuse as integer
endtype
dim explode(FragTotal,FragAmount) as explodefx
Rem Explosion Bang Vars -uses image numbers 100-116
Rem Object Num Reserved 4000-4100 - uses 20
global BangTotal=20
global bangimage=100
type Bangfx
x# as float
y# as float
z# as float
frame as integer
obj as integer
inuse as integer
endtype
dim bang(BangTotal) as bangfx
SetupSmokeTrail()
CreateExplodeFrags()
CreateExplosionBang()
gametimer=timer()
rem **********************************************************
while controlkey()=0
if spacekey()=1 and fired=0
fired=1
for a=1 to missile
show object a+3
position object a+3,20*a,10,40
InitialiseSmokeTrail(a+3)
next a
mover=0
endif
if fired=1 then mover=mover+1
if fired=1 then
for a=1 to missile
move object a+3,3
if mover=100
hide object a+3:fired=0
InitialiseExplodeFrags(a+3)
InitialiseExplodebang(a+3)
endif
next a
RunExplodefrags()
RunExplosionBang()
RunSmokeTrail()
gosub _playermove:
print "fps ",screen fps()
sync
endwhile
rem ****************************************************************************
_playermove:
rotate camera camera angle x(0)+(mousemovey()/2.0),camera angle y(0)+(mousemovex()/2.0),0
camx#=camera angle x(0)
camy#=camera angle y(0)
if upkey()=1 then xrotate camera 0,0 : move camera 0,6: xrotate camera 0,camx#
if leftkey()=1 then yrotate camera 0,camy#-90:move camera 0,6: yrotate camera 0,camy#
if rightkey()=1 then yrotate camera 0,camy#+90:move camera 0,6:yrotate camera 0,camy#
if downkey()=1 then xrotate camera 0,0 : move camera 0,-6: xrotate camera 0,camx#
if wrapvalue(camera angle x(0))>40 and wrapvalue(camera angle x(0))<180 then xrotate camera 0,40
if wrapvalue(camera angle x(0))>180 and wrapvalue(camera angle x(0))<280 then xrotate camera 0,280
playerheight#=get ground height(land,camera position x(),camera position z())
position camera camera position x(0),playerheight#+10,camera position z()
return
Function SetupSmokeTrail
Rem Uses 4000-5000
for a=1 to SmokeTrailTotal
for cnt=1 to SmokeTrailAmount
smoketrail(a,cnt).smokeobj=4000+(a*SmokeTrailAmount)+cnt
make object plain smoketrail(a,cnt).smokeobj,15,15
texture object smoketrail(a,cnt).smokeobj,smoke
set object transparency smoketrail(a,cnt).smokeobj,1
ghost object on smoketrail(a,cnt).smokeobj,0
ss=int(rnd(360))
rotate object smoketrail(a,cnt).smokeobj,0,0,ss
fix object pivot smoketrail(a,cnt).smokeobj
position object smoketrail(a,cnt).smokeobj,1000,5000,1000
next cnt
next a
endfunction
Function InitialiseSmokeTrail(TempObj)
a=0
while a<SmokeTrailTotal
inc a
if smoketrail(a,1).inuse=0
smoketrail(a,1).inuse=1
smoketrail(a,1).followObj=tempobj
Smoketrail(a,1).smokecounter=0
Smoketrail(a,1).Loopreached=0
for cnt=1 to SmokeTrailAmount
smoketrail(a,cnt).fade#=100
smoketrail(a,cnt).size#=15
position object smoketrail(a,cnt).smokeobj,8000,8000,8000
show object smoketrail(a,cnt).smokeobj
next cnt
exitfunction
endif
endwhile
endfunction
Function RunSmokeTrail()
inc smokerate
if smokerate=5
smokerate=0
for a=1 to SmokeTrailTotal
if smoketrail(a,1).inuse=1
if object visible(smoketrail(a,1).FollowObj)=1
counter=smoketrail(a,1).smokecounter
x#=object position x (smoketrail(a,1).FollowObj)
y#=object position y (smoketrail(a,1).FollowObj)
z#=object position z (smoketrail(a,1).FollowObj)
if counter=SmokeTrailAmount
counter=0
if Smoketrail(a,1).Loopreached=0 then Smoketrail(a,1).Loopreached=1
endif
inc counter
if Smoketrail(a,1).Loopreached=1
smoketrail(a,counter).fade#=100
smoketrail(a,counter).size#=15
show object (smoketrail(a,counter).smokeobj)
endif
position object smoketrail(a,counter).Smokeobj,x#,y#,z#
point object smoketrail(a,counter).Smokeobj,camera position x(),camera position y(),camera position z()
smoketrail(a,1).smokecounter=counter
if Smoketrail(a,1).Loopreached=1 then count=SmokeTrailAmount else count=counter
for cnt=1 to count
dec smoketrail(a,cnt).fade#,10
inc smoketrail(a,cnt).size#,10
if smoketrail(a,cnt).fade#<=0 then:hide object smoketrail(a,cnt).smokeobj
scale object smoketrail(a,cnt).smokeobj,100+(smoketrail(a,cnt).size#*2),100+(smoketrail(a,cnt).size#*2),100
fade object smoketrail(a,cnt).smokeobj,smoketrail(a,cnt).fade#
next cnt
else
for cnt=1 to SmokeTrailAmount
hide object smoketrail(a,cnt).smokeobj
next cnt
smoketrail(a,1).inuse=0
endif
endif
next a
endif
endfunction
function CreateExplodeFrags()
rem Uses object number 3000-3500
for a=1 to fragtotal
for cnt=1 to FragAmount
explode(a,cnt).obj=3000+(a*FragAmount)+cnt
explode(a,cnt).force=rnd(15)
make object triangle explode(a,cnt).obj,10,5,10,explode(a,cnt).force,explode(a,cnt).force,explode(a,cnt).force,10,20,10
randrotate=rnd(100)
rotate object explode(a,cnt).obj,randrotate,randrotate,randrotate
fix object pivot explode(a,cnt).obj
hide object explode(a,cnt).obj
next cnt
next a
endfunction
function InitialiseExplodeFrags(TempNo)
a=0
while a<20
inc a
if explode(a,1).inuse=0
for cnt=1 to FragAmount
explode(a,cnt).x#=object position x(TempNo)
explode(a,cnt).y#=object position y(Tempno)
explode(a,cnt).z#=object position z(TempNo)
explode(a,cnt).yy#=newyvalue(0,-45,explode(a,cnt).force)
explode(a,cnt).xx#=newxvalue(0,rnd(360),cos(object angle x(TempNo))*explode(a,cnt).force)
explode(a,cnt).zz#=newzvalue(0,rnd(360),cos(object angle x(TempNo))*explode(a,cnt).force)
position object explode(a,cnt).obj, explode(a,cnt).x#,explode(a,cnt).y#,explode(a,cnt).z#
explode(a,cnt).fade#=100
show object explode(a,cnt).obj
next cnt
explode(a,1).inuse=1:exitfunction
endif
endwhile
endfunction
function RunExplodefrags()
for a=1 to Fragtotal
if explode(a,1).inuse=1
for cnt=1 to Fragamount
explode(a,cnt).x#=explode(a,cnt).x#+explode(a,cnt).xx#
explode(a,cnt).yy#=explode(a,cnt).yy#-grav#
explode(a,cnt).y#=explode(a,cnt).y#+explode(a,cnt).yy#
explode(a,cnt).z#=explode(a,cnt).z#+explode(a,cnt).zz#
position object explode(a,cnt).obj, explode(a,cnt).x#,explode(a,cnt).y#,explode(a,cnt).z#
fade object explode(a,cnt).obj,explode(a,cnt).fade#
dec explode(a,cnt).fade#,5
if explode(a,cnt).fade#<=0 then hide object explode(a,cnt).obj
next cnt
if explode(a,Fragamount).fade#<=0 then explode(a,1).inuse=0
endif
next a
endfunction
Function CreateExplosionBang()
Rem uses image numbers 100-116
Rem Uses object numbers 4000-4020
a=0
load bitmap "Explode.jpg",1
for y=1 to 4
for x=1 to 4
get image bangimage+a,(x-1)*64,(y-1)*64,x*64,y*64
inc a
next x
next y
delete bitmap 1
for cnt=1 to BangTotal
bang(cnt).obj=4000+cnt
make object plain bang(cnt).obj,90,90
ghost object on bang(cnt).obj,0
set object ambient bang(cnt).obj,0
hide object bang(cnt).obj
next cnt
endfunction
Function InitialiseExplodeBang(TempNo)
for cnt=1 to BangTotal
if bang(cnt).inuse=0
bang(cnt).x#=object position x(TempNo)
bang(cnt).y#=object position y(Tempno)
bang(cnt).z#=object position z(TempNo)
position object bang(cnt).obj,bang(cnt).x#,bang(cnt).y#,bang(cnt).z#
show object bang(cnt).obj
bang(cnt).inuse=1:exitfunction
endif
next cnt
endfunction
function RunExplosionBang
for cnt=1 to BangTotal
if bang(cnt).inuse=1
point object bang(cnt).obj,camera position x(),camera position y(),camera position z()
texture object bang(cnt).obj,bangimage+bang(cnt).frame
inc bang(cnt).frame
if bang(cnt).frame>15
hide object bang(cnt).obj
scale object bang(cnt).obj,100,100,100
bang(cnt).frame=0
bang(cnt).inuse=0
exitfunction
endif
endif
next cnt
endfunction
Media can be got from:
http://maelstromhome.mysite.freeserve.com/pics/bang.rar
Arrow keys move camera - space sets things going.
These Functions setup and create effects:
SetupSmokeTrail()
CreateExplodeFrags()
CreateExplosionBang()
These Functions asign an effect slot to object i.e missiles:
InitialiseSmokeTrail(Object Number)
InitialiseExplodeFrags(Object Number)
InitialiseExplodebang(Object Number)
These Functions run effects until the effect has finished.
RunExplodefrags()
RunExplosionBang()
RunSmokeTrail()
Thanks