Challenge: 
Winner?: 
No
Code Snippet: 
Rem ***** Main Source File *****
Rem asteroid attack 3d by Jetmech
rem ****************** Thanx to Ric for the awesome sound function!*********************
sync on
sync rate 0
set text font "arial" : set text size 13
set text to bold : set text transparent
autocam off
color backdrop 0
randomize timer()
position camera 0,0,0
hide mouse
make object sphere 6,4000,15,15
position object 6,0,0,0
color object 6,RGB(14,0,44)
set object cull 6,0
force=80
sc#=100
createsound("explosion",3,20,1400,8000,10000.00,0.5,0,0,0,0)
createsound("bass hit",9,20,200,14000,0.00,1.2,.0,0,0,0)
make object sphere force,100,15,15
position object force,0,50,0
hide object force
ghost object on force
`--------------------------------------------------------
`matrix setup
`--------------------------------------------------------
for grassx=0 to 39
for grassy=0 to 39
ink rgb(20,rnd(100)+100,20),rgb(0,0,0)
dot grassx,grassy
next grassy
next grassx
get image 1,0,0,40,40
 
make matrix 1,6000,6000,10,10
prepare matrix texture 1,1,1,1
position matrix 1,-3000,-100,-3000
randomize matrix 1,10
set matrix wireframe off 1
update matrix 1
`--------------------------------------------------------
`type setup
`--------------------------------------------------------
type bullet
currentbullet
bullalive
explode
time as float
bullscale
distance as float
distmissle as float
score
endtype
dim bull(30) as bullet
bull(0).currentbullet=10
Type enemymissles
enemyscale
distcity
explode
wave
speed as float
etime as float
endtype
dim enemy(15) as enemymissles
enemy(0).wave = 70
FOR spd=0 to 15
enemy(spd).speed = .5
next
type citydata
destroyed
damage
gameover
endtype
dim city(5) AS citydata
`--------------------------------------------------------
`game setup
`--------------------------------------------------------
citysetup()
bulletsetup()
enemysetup()
`--------------------------------------------------------
`main loop
`--------------------------------------------------------
do
checkdist()
moveenemy()
camcontrol()
Display_UWProgramInfo()
movebullet()
hud()
explode()
` the Time variable is returned from the timer function and determines the fire rate
if timer() > time# + 150
if mouseclick()=1 then time# = fire()
endif
if mouseclick()=2 and throw = 0
throw=1
set object to camera orientation force
show object force
starttime = timer()
endif
if throw=1 then throw = forcefield(force)
if throw=2
sc#=sc#+.5
if sc#=>300 then sc#=300
scale object force,sc#,sc#,sc#
if timer()-starttime> 8000
hide object force
position object force,0,50,0
sc#=100.00
scale object force,sc#,sc#,sc#
throw=0
endif
endif
sync
loop
 
`--------------------------------------------------------
`camera controls
`--------------------------------------------------------
Function camcontrol()
camx#=camera angle x()+mousemovey()/2.0
camy#=camera angle y()+mousemovex()/2.0
if camx#>20 then camx#=20
if camx#<-90 then camx#=-90
if camy#<-90 then camy# = -90
if camy#>90 then camy# = 90
rotate camera camx#,camy#,0
endfunction
 
