Here is my code, in case I don't get to finish the plane.
It was going to be a Mars Flyer.
I spent way too much time on the effects, and didn't finish the plane.
The SPACE BAR will fire a shot at the radar guided turrets which don't shoot back yet.
The ARROW keys control the Mars Flyer.
Sorry for the messy code, routines from all over the place, stiched together, sort of works for now.
And way too much code!
`Coding Challenge - Mars Flyer
`Bill Robinson
`
`The SPACE bar fires Mars Flyer cannon.
`
set display mode 1280,1024,32
sync on
sync rate 60
hide mouse
autocam off
`set ambient light 50
color backdrop rgb(0,0,30)
randomize timer()
set camera range 1,20000
#Constant WHITEcolor=rgb(255,255,255)
#Constant YELLOW=rgb(255,255,0)
#Constant REDCOLOR=rgb(255,0,0)
#Constant GREENCOLOR=rgb(0,255,0)
global landsize=20000
type TurretGun
active as integer
objnum as integer
x as integer
y as integer
z as integer
turretobj as integer
radarobj as integer
yturretangle as integer
yradarangle as integer
endtype
dim turret(100) as TurretGun
type FlyerData
active as integer
objnum as integer
x as integer
y as integer
z as integer
y_oscillate_angle# as float
z_oscillate_angle# as float
y_oscillate_speed# as float
z_oscillate_speed# as float
y_oscillate_amplitude as integer
z_oscillate_amplitude as integer
objcolor as integer
endtype
dim flyer(100) as FlyerData
global bulletalive=0
global bulletspeed=50
global flyerspeedinc#=2.0
global flyerturninc#=0.5
global s#
global heightoffset#=50.0
`--- Mars Flyer ---
dim oscillate(100,10)
global oscillate_speed=2
global oscillate_amplitude=20
global x#
global h#
global z#
global cx#
global cy#
global cz#
`--- Turrets ---
global numturrets=30
global turretcount=0
global turretobjnum=700
global radarobjnum=800
`--- Matrix ---
global gridxmax=100
global gridzmax=100
dim gridtexture(gridxmax, gridzmax)
`--- Pyradmids ---
global numpyr=3
global pyrsize=500
global pyrheightmax=2000
`--- Boxes
global numboxes=1
global boxsize=500
global boxheightmax=2000
`--- Object Collision ---
global targetsleft=numboxes
global hitnum
global oldhitnum
global hitflag=0
`--- Camera & Screen ---
global camylookup#=0
global screenxcenter
screenxcenter=SCREEN WIDTH()/2
`--- Explosion Particles ---
rem Arrays for position, velocity and life of each explosion particle
dim partx#(300)
dim party#(300)
dim partz#(300)
dim partxvel#(300)
dim partyvel#(300)
dim partzvel#(300)
dim partxrot#(300)
dim partyrot#(300)
dim partzrot#(300)
dim partlife(300)
dim explosion(10,10)
global start_time=0
global inten#=60.0
global maxexppieces=200
global explode_object=0
global expdone=0
global exparrayindex=1
global expparticleindex=1
gosub _intro:
`--- Make Explosion Pieces ---
color=rgb(255,255,255)
piecesize=30
for i=1 to maxexppieces
obnum=199+i
make object plain obnum,rnd(piecesize)+piecesize,rnd(piecesize)+piecesize
color object obnum,color
hide object obnum
next i
sync
print "Building Textures"
sync
`--- make terrain textures ---
_terrain_textures()
for i=1 to numboxes
obj=i+400
` numlimbs=create_pyramid(obj,pyrsize,4,0)
make object box obj,boxsize,boxsize,boxsize
set object ambient obj,100
colr=rgb(64*rnd(4),64*rnd(4),64*rnd(4))
color object obj,colr
set object emissive obj,colr
set object ambient obj,25
position object obj,18000+i*(boxsize+400),1500,21000
`---DBPro collision---
set object collision on obj
`SET OBJECT COLLISION TO spheres obj
SET OBJECT COLLISION TO boxes obj
if obj=401 then _add_scannerbeams(obj)
next i
rem Make landscape
landsize=20000 :`was 5000
set camera range 10,landsize*5
make matrix 1,landsize*2,landsize*2,gridxmax+1,gridzmax+1 :`was 25,25 - now 50,50
`prepare matrix texture 1,44,4,4
prepare matrix texture 1,1,4,4
randomize matrix 1,200 :`was 200 - sets height of land matrix hills
rem Texture landscape
roadx=gridxmax/2
roadz=gridzmax/2
for z=0 to gridzmax :`both for loops were 1 to grid...changed to 0 to ... to texture to the edges
for x=0 to gridxmax
texturenum=rnd(7)+1
set matrix tile 1,x,z,texturenum :`now texturenum - was rnd(11)+1
gridtexture(x,z)=texturenum
rem Roads
if z=roadx or x=roadx
lvl=rnd(2)
lvl#=0.0-(lvl*10.0)
set matrix tile 1,x,z,13+lvl
set matrix height 1,x,z,lvl#
set matrix height 1,x+1,z,lvl#
set matrix height 1,x,z+1,lvl#
set matrix height 1,x+1,z+1,lvl#
endif
next x
next z
update matrix 1
`----- Build Gun Turrets ---
for i=1 to numturrets
spacing=15000
turretobj=_make_turret()
` position object 700,22000,200,20000
position object turretobj,landsize-(Spacing/2)+rnd(spacing),200,landsize-spacing+rnd(spacing)
turret(i).radarobj=radarobjnum
` make object box 800,10,10,100
radarobj=turret(i).radarobj
make object sphere radarobj,100,4,4
scale object radarobj,100,100,10
position object radarobj,object position x(turretobj),object position y(turretobj)+150,object position z(turretobj)
`hide object 800
inc radarobjnum
next i
`---make flyer object---
_make_flyer()
flyer(1).y_oscillate_angle#=0.0
flyer(1).z_oscillate_angle#=0.0
flyer(1).y_oscillate_speed#=2.0
flyer(1).z_oscillate_speed#=1.0
flyer(1).y_oscillate_amplitude=10
flyer(1).z_oscillate_amplitude=2
x#=landsize
z#=landsize
h#=500.0
a#=180.0
`position the flyer
position object 1,x#,h#,z#
yrotate object 1,a#
cx#=landsize
cy#=2000
cz#=landsize-2000
oscillate_angle=0
position camera 20000,500,18000
rem ----- main loop -----------------------------------------------------
do
`position object 10,object position x(1),object position y(1),object position z(1)
for i=1 to numboxes :`rotate objects to shoot at - was numpyr
obj=i+400
turn object right obj,1
turn object right obj+1000,1
next i
keypress=scancode() :`scan for keys pressed, subroutine to hadle keys
if keypress>0 then _key_action(keypress)
if upkey()=1 and s#<80.0
if keypress=42 and s#<80.0 then s#=s#*1.5
s#=s#+flyerspeedinc# :`was 4.0
endif
if downkey()=1 and s#>-100.0 then s#=s#-flyerspeedinc#
if leftkey()=1
s#=s#+0.1
a#=wrapvalue(a#-flyerturninc#) :`was a#-5
endif
if rightkey()=1
s#=s#+0.1
a#=wrapvalue(a#+flyerturninc#)
endif
`----------------------------------------
rem Other Keypress scancodes
keypress=scancode()
if keypress>0 :`and keypress<>lastkeypressed
lastkeypressed=keypress
select keypress
case 2
bulletspeed=50 :`the 1 key was pressed
endcase
case 3
bulletspeed=100 :`the 2 key was pressed
endcase
case 4
bulletspeed=150 :`the 3 key was pressed
endcase
case 82
` --- smooth camera lookup, scans camera upward ---
` lookupflag=1
offset#=300.0
camylookup#=curvevalue(offset#,camylookup#,50.0)
if camylookup#=offset#-5 then lookupflag=0
endcase
endselect
endif
rem Control turret bullet
if spacekey()=1 and bulletalive=0 then gosub _start_bullet
if bulletalive>0 then gosub _move_bullet
gosub _check_hits
if bulletalive<0 or hitflag=1
gosub _explode_bullet
` _request_explosion(ex#,ey#,ez#,explosion(ex,3),explosion(ex,4),explosion(ex,5),explosion(ex,6),explosion(ex,7))
endif
if keystate(48)=1 :`b key - self destruct
`(object,num particles,intensity,particle life,color)
` _set_explosion(2,50,30,YELLOW)
_set_explosion(2,50,40,150,YELLOW)
` playerdeadtime=200
wait 200
endif
` --- smooth camera lookup, scans camera back down ---
if keypress<>82 then camylookup#=curvevalue(0,camylookup#,50.0)
if camylookup#<1.0 then camylookup#=0.0:lookupflag=0
rem Calculate flyer data
oldx#=x#
oldz#=z#
x#=newxvalue(x#,a#,s#)
z#=newzvalue(z#,a#,s#)
s#=s#/1.2
rem ----- Smooth control camera -----
cdx#=newxvalue(x#,a#,-700)
cdz#=newzvalue(z#,a#,-700)
cdy#=get ground height(1,cx#-mx#,cz#-mz#)+50 :`was +50
if cdy#<225 then cdy#=225
cx#=curvevalue(cdx#,cx#,10.0)
cy#=curvevalue(cdy#,cy#,10.0)
cz#=curvevalue(cdz#,cz#,10.0)
rem Update flyer model
` h#=get ground height(1,x#-mx#,z#-mz#)+heightoffset#
h#=500.0
position camera cx#,h#+350.0,cz#-50:`orig didn't say -100 for z
point camera x#,h#+camylookup#,z#
` trackh#=(frontlefth#+frontrighth#+backlefth#+backrighth#)/4.0
` if trackh#>h# then h#=trackh#
position object 1,x#,h#,z#
yrotate object 1,a#
rotate object 2,wrapvalue(length#/4.0),0,wrapvalue(across#/4.0)
`----------------------------------------
_check_newexplosions()
_continue_explosion() :`continue to explode pieces
_check_turrets()
oscillate_angle#=wrapvalue(flyer(1).y_oscillate_angle# + flyer(1).y_oscillate_speed#)
flyer(1).y_oscillate_angle#=oscillate_angle#
` _update_oscillation(1,1,0,flyer(1).y_oscillate_amplitude,oscillate_angle#)
oscillate_angle#=wrapvalue(flyer(1).z_oscillate_angle# + flyer(1).z_oscillate_speed#)
flyer(1).z_oscillate_angle#=oscillate_angle#
_update_oscillation(1,0,1,flyer(1).z_oscillate_amplitude,oscillate_angle#)
` _update_oscillation(objnum,yposflag,bankflag,intensity#,angle#)
mx=mousex()
mousebutton=mouseclick()
` gosub _show_score :`show score on screen
set cursor 0,0
print screen fps()
print "x=";x#
print "z=";z#
sync
loop
end
`----END MAIN--------------------------------------------------------------------------------------------------
function _start_oscillation(objnum,pitchflag,bankflag,intensity)
endfunction
function _update_oscillation(objnum,yposflag,bankflag,intensity#,angle#)
if objnum=1
if yposflag=1
ypos#=h#+cos(angle#)*intensity#
position object objnum,object position x(objnum),ypos#,object position z(1)
endif
if bankflag=1
` zrot#=object angle z(objnum)+cos(angle#)*intensity#
zrot#=cos(angle#)*intensity#
zrotate object objnum,zrot#
endif
endif
endfunction incval#
function _angle_diff(a1#,a2#)
a2#=(a2#-a1#) mod 360
if a2#>180 then a2#=a2#-360
endfunction a2#
function _make_Flyer()
rem Create a tilt object (to handle "independent" X & Z axis rotation)
make object cone 1,5
hide limb 1,0
` make object box 2,200,75,300
make object box 2,1000,5,150
color object 2,rgb(255,255,0)
rem Glue flyer to tilt-object
glue object to limb 2,1,0
rem Create small bullet
make object sphere 3,50
` texture object 3,6
color object 3,rgb(255,255,255)
hide object 3
remstart
rem ----- Create Enemy Body -----
make object box 400+i,100,200,20 :`Enemy Body
color object 400+i,rgb(255,150,0)
make object box 420+i,50,50,50 :`Enemy Head
color object 420+i,rgb(r,g,b)
xrotate object 420+i,45
fix object pivot 420+i
rem Create Enemy Bazooka Tube
make object cylinder 450+i,40 :`Enemy Tennis ball CANNON
set object 450+i,1,1,0
scale object 450+i,60,250,60
color object 450+i,rgb(250,250,0)
xrotate object 450+i,90
fix object pivot 450+i
remend
endfunction
function _move_ailerons()
` vis=static line of sight(camx,camy,camz,enemy#(i,3),enemy#(i,4),enemy#(i,5),1,1)
remstart
if vis=0 :`can enemy head see me, yes then fire ready to fire
if gunangle#(i,1)>0
dec gunangle#(i,1),gunangleinc#
xrotate object eobj+50,gunangle#(i,1)
gunangle#(i,2)=0
else
point object eobj+50,camx,camy-500,camz
gunangle#(i,2)=1
endif
else
if gunangle#(i,1)<120
inc gunangle#(i,1),gunangleinc#
xrotate object eobj+50,gunangle#(i,1)
gunangle#(i,2)=0
endif
endif
remend
endfunction
function _check_turrets()
dist#=3000
`flyer
flyerobj=1
x1#=object position x(flyerobj)
y1#=object position y(flyerobj)
z1#=object position z(flyerobj)
for i=1 to turretcount
turretobj=turret(i).turretobj :`was 700+i-1
radarobj=turret(i).radarobj
`each turrets position
x2#=object position x(turretobj)
y2#=object position y(turretobj)
z2#=object position z(turretobj)
`--- measure the distance of each turret to the flyer
l#=threeD_distance(x1#, y1#, z1#, x2#, y2#, z2#)
if l#<dist#
` position object radarobj,x2#,y2#+150,z2#
point object radarobj,x1#,y1#,z1# :`point turret radar to flyer
color object radarobj,REDCOLOR
ang1=object angle y(turretobj) :`turret angle
ang2=object angle y(radarobj) :`turret radar angle
turret(i).yradarangle=ang2
anglediff=_angle_diff(ang1,ang2)
if anglediff<>0
if anglediff>0
newangle=wrapvalue(ang1+1)
yrotate object turretobj,newangle
else
newangle=wrapvalue(ang1-1)
yrotate object turretobj,newangle
endif
endif
else
newangle=wrapvalue(turret(i).yradarangle+2)
turret(i).yradarangle=newangle
yrotate object radarobj,newangle
color object radarobj,GREENCOLOR
endif
next i
endfunction
function _make_turret()
make object box turretobjnum,100,120,180
color object turretobjnum,rgb(255,0,255)
`index into turret array - number of turrets also
inc turretcount
turret(turretcount).yturretangle=object angle y(turretobjnum)
turret(turretcount).yradarangle=rnd(360) :`was object angle y(turretobjnum)
turret(turretcount).turretobj=turretobjnum
tnum=turretobjnum
inc turretobjnum
endfunction tnum
function _add_scannerbeams(objnum)
scannerobj=objnum+1000
make object box scannerobj,200,200,2000
rotate object scannerobj,135,0,0
position object scannerobj,object position x(objnum),object position y(objnum),object position z(objnum)
color object scannerobj,rgb(255,0,0)
set object ambient scannerobj,0
set object emissive scannerobj,rgb(5,0,0)
OFFSET LIMB scannerobj, 0, 0, 0, 1000
fix object pivot scannerobj
GHOST OBJECT ON scannerobj, 0
`make mesh from object 1,scannerobj
`add limb objnum,1,1
`glue object to limb scannerobj,objnum,0
`set object emissive scannerobj,rgb(10,0,0)
`set limb smoothing objnum,1,100
endfunction
Rem PJY - simple function to calculate the length of a 3D vector using DBPro's inbuilt 3D maths commands
FUNCTION threeD_distance(x1# AS float, y1# AS float, z1# AS float, x2# AS float, y2# AS float, z2# AS float)
null = make vector3(1)
set vector3 1, x1# - x2#, y1# - y2#, z1# - z2#
length_vector# = length vector3(1)
null = delete vector3(1)
ENDFUNCTION length_vector#
rem --- show score on screen
_show_score:
`set cursor 1,1
`print screen fps()
center text screenxcenter,10,"Bulletspeed=: "+str$(bulletspeed)+" TARGETS LEFT: "+str$(targetsleft)+" SCORE: "+str$(score)
set cursor 0,50
print "keypress=";keypress
print "camylookup=";camylookup#
print "lookupflag=";lookupflag
print "exparrayindex=";exparrayindex
for i=1 to 10
` print explosion(i,1)
print partlife(i)
next i
return
_level_completed:
set cursor 0,100
print "Level Completed!!!"
sync
wait key
end
return
`--- check if shot hit any boxes - still working on pyramids
_check_hits:
if hitflag=0
hitnum=object hit(3,0)
if hitnum>=101 :`and hitnum<=101+numpyr
bulletalive=-20
hitflag=1
oldhitnum=hitnum
texture object 3,6
ghost object on 3
if object exist(hitnum)
_set_explosion(hitnum,30,40,300,YELLOW)
hide object hitnum
exclude object on hitnum
set object collision off hitnum
` position object hitnum,object position x(hitnum),5000,object position z(hitnum)
hide object hitnum
exclude object on hitnum
dec targetsleft
endif
endif
endif
return
function getdistance(x#,z#,obj2)
rem Calculate distance between two objects
dx#=object position x(obj2)-x#
dz#=object position z(obj2)-z#
dist#=sqrt((dx#*dx#)+(dz#*dz#))
endfunction dist#
`----------Bullet Routines--------------------------------------------------------------------------------------------
_start_bullet:
rem Calculate position of bullet creation
bx#=newxvalue(x#,a#,100)
bz#=newzvalue(z#,a#,100)
by#=get ground height(1,bx#-mx#,bz#-mz#)+50
by#=h#
rem Begin life of bullet
position object 3,bx#,by#,bz#
rotate object 3,wrapvalue(object angle x(2)-10),a#,0
scale object 3,100,50,100
color object 3,rgb(180,180,230)
fade object 3,100
ghost object off 3
show object 3
bulletalive=50
set object collision on 3
SET OBJECT COLLISION TO SPHERES 3
return
_move_bullet:
rem Arc bullet by slowly rotation X axis whilst moving
xrotate object 3,wrapvalue(object angle x(3)+.4)
move object 3,bulletspeed
rem Detect collision with ground to destroy
if get ground height(1,object position x(3)-mx#,object position z(3)-mz#)>object position y(3) or detonate=1
`if CountCollisionsPRO(3) > 0
rem Show explosion from bullet
bulletalive=-20
texture object 3,6
ghost object on 3
rem At point of impact, make crator
gridunitsize#=(landsize*2.0)/gridxmax :`was 25.0 - now gridxmax
gridx=int((object position x(3)-mx#)/gridunitsize#)
gridz=int((object position z(3)-mz#)/gridunitsize#)
rem Affect matrix with changes
gridy#=get ground height(1,object position x(3)-mx#,object position z(3)-mz#)
for tx=gridx-1 to gridx+1
for ty=gridz-1 to gridz+1
if tx>0 and tx<gridxmax and ty>0 and ty<gridzmax
gridy#=get matrix height(1,tx,ty)
ngy#=gridy#-50-rnd(20)
if ngy#<-500.0 then ngy#=-500.0 :`was -50 in both places, sets crater depth limit
set matrix height 1,tx,ty,ngy#
tt=12-abs((ngy#+50.0)/10.0)
if tt<0 then tt=0
if tt>12 then tt=12
if tx=gridx and ty=gridz
set matrix tile 1,tx,ty,12 :`where shell hits, make darkest
gridtexture(tx,ty)=12
else
if gridtexture(tx,ty)=12
set matrix tile 1,tx,ty,12 :`leave old darker shell hit darker
else
texturenum=9+rnd(2)
set matrix tile 1,tx,ty,texturenum
gridtexture(tx,ty)=texturenum
endif
endif
endif
next ty
next tx
update matrix 1
endif
return
_explode_bullet:
rem Scale up bullet as it explodes
scl=(((50*150))-(((abs(bulletalive))*150)))-3500
scale object 3,scl,scl,scl
fd=abs(bulletalive*10)
if fd<0 then fd=0
fade object 3,fd
xrotate object 3,wrapvalue(object angle x(3)+10)
rem Count down during explosion
bulletalive=bulletalive+1
if bulletalive=0
set object collision off 3
hide object 3
` position object 3,0,5000,0
hitflag=0
endif
return
function _finished_level(level)
set cursor 1,200
print "YOU FINISHED LEVEL - ";level
print "Press a key to continue"
sync
wait key
if level=numlevels
print " "
print "That's all there is for now - Thanks for Playing!"
print "Press a key to exit game - Bye!"
sync
wait key
end
endif
endfunction
function _key_action(keypress)
select keypress
`T key
case 20
if numballs<100
inc numballs,100
endif
endcase
endselect
endfunction
function _terrain_textures()
imsize=64
cellsize=16
cellcount=0
blurflag=0
create bitmap 1,imsize,imsize
for row=1 to 4
for col=1 to 4
inc cellcount
if row<=3
ink rgb(200-(cellcount*10),70-(cellcount*5),0),0
else
ink rgb(100,100,100),0
endif
box cellsize*(col-1)+1,cellsize*(row-1)+1,cellsize*(col)+1,cellsize*(row)+1
x1=cellsize*(col-1)
x2=cellsize*col
y1=cellsize*(row-1)
y2=cellsize*row
if row<4
for x=1 to 50
r=45-(rnd(20)+cellcount)
g=32-(rnd(20)+cellcount)
ink rgb(r,g,0),0
dot x1+rnd(cellsize),y1+rnd(cellsize)
next x
endif
if row=4
if blurflag=0
blur bitmap 1,3
blurflag=1
endif
ink rgb(50,25,0),0
lineinc#=cellsize/8
for liney#=y1 to y2 step lineinc#
line x1,liney#,x2,liney#
next liney#
for linex#=x1 to x2 step lineinc#
line linex#,y1,linex#,y2
next linex#
endif
next col
next row
get image 1,0,0,imsize,imsize
delete bitmap 1
ink rgb(255,255,255),0
endfunction
_intro:
sync
set text font "Arial"
set text size 30
cx=screen width()/2
cy=100
introtext:
data "-green"
data "Mars Flyer Game"
data " "
data "-purple"
data "Fly your ship around and destroy hovering boxes and radar turret objects,"
data " "
data " "
data "-cyan"
data "The ARROW keys control flyer movement"
data "Keys 1,2,3 set flyer firing power"
data "The SPACE bar FIRES!"
data " "
data " "
data "-yellow"
data "Press a key to continue"
data "999"
cls
restore introtext
read t$
while t$<>"999"
if left$(t$,1)="-"
if t$="-green" then ink rgb(0,255,0),0
if t$="-purple" then ink rgb(220,0,220),0
if t$="-yellow" then ink rgb(255,255,0),0
if t$="-cyan" then ink rgb(0,255,255),0
else
center text cx,cy,t$
inc cy,30
endif
read t$
endwhile
sync
wait key
ink rgb(0,255,255),0
cls
sync
return
function _make_rail(objid,xsize,ysize,zsize,color,posx,posz,yangle)
make object box objid,xsize,ysize,zsize
color object objid,color
if angle<>0
rotate object objid,0,yangle,0
endif
position object objid,posx,posy,posz
set text size 16
endfunction
`--------DB demo routines for explosions--------
`--- (explosion x,y,z, num particles, explosion intensity, life of particles, particle index, color)
function _request_explosion(ex#,ey#,ez#,particles,intensity#,life,partindex,color)
count=0
for i=partindex to partindex+particles
partlife(i)=life + rnd(life/2) :`was rnd(life/5)
partx#(i)=ex#
party#(i)=ey#
partz#(i)=ez#
partyvel#(i)=rnd(intensity#)-(intensity#/4)
partxvel#(i)=rnd(intensity#)-(intensity#/2)
partzvel#(i)=rnd(intensity#)-(intensity#/2)
inc count
partyrot#(i)=5+rnd(5)
partxrot#(i)=5+rnd(5)
partzrot#(i)=5+rnd(5)
show object 199+i
color object 199+i,rgb(rnd(255),rnd(255),rnd(255)) :`color
next i
endfunction
`explosion 1=active flag, 2=object, 3=#particles, 4=intensity, 5=particle life, 6=particle start num,
` 7=color, 8=rotx, 9=roty, 10=rotz
function _continue_explosion()
for ex=1 to 10
if explosion(ex,1)=2
for t=explosion(ex,6) to explosion(ex,6)+explosion(ex,3)
if partlife(t)>1
dec partlife(t)
position object 199+t,partx#(t),party#(t),partz#(t)
partxvel#(t)=partxvel#(t)*0.99 :`was 0.95 then 0.98
partyvel#(t)=partyvel#(t)*0.99
partzvel#(t)=partzvel#(t)*0.99 :`particles slow down from air friction
`` partzvel#(t)=0.0
partyvel#(t)=partyvel#(t)-0.15 :`was -0.5 particles effected by gravity
inc partx#(t),partxvel#(t)
inc party#(t),partyvel#(t)
inc partz#(t),partzvel#(t)
` if party#(t)<=0 then partyvel#(t)=partyvel#(t)*-0.7 :`particles bounce on the ground
`particles bounce on the ground
if party#(t)<=get ground height(1,partx#(t),partz#(t)) then partyvel#(t)=partyvel#(t)*-0.7
` rotate object t+199,wrapvalue(object angle x(t+199)+rnd(50)),wrapvalue(object angle y(t+199)+rnd(100)),0
`xrot=explosion(exparrayindex,8)
`yrot=explosion(exparrayindex,9)
`zrot=explosion(exparrayindex,10)
xrot=partxrot#(t)
yrot=partyrot#(t)
zrot=partzrot#(t)
rotate object t+199,wrapvalue(object angle x(t+199)+xrot),wrapvalue(object angle y(t+199)+xrot),0
endif
if partlife(t)=1
partlife(t)=0
hide object 199+t
start_time=0
expdone=1
partxvel#(t)=0
partyvel#(t)=0
partzvel#(t)=0
` explosion(ex,1)=0
endif
next t
endif
next ex
endfunction
`--- array entry for another explosion ---
function _set_explosion(object,numparticles,intensity,particlelife,color)
explosion(exparrayindex,1)=1 :`explosion flag 1=on 0=off
explosion(exparrayindex,2)=object :`object to explode
explosion(exparrayindex,3)=numparticles :`number of particles
explosion(exparrayindex,4)=intensity :`intensity
explosion(exparrayindex,5)=particlelife :`particle life
explosion(exparrayindex,7)=color :`color of particles
explosion(exparrayindex,8)=rnd(5) :`x-rotation
explosion(exparrayindex,9)=rnd(5) :`y-rotation
explosion(exparrayindex,10)=rnd(5) :`z-rotation
inc exparrayindex
if exparrayindex>10 then exparrayindex=1
endfunction
function _check_newexplosions()
for ex=1 to 10
if explosion(ex,1)=1
ex#=object position x(explosion(ex,2))
ey#=object position y(explosion(ex,2))
ez#=object position z(explosion(ex,2))
if expparticleindex+explosion(ex,3)>=200
expparticleindex=1
endif
explosion(ex,6)=expparticleindex
inc expparticleindex,explosion(ex,3)
`---- explosion() 1=active flag, 2=object, 3=#particles, 4=intensity, 5=particle life, 6=particle start num, 7=color
_request_explosion(ex#,ey#,ez#,explosion(ex,3),explosion(ex,4),explosion(ex,5),explosion(ex,6),explosion(ex,7))
start_time=1
hide object explosion(ex,2) :`was explode_object
set object collision off explosion(ex,2) :`was explode_object
explosion(ex,1)=2
endif
next ex
endfunction