`--------------------------------------------------------
`info loop
`--------------------------------------------------------
Function Display_UWProgramInfo()
text 0,0,"Fps:"+str$(screen fps())
text 300,0,"SCORE: "+ str$(bull(0).score)
sz=object size(80)
text 0,100,str$(sz)
EndFunction
function citysetup()
for cty = 1 to 5
make object box cty,50,20,50
color object cty,RGB(0,128,128)
city(cty).damage=100
position object cty, rnd(2000)-1000,-90,rnd(200)+500
next cty
endfunction
function bulletsetup()
for bx=0 to 9
for by=0 to 9
ink RGB(255,255,0),rgb(0,0,0)
dot bx,by
next by
next bx
get image 2,0,0,10,10
for bullet=10 to 20
make object sphere bullet,2,5,5
texture object bullet,2
set object light bullet,0
hide object bullet
position object bullet,rnd(5)-rnd(5),rnd(10)-15,0
bull(bullet-10).bullscale=100
next bullet
endfunction
function fire()
if bull(0).currentbullet = 20 then bull(0).currentbullet = 10
if bull(bull(0).currentbullet-10).bullalive=0
set object to camera orientation bull(0).currentbullet
show object bull(0).currentbullet
bull(bull(0).currentbullet-10).bullalive=1
play sound 9
hide object bull(0).currentbullet
move object bull(0).currentbullet,20
show object bull(0).currentbullet
inc bull(0).currentbullet
endif
oldtime#= timer()
endfunction oldtime#
function movebullet()
for bullcount=10 to 20
if bull(bullcount-10).bullalive=1 and bull(bullcount-10).explode = 0
move object bullcount,12
endif
next bullcount
endfunction
function enemysetup()
for bx=0 to 9
for by=0 to 9
ink RGB(rnd(100)+50,rnd(30)+30,rnd(30)+30),rgb(0,0,0)
dot bx,by
next by
next bx
get image 3,0,0,10,10
for E = 60 to enemy(0).wave
make object sphere E,rnd(20)+20,rnd(6)+4,rnd(6)+4
texture object e,3
position object E,rnd(2000)-1000,1000,rnd(2000)-1000
repeat
cty = rnd(4)+1
until city(cty).destroyed=0
point object E, object position x(cty)+ rnd(100)-50, -100, object position z(cty)+ rnd(100)-50
enemy(E-60).enemyscale = 100
next E
endfunction
 
function hud()
Ink RGB(255,0,0),0
circle Screen Width()/2, (Screen Height()/2)+5,3
Dot Screen Width()/2, (Screen Height()/2)+15
Dot Screen Width()/2, (Screen Height()/2)-5
endfunction
function moveenemy()
for e=60 to enemy(0).wave
if enemy(e-60).explode = 0
move object e,enemy(e-60).speed
if object position y(e) < -99
enemy(e-60).explode = 1
play sound 3
endif
endif
next e
endfunction
 
function explode()
for bullcount=10 to 20
if bull(bullcount-10).explode=1
if sound playing(3) =0
play sound 3
endif
ghost object on bullcount
if particles exist(bullcount) = 0
make particles bullcount,2,10,30
color particles bullcount,rnd(254)+1,rnd(254)+1,rnd(254)+1
set particle emissions bullcount,1
set particle life bullcount,20
set particle gravity bullcount,1
bull(bullcount-10).time=timer()
endif
position particles bullcount,object position x(bullcount),object position y(bullcount),object position z(bullcount)
scale object bullcount,bull(bullcount-10).bullscale,bull(bullcount-10).bullscale*.05,bull(bullcount-10).bullscale
inc bull(bullcount-10).bullscale,40
fade object bullcount,0
if timer()>bull(bullcount-10).time+150
set particle emissions bullcount,0
endif
if bull(bullcount-10).bullscale => 2500
bull(bullcount-10).bullscale = 100
scale object bullcount,bull(bullcount-10).bullscale,100,bull(bullcount-10).bullscale
position object bullcount,rnd(5)-rnd(5),rnd(10)-15,0
hide object bullcount
delete particles bullcount
bull(bullcount-10).bullalive=0
bull(bullcount-10).explode = 0
ghost object off bullcount
endif
endif
 
next bullcount
for e=60 to enemy(0).wave
if enemy(e-60).explode =1
hide object e
if particles exist(e) = 0
make particles e,2,10,30
color particles e,rnd(254)+1,rnd(254)+1,rnd(254)+1
set particle emissions e,1
set particle floor e,0
set particle gravity e,1
enemy(e-60).etime=timer()
position particles e,object position x(e),object position y(e),object position z(e)
position object e,rnd(2000)-1000,1000,rnd(2000)-1000
endif
` position particles e,object position x(e),object position y(e),object position z(e)
if timer()>enemy(e-60).etime+200
set particle emissions e,0
endif
if timer()>enemy(e-60).etime+2500
delete particles e
enemy(e-60).explode =0
continue=0
repeat
cty = rnd(4)+1
if city(cty).destroyed=0
continu=1
obx = object position x(cty)+ rnd(100)-50
obz = object position z(cty)+ rnd(100)-50
endif
for dead= 1 to 5
if city(dead).destroyed = 1 then count=count +1
next dead
if count = 5
GameOver()
continu=1
obx = rnd(2000)-1000
obz = rnd(200)+500
endif
until continu=1
` position object e,rnd(2000)-1000,1000,rnd(2000)-1000
point object E, obx, -100,obz
show object e
enemy(e-60).speed= enemy(e-60).speed +.05
endif
endif
next e
for cty = 1 to 5
if object exist(cty)
if city(cty).destroyed = 1
ghost object on cty
fade object cty,50
delete object cty
endif
endif
next cty
endfunction
function checkdist()
for bullcount = 10 to 20
`--------determin object distance--------------
xd# = 0 - object position x(bullcount)
yd# = 20 - object position y(bullcount)
zd# = 0 - object position z(bullcount)
bull(bullcount-10).distance = sqrt((xd#*xd#) + (yd#*yd#) + (zd#*zd#))
`----------------------------------------------
if bull(bullcount-10).distance >1500
bull(bullcount-10).bullalive=0
position object bullcount,rnd(5)-rnd(5),rnd(10)-15,0
hide object bullcount
endif
`--------determin bullet distance from missle--------------
for missle = 60 to enemy(0).wave
xd2# = object position x(missle) - object position x(bullcount)
yd2# = object position y(missle) - object position y(bullcount)
zd2# = object position z(missle) - object position z(bullcount)
fxd2# = object position x(missle) - object position x(80)
fyd2# = object position y(missle) - object position y(80)
fzd2# = object position z(missle) - object position z(80)
bull(bullcount-10).distmissle = sqrt((xd2#*xd2#) + (yd2#*yd2#) + (zd2#*zd2#))
forcedist# = sqrt((fxd2#*fxd2#) + (fyd2#*fyd2#) + (fzd2#*fzd2#))
if forcedist# < object size(80)+object size(missle)
enemy(missle-60).explode = 1
endif
if bull(bullcount-10).distmissle < bull(bullcount-10).bullscale/20
if enemy(missle-60).explode = 0 then bull(0).score = bull(0).score + ((enemy(missle-60).speed*2)+ (100/object size(missle)))
bull(bullcount-10).explode=1
enemy(missle-60).explode = 1
endif
if bull(bullcount-10).bullscale=100
if bull(bullcount-10).distmissle < object size(missle)
if enemy(missle-60).explode = 0 then bull(0).score = bull(0).score + ((enemy(missle-60).speed*2)+ (100/object size(missle)))
bull(bullcount-10).explode=1
enemy(missle-60).explode = 1
endif
endif
for cty = 1 to 5
if object exist(cty)
xd3# = object position x(missle) - object position x(cty)
yd3# = object position y(missle) - object position y(cty)
zd3# = object position z(missle) - object position z(cty)
enemy(missle-60).distcity = sqrt((xd3#*xd3#) + (yd3#*yd3#) + (zd3#*zd3#))
if enemy(missle-60).distcity < 70
dec city(cty).damage,50
if city(cty).damage =< 0 then city(cty).destroyed = 1
endif
endif
next cty
next missle
next bullcount
endfunction
 
 
function createsound(name$,soundnumber,frequency#,length#,loudness#,bend#,decay#,vibratospeed#,vibratodepth#,tremelospeed#,tremelodepth#)
if file exist(name$+".wav")=1 then delete file name$+".wav"
open to write 1,name$+".wav"
chunk=int(((length#/1000)*44100*16)/8) `sample size (no of samples * bitrate * channels / 8)
samples=int((length#/1000)*44100) `length *44100
restore
for x=1 to 40
read byte2
write byte 1, byte2
next x
write long 1,chunk
rem generate and write wave
for x=1 to samples
output#=int(sin((x/122.5)*(frequency#+vibratodepth#*sin(theta#)))*(loudness#+tremelodepth#*sin(phi#)))*3.0
inc theta#,vibratospeed#
inc phi#,tremelospeed#
dec frequency#,bend#
if loudness#>0 then dec loudness#,decay#
write word 1,output#
next x
close file 1
load sound name$+".wav",soundnumber
data 82:data 73:data 70:data 70:data 208:data 59:data 1:data 0:data 87
data 65:data 86:data 69:data 102:data 109:data 116:data 32:data 16
data 0:data 0:data 0:data 1:data 0:data 2:data 0:data 34:data 86:data 0
data 0:data 136:data 88:data 1:data 0:data 4:data 0:data 16:data 0
data 100:data 97:data 116:data 97
endfunction
Function GameOver()
for e=60 to enemy(0).wave
enemy(e-60).speed=10
next e
city(0).gameover = 1
endfunction
Function Forcefield(force)
move object force,10
pitch object down force,.5
if get ground height(1,object position x(force), object position z(force)) => object position y(force)+object size(force)*2
throw=2
else
throw=1
endif
endfunction throw