remstart **************************************************************************** * * * Author: Mark Joyce * * Forum: Spooky * * Compile: Designed for 800 * 600 * 32bit in Fullscreen Exclusive Mode * * Anything else will give wierd results * * Tested: DarkBASIC Professional with Upgrade 5.1b * * * **************************************************************************** remend hide mouse : sync on : sync rate 0 : autocam off : randomize timer() : set global collision on : color backdrop rgb(0,0,0) rem stuff that is done once only null=make vector2(1) null2=make vector3(2) global xs,zs,xw,zw,xm,zm rem vars - constants #constant runmode = 1 ` 0 = developer mode, shows diagnostic stuff and allows edit mode with F1 ` 1 = real mode for compo, gets rid of diagnostic stuff and doesn't allow edit mode #constant skytrim = 9 ` number of pixels to trim sky edges to get rid of seams #constant skysize = 7500 ` size of sky plains #constant bulletlife = 1500 ` life of bullets in milliseconds #constant bulletmax = 10 ` max number of bullets #constant bulletwait = 200 ` time between bullets #constant bulletspeed = 1000.0 ` how many units per second per loop specified below (MUST put .0 on end) #constant bulletloop = 2 ` how many loops per frame #constant ufospeed = 800.0 ` units per sec for ufo (MUST put .0 on end) rem load images to keep in memory load image "images\loading.png",999,1 mainmenu: enable escapekey : clear entry buffer rem show loading screen whilst loading stuff for main menu ink rgb(0,0,0),rgb(0,0,0) : cls paste image 999,400-(437/2),300-(143/2),1 sync rem load images needed for main menu load image "images\abducted.png",1,1 load image "images\start.png",2,1 load image "images\startr.png",3,1 load image "images\cursor.png",4,1 load image "images\blue.jpg",5 load image "images\pixel.png",6,1 load image "images\exit.png",7,1 load image "images\exitr.png",8,1 load image "images\spooky.png",9,1 load image "images\logos.png",10,1 load image "images\help.png",11,1 load image "images\helpr.png",12,1 load image "images\helpscreen.png",13,1 rem create sprites for buttons to make it easier to detect what mouse is on sprite 1,(800-783)/2,10,1 sprite 2,(800-269)/2,250,2 sprite 5,(800-215)/2,500,7 sprite 6,(800-200),(600-150),9 sprite 7,0,(600-150),10 sprite 8,(800-219)/2,350,7 sprite 9,0,1000,13 rem create couple of big spheres, texture with blue image make object sphere 1,2000 set object 1,1,1,0,2,0,0,0 texture object 1,5 make object sphere 2,1900 ghost object on 2 set object 2,1,1,0,2,0,0,0 texture object 2,5 position camera 0,0,0 : rotate camera 0,0,0 load music "music\music2.mid",1 : loop music 1 t1=timer() scr=0 lk=timer() do gosub timerstuff turn object left 1,div#*4.0 turn object right 2,div#*5.0 sprite 3,mousex(),mousey(),4 : sprite 4,mousex(),mousey(),6 if scr=0 if sprite collision(4,2)=1 sprite 2,sprite x(2),sprite y(2),3 if mouseclick()=1 and (timer()-lk > 500) then exit else sprite 2,sprite x(2),sprite y(2),2 endif if sprite collision(4,8)=1 sprite 8,sprite x(8),sprite y(8),12 if mouseclick()=1 and (timer()-lk > 500) scr=1 for f=1 to 8 if f <> 3 and f <> 4 move sprite f,1000 endif next f sprite 9,0,0,13 lk=timer() disable escapekey clear entry buffer endif else sprite 8,sprite x(8),sprite y(8),11 endif if sprite collision(4,5)=1 sprite 5,sprite x(5),sprite y(5),8 if mouseclick()=1 and (timer()-lk > 500) then end else sprite 5,sprite x(5),sprite y(5),7 endif else if (mouseclick()=1 or scancode()<>0) and ((timer()-lk) > 500) for f=1 to 8 if f <> 3 and f <> 4 move sprite f,-1000 endif sprite 9,0,1000,13 next f scr=0 lk=timer() enable escapekey clear entry buffer endif endif sync loop rem you have clicked START, so delete all the loaded stuff clear entry buffer stop music 1 : delete music 1 for f=1 to 9 : delete sprite f : next f for f=1 to 13 : delete image f : next f for f=1 to 2 : delete object f : next f rem show LOADING screen ink rgb(0,0,0),rgb(0,0,0) cls paste image 999,400-(437/2),300-(143/2),1 sync ink rgb(255,255,255),rgb(0,0,0) disable escapekey rem vars - changable mode=0 ; ` 0=play,1=edit diag=0 : ` diag mode, 0 or 1 where 1 shows diag objects around player r#=15 : ` player radius r2#=20 : ` alien radius frc#=30 : ` force (bigger number means bigger slopes can be climbed) slide#=10 : ` how steep before autoslide objcol#=7 : ` object collision sensitivity sp=12 : ` number of collision objects around player (more=smoother max=16) sp2=8 : ` alien collision spheres (max=16) spr#=4 : ` radius of collision spheres ch=75 : ` height above ground of player's eyes mangu#=50 : ` maximum angle you can look up mangd#=80 : ` maximum angle you can look down midx#=3 : ` smoothness of mouse camera (higher=smoother) crg=6700 : ` camera range poff=200 : ` sky height offset objoff=500 : ` units over mat edge before cull t9=500 : ` update interval for frame rate limiter s1#=250 : ` move units per sec (game) s2#=1000 : ` move units per game (editor) alc=5 : ` number of aliens (1-10) ammo=999 : ` start ammo rem init matrix variables xs=100 : zs=100 : ` tile size xw=300 : zw=300 : ` total tiles xm=79 : zm=79 : ` virtual tiles xt=150 : zt=150 : ` start tile rem vars - other sp2#=(360.0/sp) sp3#=(360.0/sp2) s3#=s1# po=(skysize/2)-skytrim ob1=0 ob2=0 fogstatus=0 seltex=1 selx=-1 : selz=-1 : selc=1 if sp > sp2 : spmax=sp : else : spmax=sp2 : endif ang#=0 mv#=0 mv1=0 : mv2=0 : mv3=0 : mv4=0 alphaok=alpha available() rem images load image "images\tiles.jpg",1 load image "objects\alien_gn.jpg",2 load image "objects\laser.bmp",3 load image "images\bullet.png",4 load image "images\green.jpg",5 load image "images\glass.jpg",6 for f=0 to 9 f$="images\num" + str$(f) + ".png" load image f$,10+f,1 next f load image "images\ammo.png",20,1 load image "images\sky2.jpg",90 load image "images\sky3.jpg",91 load image "images\sky4.jpg",92 load image "images\sky1.jpg",93 load image "images\sky5.jpg",94 load image "images\tilesthumb.png",95,1 load image "images\select.png",96,1 load image "images\pointer.png",98,1 load image "images\sand.jpg",103 load image "images\lava.jpg",104 load image "images\brass.png",105 load image "images\pattern.jpg",106 rem objects load object "objects\laserrif.x",1 : set object collision off 1 load object "objects\alien.x",2 : hide object 2 : set object collision off 2 load object "objects\pyramid.x",100 : hide object 100 : set object collision off 100 load object "objects\dbpyramid.x",101 : hide object 101 : set object collision off 101 rem sounds load sound "sounds\phaser.wav",1 load sound "sounds\aliendie.wav",2 load sound "sounds\scifi1.wav",3 rem music load music "music\music.mid",1 rem sky for f=1 to 5 make object plain 89+f,skysize,skysize set object light 89+f,0 set object fog 89+f,0 texture object 89+f,89+f set object collision off 89+f set object filter 89+f,2 next f yrotate object 91,270 yrotate object 92,0 yrotate object 93,90 xrotate object 94,90 : yrotate object 94,90 rem init calculations dim ofs#(sp-1,1) for r=0 to (sp-1) ex#=newxvalue(0,r*sp2#,r#) : ez#=newzvalue(0,r*sp2#,r#) : ofs#(r,0)=ex# : ofs#(r,1)=ez# next r dim ofs2#(sp2-1,1) for r=0 to (sp2-1) ex#=newxvalue(0,r*sp3#,r2#) : ez#=newzvalue(0,r*sp3#,r2#) : ofs2#(r,0)=ex# : ofs2#(r,1)=ez# next r rem init view stuff make light 1 : set directional light 1,1,-1,1 : set camera range 1,crg gosub fogon rem init collision stuff make object cube 30,200 : hide object 30 make object cylinder 31,spr# : scale object 31,100,4300,100 : hide object 31 if diag=1 for f=0 to spmax-1 make object cylinder 40+f,spr# : scale object 40+f,100,4300,100 : set object collision off 40+f make object sphere 40+f+spmax,spr#+1 : color object 40+f+spmax,rgb(255,0,0) : set object collision off 40+f+spmax next f endif rem init editor stuff for f=95 to 98 make object sphere f,5 : hide object f : set object collision off f next f rem make matrix make matrix 1,xs*xm,zs*zm,xm,zm : prepare matrix texture 1,1,8,4 : set matrix 1,0,0,1,1,1,1,1 rem load matrix data OR if file not found then generate some random hills f$="level\map.txt" dim m(xw,zw,2) if file exist(f$)=1 open to read 1,f$ for f=0 to xw for g=0 to zw s1$="" : s2$="" : s3$="" read string 1,s$ if s$ <> "" h=1 for i=1 to len(s$) c$=mid$(s$,i) if c$="," inc h else if h=1 s1$=s1$+c$ else if h=2 s2$=s2$+c$ else s3$=s3$+c$ endif endif endif next i endif if s1$="" then s1$="0" if s2$="" then s2$="0" if s3$="" then s3$="1" m(f,g,0)=val(s1$) m(f,g,1)=val(s2$) m(f,g,2)=val(s3$) if runmode = 0 if m(f,g,2)<>1 or f<2 or f>(xw-2) or g<2 or g>(zw-1) dot f/2,(300-g)/2 endif else if f<2 or f>(xw-2) or g<2 or g>(zw-1) dot f/2,(300-g)/2 endif endif next g next f close file 1 else rem set all normals to 0 (bright), heights to random, tiles to 1 (grass) for f=0 to 300 for g=0 to 300 m(f,g,0)=0 m(f,g,1)=rnd(700) if f < 300 and g < 300 m(f,g,2)=1 endif next g next f rem create some random BIG hills for f=1 to 50 v1=rnd(270)+15 v2=rnd(270)+15 for xx=-1 to 1 for zz=-1 to 1 m(v1+xx,v2+zz,1)=1000+rnd(1000) next zz next xx next f rem rough smoothing it=3 : gosub smooth rem find lowest point minh=9999 for f=2 to 298 for g=2 to 298 h=m(f,g,1) if h < minh then minh=h next g next f rem set area around start point to flat for xx=-15 to 15 for zz=-15 to 15 m(150+xx,150+zz,1)=minh next zz next xx rem mountains around edge of game v1=1000 : v2=500 for f=0 to 300 for g=0 to 2+rnd(4) m(g,f,1)=v1+rnd(v2) m(300-g,f,1)=v1+rnd(v2) m(f,g,1)=v1+rnd(v2) m(f,300-g,1)=v1+rnd(v2) next g next f rem smooth some more it=3 : gosub smooth rem find low point again minh=9999 for f=2 to 298 for g=2 to 298 h=m(f,g,1) if h < minh then minh=h next g next f rem lower whold thing so lowest point is at 0 for f=0 to 300 for g=0 to 300 newh=m(f,g,1)-minh m(f,g,1)=newh next g next f rem set normals so dark areas on unlit side of hills for x=0 to 300 for y=0 to 300 a=m(x,y,1) if x > 0 and y > 0 b=m(x-1,y-1,1) endif if a < b m(x,y,0)=1 if a < (b-20) m(x,y,0)=2 endif if a < (b-50) m(x,y,0)=3 endif if a < (b-100) m(x,y,0)=4 endif endif next y next x endif rem level map for edit mode get image 97,0,0,150,150,1 : cls rem position player xp=xt : zp=zt gosub moveplayer x#=xmid(xp) : y#=0 : z#=zmid(zp) position camera x#,y#,z# rem The idea WAS to have all following objects loaded from an editor but just done manually cubes=30 dim objs(cubes) rem lava1 make object plain 150,3000,3000 texture object 150,104 position object 150,15000,-101,15000 xrotate object 150,270 scale object texture 150,8,8 set object collision off 150 objs(1)=1 rem lava2 make object plain 151,3000,3000 texture object 151,104 position object 151,15000,-100,15000 xrotate object 151,270 scale object texture 151,10,10 set object collision off 151 ghost object on 151 objs(2)=1 rem pyramid clone object 152,101 position object 152,14000,800,18000 scale object 152,1000,1000,1000 set object cull 152,0 objs(3)=0 rem doorway to pyramid make object box 153,40,200,100 texture object 153,103 position object 153,13850,200,17500 objs(4)=0 rem doorway to pyramid make object box 154,40,200,100 texture object 154,103 position object 154,14050,200,17500 objs(5)=0 rem doorway to pyramid make object box 155,500,20,110 texture object 155,103 position object 155,14000,300,17500 objs(6)=0 rem rotating thingy make object box 156,400,30,300 texture object 156,105 position object 156,13000,200,15000 yrotate object 156,30 objs(7)=0 rem cave1 make object box 157,800,200,20 texture object 157,106 scale object texture 157,4,2 position object 157,14000,170,12000 turn object left 157,8 set object light 157,0 objs(8)=0 rem cave2 o=158 : objs(o-149)=0 make object box o,800,200,20 texture object o,106 scale object texture o,4,2 position object o,14000,170,11800 turn object right 158,8 set object light 158,0 rem cave3 o=159 : objs(o-149)=0 make object box o,795,20,300 texture object o,106 scale object texture o,4,2 position object o,14000,260,11900 set object light o,0 o=159 : ` 11-20 = pyramids (160-169) for f=1 to 10 inc o : objs(o-149)=0 clone object o,100 texture object o,105 position object o,13500+(f*300),120,13000 next f rem crystals (170-179 21-30) power=10 : ` 10 cubes to collect oox = 140 : ooz = 181 inc o : objs(o-149)=2 make object cube o,30 : texture object o,5 : ghost object on o : set object cull o,0 : set object light o,0 ox=xmid(oox) : oz=zmid(ooz) : oh=m(oox,ooz,1) : position object o,ox,oh+30,oz oox = 126 : ooz = 146 inc o : objs(o-149)=2 make object cube o,30 : texture object o,5 : ghost object on o : set object cull o,0 : set object light o,0 ox=xmid(oox) : oz=zmid(ooz) : oh=m(oox,ooz,1) : position object o,ox,oh+30,oz oox = 133 : ooz = 119 inc o : objs(o-149)=2 make object cube o,30 : texture object o,5 : ghost object on o : set object cull o,0 : set object light o,0 ox=xmid(oox) : oz=zmid(ooz) : oh=m(oox,ooz,1) : position object o,ox,oh+30,oz oox = 197 : ooz = 57 inc o : objs(o-149)=2 make object cube o,30 : texture object o,5 : ghost object on o : set object cull o,0 : set object light o,0 ox=xmid(oox) : oz=zmid(ooz) : oh=m(oox,ooz,1) : position object o,ox,oh+30,oz oox = 101 : ooz = 198 inc o : objs(o-149)=2 make object cube o,30 : texture object o,5 : ghost object on o : set object cull o,0 : set object light o,0 ox=xmid(oox) : oz=zmid(ooz) : oh=m(oox,ooz,1) : position object o,ox,oh+30,oz oox = 257 : ooz = 206 inc o : objs(o-149)=2 make object cube o,30 : texture object o,5 : ghost object on o : set object cull o,0 : set object light o,0 ox=xmid(oox) : oz=zmid(ooz) : oh=m(oox,ooz,1) : position object o,ox,oh+30,oz oox = 137 : ooz = 233 inc o : objs(o-149)=2 make object cube o,30 : texture object o,5 : ghost object on o : set object cull o,0 : set object light o,0 ox=xmid(oox) : oz=zmid(ooz) : oh=m(oox,ooz,1) : position object o,ox,oh+30,oz oox = 23 : ooz = 224 inc o : objs(o-149)=2 make object cube o,30 : texture object o,5 : ghost object on o : set object cull o,0 : set object light o,0 ox=xmid(oox) : oz=zmid(ooz) : oh=m(oox,ooz,1) : position object o,ox,oh+30,oz oox = 27 : ooz = 23 inc o : objs(o-149)=2 make object cube o,30 : texture object o,5 : ghost object on o : set object cull o,0 : set object light o,0 ox=xmid(oox) : oz=zmid(ooz) : oh=m(oox,ooz,1) : position object o,ox,oh+30,oz oox = 142 : ooz = 14 inc o : objs(o-149)=2 make object cube o,30 : texture object o,5 : ghost object on o : set object cull o,0 : set object light o,0 ox=xmid(oox) : oz=zmid(ooz) : oh=m(oox,ooz,1) : position object o,ox,oh+30,oz rem END fo setting up manual objects rem setup initial alien set object smoothing 2,100 texture object 2,2 rem aliens dim aliens(alc-1,1) aliencount=0 for f=1 to alc o=9+f clone object o,2 yrotate object o,180 fix object pivot o scale object o,30,30,30 hide object o set object collision off o next f rem gun texture object 1,3 rotate object 1,0,180,0 fix object pivot 1 offset limb 1,0,-0.5,-0.8,-1.2 scale object 1,1000,1000,1000 set object collision off 1 disable object zdepth 1 rem bullet box make object box 3,1,1,20 set object collision off 3 hide object 3 rem bullets bullet=0 dim bullets#(bulletmax-1,2) dim bullets(bulletmax-1) lastbullet=timer() for f=1 to bulletmax o=19+f make object plain o,8,8 texture object o,4 set object transparency o,2 set object collision off o set object light o,0 hide object o next f rem sprites for editor sprite 95,200,0,95 : hide sprite 95 sprite 96,0,0,96 : hide sprite 96 sprite 97,650,0,97 : if runmode = 0 then hide sprite 97 sprite 98,650,10,98 : if runmode = 0 then hide sprite 98 rem create ammo qty sprites gosub updateammo rem create power sprite gosub updatepower rem ammo sprite sprite 13,670,523,20 rem make ufo make object sphere 75,200,5,32 : set object collision off 75 : scale object 75,100,20,100 : texture object 75,6 make object sphere 76,50 : set object collision off 76 : texture object 76,6 make object sphere 77,30 : scale object texture 77,5,5 : texture object 77,5 set object light 77,0 : set object collision off 77 for f=1 to 3 make object sphere 77+f,10 : set object light 77+f,0 : set object collision off 77+f : texture object 77+f,5 next f for f=75 to 80 : hide object f : next f shipx#=0 : shipy#=0 : shipz#=0 shipxa#=0 : shipya#=0 : shipza#=0 make object cylinder 81,50 : scale object 81,100,1000,100 : set object collision off 81 : hide object 81 ghost object on 81 set object cull 81,0 : texture object 81,5 : set object light 81,0 gosub moveufo loop music 1 set music volume 1,200 ufo=0 t1=timer() : lk=t1 rem ******************************************************************************************************************************* do gosub timerstuff ang#=wrapvalue(ang#+(30.0*div#)) s4#=s3#*div# rem lava if object visible(150) scroll object texture 150,0.002*sin(ang#),0.003*cos(ang#) scroll object texture 151,0.001*sin(60-ang#),0.001*cos(130-ang#) endif rem rotating thingy if object visible(156) pitch object down 156,20.0*div# endif rem rotate remaining power cubes for f=1 to cubes if objs(f) = 2 o=149+f if object visible(o) turn object left o,30.0*div# pitch object up o,20.0*div# endif endif next f x#=camera position x() : y#=camera position y() : z#=camera position z() xa#=camera angle x() : ya#=camera angle y() : za#=camera angle z() gosub move if mode=0 then gosub collision if mode=0 and bullet > 0 then gosub bulletmove gosub matmove gosub hidestuff gosub cameraview gosub sky if mode=0 rem collect power cube if mj > 0 objs(mj)=3 dec power gosub updatepower o=149+mj set object collision off o delete object o play sound 3 if power = 0 then exit endif rem control ufo if ufo=0 if alc <> aliencount gosub newalienpos shiph#=get ground height(1,alx#-xvm,alz#-zvm) shiph2#=shiph#+4000 shiph3#=shiph#+300 shipx#=alx# : shipz#=alz# : shipy#=shiph2# shipxa#=0 : shipya#=0 : shipza#=0 gosub moveufo for f=75 to 80 : show object f : next f ufo=1 endif else if ufo = 1 if shipy# > shiph3# shipy#=shipy#-(ufospeed*div#) shipya#=wrapvalue(shipya#+(div#*45.0)) gosub moveufo else shipy#=shiph3# alx#=shipx# : alz#=shipz# for f=1 to alc if aliens(f-1,0)=0 o=9+f exit endif next f position object o,alx#,0,alz# loop object o,670,720 show object o inc aliencount aliens(f-1,0)=1 position object 81,alx#,shiph#+50,alz# show object 81 ufo=2 ufot=timer() endif else if ufo = 2 if timer()-ufot < 2000 yrotate object 81,rnd(359) shipya#=wrapvalue(shipya#+(div#*45.0)) gosub moveufo else hide object 81 shipxx#=-500.0+rnd(1000.0) shipzz#=-500.0+rnd(1000.0) ufo=3 endif else if ufo = 3 if shipy# < shiph2# shipx#=shipx#+(shipxx#*div#) shipz#=shipz#+(shipzz#*div#) shipy#=shipy#+(ufospeed*div#) shipya#=wrapvalue(shipya#+(div#*45.0)) gosub moveufo else for f=75 to 80 : hide object f : next f ufo=0 endif endif endif endif endif rem move aliens if aliencount <> 0 for f=1 to alc if aliens(f-1,0) = 3 if timer()-aliens(f-1,1) > 3000 aliens(f-1,0)=0 hide object f+9 position object f+9,0,0,0 dec aliencount if alphaok = 0 fade object f+9,100 ghost object off f+9 else set alpha mapping on f+9,100 endif else if alphaok = 0 fade object f+9,(3000-(timer()-aliens(f-1,1)))/30 else set alpha mapping on f+9,(3000-(timer()-aliens(f-1,1)))/30 endif endif else if aliens(f-1,0) = 2 if timer()-aliens(f-1,1) > 3000 aliens(f-1,0)=3 aliens(f-1,1)=timer() if alphaok = 0 ghost object on f+9 endif endif else if aliens(f-1,0) = 1 alien=f+9 aspd#=0.3 point object alien,x#,object position y(alien),z# xe#=newxvalue(object position x(alien),object angle y(alien),s4#*aspd#) ze#=newzvalue(object position z(alien),object angle y(alien),s4#*aspd#) gosub objcollision he#=get ground height(1,xe#-xvm,ze#-zvm) position object alien,xe#,he#,ze# if xe# >= xvm2 or xe# < xvm or ze# >= zvm2 or ze# < zvm stop object alien aliens(f-1,0)=0 hide object alien position object alien,0,0,0 dec aliencount endif endif endif endif next f endif endif rem gun movement position object 1,x#,camera position y()+(0.2*sin(mv#)),z# set object to camera orientation 1 rem onscreen stuff if runmode = 0 set cursor 0,0 print "FPS: ";str$(screen fps()) print "Collisions: ";cc;" / ";cola;" / ";acola print "Aliens: ";aliencount print "Objects: ";ob1b;" + ";ob2b print mj if mode = 1 print "Scancode: ";str$(scancode()) print "Height (Q/Z)" print "FOG (F): ";fogstatus print "XT / ZT : ";xt;" / ";zt print "XV / ZV : ";xv;" / ";zv print "SELX / SELZ : ";selx;" / ";selz if selx > -1 if object in screen(95)=1 text object screen x(95),object screen y(95)-25,str$(m(selx+xv-1,selz+zv-1,1))+" EC/RV "+str$(m(selx+xv-1,selz+zv-1,0))+" TB" endif endif ts=0 for g=1 to 4 : for f=1 to 8 inc ts if ts=seltex f2=((f-1)*32)+200 : g2=(g-1)*32 : sprite 96,f2,g2,96 : exit endif next f : next g sprite 98,650+(xt/2),(300-zt)/2,98 endif endif if runmode=1 sprite 98,650+(xt/2),(300-zt)/2,98 endif sync if keystate(1)=1 then exit loop rem EXIT GAME stop music 1 : delete music 1 delete light 1 delete matrix 1 gosub fogoff for f=1 to 10 if sound exist(f)=1 if sound playing(f)=1 stop sound f endif delete sound f endif next f for f=1 to 200 if sprite exist(f)=1 then delete sprite f next f for f=1 to 200 if object exist(f)=1 then delete object f next f for f=1 to 200 if image exist(f)=1 then delete image f next f undim ofs#(0) undim ofs2#(0) undim aliens(0) undim m(0) undim bullets#(0) undim bullets(0) undim objs(0) ink rgb(0,0,0),rgb(0,0,0) cls paste image 999,400-(437/2),300-(143/2),1 sync goto mainmenu rem ******************************************************************************************************************************* rem find a new positon for alien to be beamed down to newalienpos: for g=1 to 10000 alx=rnd(xm-1)+1 : alz=rnd(zm-1)+1 alxt=alx+xv-1 alzt=alz+zv-1 if m(alxt-1,alzt-1,2)=1 alx#=xmid(alxt) : alz#=zmid(alzt) ald#=range2D(alx#,alz#,x#,z#) if ald# > 1000 and ald# < 3000 exit endif endif next g return rem move the ufo to new coordinates moveufo: position object 75,shipx#,shipy#,shipz# rotate object 75,shipxa#,shipya#,shipza# for f=76 to 80 position object f,shipx#,shipy#,shipz# if f > 77 then set object to object orientation f,75 next f move object up 76,15 move object down 77,15 move object 78,70 : move object down 78,12 turn object right 79,120 : move object 79,70 : move object down 79,12 turn object right 80,240 : move object 80,70 : move object down 80,12 return rem update the ammo counter in bottom right of screen updateammo: am1=(ammo/100) am2=(ammo-(am1*100))/10 am3=(ammo-(am1*100)-(am2*10)) sprite 10,705,523,am1+10 sprite 11,735,523,am2+10 sprite 12,765,523,am3+10 return rem update the counter at bottom left of screen of how many cubes left updatepower: pow1=(power/10) pow2=(power-(pow1*10)) sprite 14,10,523,pow1+10 sprite 15,40,523,pow2+10 return rem move any bullets and see if they hit an alien bulletmove: set object collision on 3 for b=1 to bulletmax if bullets(b-1) <> 0 for bul=1 to bulletloop position object 3,object position x(b+19),object position y(b+19),object position z(b+19) rotate object 3,bullets#(b-1,0),bullets#(b-1,1),bullets#(b-1,2) move object 3,div# * bulletspeed if timer()-bullets(b-1) > bulletlife or get ground height(1,object position x(3)-xvm,object position z(3)-zvm) > object position y(3) or object collision(3,0) > 0 hide object b+19 position object 3,0,0,0 position object b+19,0,0,0 bullets(b-1)=0 dec bullet exit else if aliencount > 0 hit=alienhit(alc,object position x(3),object position y(3),object position z(3)) if hit<>0 play sound 2 o=9+hit aliens(hit-1,0)=2 aliens(hit-1,1)=timer() stop object o play object o,200,250 hide object b+19 position object 3,0,0,0 position object b+19,0,0,0 bullets(b-1)=0 dec bullet exit endif endif endif if bullets(b-1) <> 0 position object b+19,object position x(3),object position y(3),object position z(3) set object to camera orientation b+19 endif next bul endif next b set object collision off 3 return rem player keyboard operations move: if upkey() x#=newxvalue(x#,ya#,s4#) : z#=newzvalue(z#,ya#,s4#) : mv#=wrapvalue(mv#+(450.0*div#)) : mv1=10 : mv1#=s4#/4.0 else if mv1 <> 0 dec mv1 : mv1#=curvevalue(0,mv1#,10) : x#=newxvalue(x#,ya#,mv1#) : z#=newzvalue(z#,ya#,mv1#) endif endif if downkey() x#=newxvalue(x#,ya#,-s4#) : z#=newzvalue(z#,ya#,-s4#) : mv#=wrapvalue(mv#-(450.0*div#)) : mv2=10 : mv2#=s4#/4.0 else if mv2 <> 0 dec mv2 : mv2#=curvevalue(0,mv2#,10) : x#=newxvalue(x#,ya#,-mv2#) : z#=newzvalue(z#,ya#,-mv2#) endif endif if leftkey() x#=newxvalue(x#,wrapvalue(ya#-90.0),s4#) : z#=newzvalue(z#,wrapvalue(ya#-90.0),s4#) : mv3=10 : mv3#=s4#/4.0 else if mv3 <> 0 dec mv3 : mv3#=curvevalue(0,mv3#,10) : x#=newxvalue(x#,wrapvalue(ya#-90.0),mv3#) : z#=newzvalue(z#,wrapvalue(ya#-90.0),mv3#) endif endif if rightkey() x#=newxvalue(x#,wrapvalue(ya#+90.0),s4#) : z#=newzvalue(z#,wrapvalue(ya#+90.0),s4#) : mv4=10 : mv4#=s4#/4.0 else if mv4 <> 0 dec mv4 : mv4#=curvevalue(0,mv4#,10) : x#=newxvalue(x#,wrapvalue(ya#+90.0),mv4#) : z#=newzvalue(z#,wrapvalue(ya#+90.0),mv4#) endif endif rem F1 = toggle mode beween PLAY and EDIT if runmode = 0 if keystate(59)=1 and timer() > (lk+500) mode=1-mode lk=timer() if mode=0 hide sprite 95 : hide sprite 96 : hide sprite 97 : hide sprite 98 hide mouse if selx > -1 for f=95 to 98 : hide object f : next f selx=-1 : selz=-1 endif show object 1 s3#=s1# else show mouse s3#=s2# hide object 1 show sprite 95 : show sprite 96 : show sprite 97 : show sprite 98 endif endif endif if mode=0 if mouseclick()=1 if bullet < bulletmax and ammo <> 0 if timer()-lastbullet > bulletwait inc bullet dec ammo for f=1 to bulletmax if bullets(f-1) = 0 b=f : exit endif next f o=19+b bulletx#=object position x(1) bullety#=object position y(1) bulletz#=object position z(1) position object o,bulletx#,bullety#,bulletz# set object to object orientation o,1 move object right o,4.7 move object down o,6.5 move object o,10 show object o bullets(b-1)=timer() bullets#(b-1,0)=object angle x(20) bullets#(b-1,1)=object angle y(20) bullets#(b-1,2)=object angle z(20) play sound 1 lastbullet=timer() gosub updateammo endif endif endif endif if mode=1 rem Q = Move Up if keystate(16)=1 then inc y#,5 rem Z = Move Down if keystate(44)=1 then dec y#,5 rem D = move selected texture cursor Right if keystate(32)=1 and timer() > (lk+200) if seltex mod 8 <> 0 inc seltex lk=timer() endif endif rem A = move selected texture cursor Left if keystate(30)=1 and timer() > (lk+200) if seltex<>1 and seltex<>9 and seltex<>17 and seltex<>25 dec seltex lk=timer() endif endif rem W = move selected texture cursor Up if keystate(17)=1 and timer() > (lk+200) if seltex > 8 dec seltex,8 lk=timer() endif endif rem X = move selected texture cursor Down if keystate(45)=1 and timer() > (lk+200) if seltex < 25 inc seltex,8 lk=timer() endif endif rem CLICK MOUSE = select a matrix tile if mouseclick()=1 and timer() > (lk+200) gosub mousetile if ttx > -1 if selx = -1 for f=95 to 98 : show object f : color object f,rgb(255,255,255) : next f color object 94+selc,rgb(255,0,0) endif selx=ttx : selz=ttz gosub selectspheres endif lk=timer() endif rem 0 (zero) = save edited matrix - WARNING = overwrites level! if inkey$()="0" hide mouse gosub savearray show mouse endif if selx > -1 rem S = select texture if keystate(31)=1 and timer() > (lk+100) if m(selx+xv-1,selz+zv-1,2) <> seltex m(selx+xv-1,selz+zv-1,2)=seltex set matrix tile 1,selx,selz,seltex update matrix 1 endif lk=timer() endif rem N = raise surrounding heights to current height (highlighted with red blob) if inkey$()="n" and timer() > (lk+500) h=m(selx+xv-1,selz+zv-1,1) r=1 s=30 for xx=selx-r to selx+r for zz=selz-r to selz+r if xx>0 and zz>0 set matrix height 1,xx,zz,h m(xx+xv-1,zz+zv-1,1)=h endif next zz next xx update matrix 1 : gosub selectspheres lk=timer() endif rem E = height +1 if keystate(18)=1 and timer() > (lk+100) h=m(selx+xv-1,selz+zv-1,1) : inc h : m(selx+xv-1,selz+zv-1,1)=h set matrix height 1,selx,selz,h update matrix 1 : gosub selectspheres lk=timer() endif rem C = height -1 if keystate(46)=1 and timer() > (lk+100) h=m(selx+xv-1,selz+zv-1,1) : dec h : m(selx+xv-1,selz+zv-1,1)=h set matrix height 1,selx,selz,h update matrix 1 : gosub selectspheres lk=timer() endif rem R = height +10 if keystate(19)=1 and timer() > (lk+100) h=m(selx+xv-1,selz+zv-1,1) : inc h,10 : m(selx+xv-1,selz+zv-1,1)=h set matrix height 1,selx,selz,h update matrix 1 : gosub selectspheres lk=timer() endif rem V = height -10 if keystate(47)=1 and timer() > (lk+100) h=m(selx+xv-1,selz+zv-1,1) : dec h,10 : m(selx+xv-1,selz+zv-1,1)=h set matrix height 1,selx,selz,h update matrix 1 : gosub selectspheres lk=timer() endif rem T = normal lighter if keystate(20)=1 and timer() > (lk+100) h=m(selx+xv-1,selz+zv-1,0) if h > 0 dec h : m(selx+xv-1,selz+zv-1,0)=h n#=(10-h)/10.0 set matrix normal 1,selx,selz,n#,n#,n# update matrix 1 endif lk=timer() endif rem B = normal darker if keystate(48)=1 and timer() > (lk+100) h=m(selx+xv-1,selz+zv-1,0) if h < 10 inc h : m(selx+xv-1,selz+zv-1,0)=h n#=(10-h)/10.0 set matrix normal 1,selx,selz,n#,n#,n# update matrix 1 endif lk=timer() endif rem I = move selection up if keystate(23)=1 and timer() > (lk+100) inc selz : gosub selectspheres : lk=timer() endif rem M = move selection down if keystate(50)=1 and timer() > (lk+100) dec selz : gosub selectspheres : lk=timer() endif rem J = move selection left if keystate(36)=1 and timer() > (lk+100) dec selx : gosub selectspheres : lk=timer() endif rem L = move selection right if keystate(38)=1 and timer() > (lk+100) inc selx : gosub selectspheres : lk=timer() endif endif endif return rem update matrix editor selection spheres selectspheres: position object 95,xbl(xv+selx),m(selx+xv-1,selz+zv-1,1),zbl(zv+selz) position object 96,xbl(xv+selx+1),m(selx+xv,selz+zv-1,1),zbl(zv+selz) position object 97,xbl(xv+selx),m(selx+xv-1,selz+zv,1),zbl(zv+selz+1) position object 98,xbl(xv+selx+1),m(selx+xv,selz+zv,1),zbl(zv+selz+1) return rem update whole matrix from player position (usually at start but rem could be used for teleporting around level) moveplayer: xv=xmat(xp) : zv=zmat(zp) xvm=xbl(xv) : zvm=zbl(zv) : xvm2=xvm+(xs*xm) : zvm2=zvm+(zs*zm) for f=0 to xm for g=0 to zm n#=(10-m(xv+f-1,zv+g-1,0))/10.0 set matrix height 1,f,g,m(xv+f-1,zv+g-1,1) set matrix normal 1,f,g,n#,n#,n# if f < xm and g < zm set matrix tile 1,f,g,m(xv+f-1,zv+g-1,2) endif next g next f update matrix 1 position matrix 1,xvm,0,zvm return rem detect which matrix tile mouse is hovering over mousetile: ttx=-1 : tty=-1 : t=0 for f=0 to 5000 step 100 pick screen mousex(),mousey(),f xx#=get pick vector x()+camera position x() : yy#=get pick vector y()+camera position y() : zz#=get pick vector z()+camera position z() if xx# > matrix position x(1) and xx# < ((xs*xm) + matrix position x(1)) and zz# > matrix position z(1) and zz# < ((zs*zm) + matrix position z(1)) hh#=get ground height(1,xx#-matrix position x(1),zz#-matrix position z(1)) : vv#=yy#-hh#-matrix position y(1) : if vv# < 0 then t=1 : exit endif next f if t=1 t=0 for g=f-100 to f step 10 pick screen mousex(),mousey(),g xx#=get pick vector x()+camera position x() : yy#=get pick vector y()+camera position y() : zz#=get pick vector z()+camera position z() if xx# > matrix position x(1) and xx# < ((xs*xm) + matrix position x(1)) and zz# > matrix position z(1) and zz# < ((zs*zm) + matrix position z(1)) hh#=get ground height(1,xx#-matrix position x(1),zz#-matrix position z(1)) : vv#=yy#-hh#-matrix position y(1) : if vv# < 0 then t=1 : exit endif next g if t=1 t=0 for h=g to g-10 step -1 pick screen mousex(),mousey(),h xx#=get pick vector x()+camera position x() : yy#=get pick vector y()+camera position y() : zz#=get pick vector z()+camera position z() if xx# > matrix position x(1) and xx# < ((xs*xm) + matrix position x(1)) and zz# > matrix position z(1) and zz# < ((zs*zm) + matrix position z(1)) hh#=get ground height(1,xx#-matrix position x(1),zz#-matrix position z(1)) : vv#=yy#-hh#-matrix position y(1) : if vv# >= 0 then t=1 : exit endif next h if t=1 ttx=int((xx#-matrix position x(1))/((xs*xm)/xm)) ttz=int((zz#-matrix position z(1))/((zs*zm)/zm)) endif endif endif rem update camera view cameraview: if mode=0 h#=get ground height(1,x#-xvm,z#-zvm) position camera x#,h#+ch+(2.0*sin(mv#)),z# else position camera x#,y#,z# endif ya#=wrapvalue(ya#+(mousemovex()/midx#)) : xa#=wrapvalue(xa#+(mousemovey()/midx#)) if xa# > 180 and xa# < (360.0-mangu#) then xa#=(360.0-mangu#) if xa# > mangd# and xa# < 180 then xa#=mangd# rotate camera xa#,ya#,0 return rem CPU independent time limiter timerstuff: t2=timer() : inc t3 if t2-t1 >= t9 div#=((t2-t1)/1000.0)/t3 : t1=t2 : t3=0 : t4=1 else if t4=0 then div#=((t2-t1)/1000.0)/t3 endif return rem handle player collision with matrix and objects collision: fx#=0 : fz#=0 : hlow#=99999 : hhigh#=-99999 : cc=1 : mj=0 position object 30,x#,get ground height(1,x#-xvm,z#-zvm),z# if object collision(30,0) > 0 : cola=1 : else : cola=0 : endif position object 30,-2000,0,-2000 for r=0 to (sp-1) ex#=x#+ofs#(r,0) : ez#=z#+ofs#(r,1) eh#=get ground height(1,ex#-xvm,ez#-zvm) if diag=1 then position object 40+r,ex#,eh#,ez# if cola=1 position object 31,ex#,eh#,ez# : inc cc mjc=object collision (31,0) if mjc > 0 if mj=0 mjx=mjc-149 if mjx >=1 and mjx <= cubes if objs(mjx)=2 then mj=mjx endif endif if eh# < 0 then eh#=0 fs#=0 : fe#=r# for o=0 to 5 f#=fs#+((fe#-fs#)/2.0) zx#=newxvalue(x#,r*sp2#,(r#-f#)) : zz#=newzvalue(z#,r*sp2#,(r#-f#)) position object 31,zx#,get ground height(1,zx#-xvm,zz#-zvm),zz# inc cc : if object collision (31,0) = 0 : fe#=f# : else : fs#=f# : endif next o eh#=eh#+((fs#+((fe#-fs#)/2.0))*objcol#) qex#=newxvalue(x#,r*sp2#,r#-f#) : qez#=newzvalue(z#,r*sp2#,r#-f#) if diag=1 then position object 40+r,qex#,get ground height(1,qex#-xvm,qez#-zvm),qez# else if eh# < 0 then eh#=(-eh#*objcol#/3.0) endif else if eh# < 0 then eh#=(-eh#*objcol#/3.0) endif if diag=1 then position object 40+r+spmax,ex#,eh#,ez# if eh# > hhigh# then hhigh#=eh# if eh# < hlow# then hlow#=eh# force#=eh#/frc# : fx#=fx#+((ex#-x#)*force#) : fz#=fz#+((ez#-z#)*force#) next r nx#=x#-(fx#/(sp-1)) : nz#=z#-(fz#/(sp-1)) : if abs(hhigh#-hlow#) >= slide# then x#=nx# : z#=nz# : mv1=0 : mv2=0 : mv3=0 : mv4=0 position object 31,-4000,0,-4000 return rem handle alien collision with matrix and objects objcollision: fx#=0 : fz#=0 : hlow#=99999 : hhigh#=-99999 position object 30,xe#,get ground height(1,xe#-xvm,ze#-zvm),ze# : inc cc if object collision(30,0) > 0 : acola=1 : else : acola=0 : endif position object 30,-2000,0,-2000 for r=0 to (sp2-1) ex#=xe#+ofs2#(r,0) : ez#=ze#+ofs2#(r,1) eh#=get ground height(1,ex#-xvm,ez#-zvm) if acola=1 position object 31,ex#,eh#,ez# : inc cc if object collision (31,0) > 0 if eh# < 0 then eh#=0 fs#=0 : fe#=r2# for o=0 to 3 f#=fs#+((fe#-fs#)/2.0) zx#=newxvalue(xe#,r*sp3#,(r2#-f#)) : zz#=newzvalue(ze#,r*sp3#,(r2#-f#)) position object 31,zx#,get ground height(1,zx#-xvm,zz#-zvm),zz# inc cc : if object collision (31,0) = 0 : fe#=f# : else : fs#=f# : endif next o eh#=eh#+((fs#+((fe#-fs#)/2.0))*objcol#/1.33) qex#=newxvalue(xe#,r*sp3#,r2#-f#) : qez#=newzvalue(ze#,r*sp3#,r2#-f#) else d#=aliendist(alien,alc,ex#,ez#) if d# < r2# eh#=eh#+(objcol#*3.0) else if eh# < 0 eh#=(-eh#*objcol#/1.0) endif endif endif else if eh# < 0 eh#=(-eh#*objcol#/1.0) else d#=aliendist(alien,alc,ex#,ez#) if d# < r2# eh#=eh#+(objcol#*3.0) endif endif endif if eh# > hhigh# then hhigh#=eh# if eh# < hlow# then hlow#=eh# force#=eh#/frc# : fx#=fx#+((ex#-xe#)*force#) : fz#=fz#+((ez#-ze#)*force#) next r nx#=xe#-(fx#/(sp2-1)) : nz#=ze#-(fz#/(sp2-1)) : if abs(hhigh#-hlow#) >= (slide#/1.2) then xe#=nx# : ze#=nz# position object 31,-4000,0,-4000 return rem how far from selected alien to other aliens or player function aliendist(a,c,x#,z#) dist#=999 for f=1 to c if aliens(f-1,0) > 0 o=9+f if o <> a d#=range2d(x#,z#,object position x(o),object position z(o)) if d# < dist# then dist# = d# endif endif next f d#=range2d(x#,z#,camera position x(),camera position z()) if d# < dist# then dist# = d# endfunction dist# rem has bullet hit an alien function alienhit(c,x#,y#,z#) hit=0 for f=1 to c if aliens(f-1,0) = 1 o=9+f d#=range3d(x#,y#,z#,object position x(o),object position y(o),object position z(o)) if d# < 80 then hit=f : exit endif next f endfunction hit rem move sky with player sky: position object 90,camera position x(),poff,camera position z()+po position object 91,camera position x()+po,poff,camera position z() position object 92,camera position x(),poff,camera position z()-po position object 93,camera position x()-po,poff,camera position z() position object 94,camera position x(),po+poff,camera position z() return rem update matrix as player moves matmove: xt=int(x#/xs)+1 : zt=int(z#/zs)+1 : xvn=xmat(xt) : zvn=zmat(zt) if (xvn <> xv) or (zvn <> zv) xvm=xbl(xvn) : zvm=zbl(zvn) position matrix 1,xvm,0,zvm xvm2=xvm+(xs*xm) : zvm2=zvm+(zs*zm) if zvn > zv inc zv : shift matrix up 1 for f=0 to xm n#=(10-m(xv+f-1,zv+zm-1,0))/10.0 set matrix normal 1,f,zm,n#,n#,n# set matrix height 1,f,zm,m(xv+f-1,zv+zm-1,1) if f < xm : set matrix tile 1,f,zm-1,m(xv+f-1,zv+zm-2,2) : endif next f if selx > -1 dec selz if selz < 0 for f=95 to 98 : hide object f : next f selx=-1 : selz=-1 endif endif else if zvn < zv dec zv : shift matrix down 1 for f=0 to xm n#=(10-m(xv+f-1,zv-1,0))/10.0 set matrix normal 1,f,0,n#,n#,n# set matrix height 1,f,0,m(xv+f-1,zv-1,1) if f < xm : set matrix tile 1,f,0,m(xv+f-1,zv-1,2) : endif next f if selx > -1 inc selz if selz >= zm for f=95 to 98 : hide object f : next f selx=-1 : selz=-1 endif endif endif endif if xvn > xv inc xv : shift matrix left 1 for f=0 to zm n#=(10-m(xv+xm-1,zv+f-1,0))/10.0 set matrix normal 1,xm,f,n#,n#,n# set matrix height 1,xm,f,m(xv+xm-1,zv+f-1,1) if f < zm : set matrix tile 1,xm-1,f,m(xv+xm-2,zv+f-1,2) : endif next f if selx > -1 dec selx if selx < 0 for f=95 to 98 : hide object f : next f selx=-1 : selz=-1 endif endif else if xvn < xv dec xv : shift matrix right 1 for f=0 to zm n#=(10-m(xv-1,zv+f-1,0))/10.0 set matrix normal 1,0,f,n#,n#,n# set matrix height 1,0,f,m(xv-1,zv+f-1,1) if f < zm : set matrix tile 1,0,f,m(xv-1,zv+f-1,2) : endif next f if selx > -1 inc selx if selx >= xm for f=95 to 98 : hide object f : next f selx=-1 : selz=-1 endif endif endif endif update matrix 1 endif return rem hide objects out of camera view to speed up frame rate hidestuff: for f=1 to 2 inc j : if j > cubes then j=1 : ob1b=ob1 : ob2b=ob2 : ob1=0 : ob2=0 k=j+149 if objs(j) <> 3 ox#=object position x(k) : oz#=object position z(k) if ox# >= (xvm2+objoff) or ox# < (xvm-objoff) or oz# >= (zvm2+objoff) or oz# < (zvm-objoff) if object visible(k)=1 then hide object k : set object collision off k inc ob1 else if object visible(k)=0 show object k if objs(j)=0 or objs(j)=2 set object collision on k endif endif inc ob2 endif endif next f return rem during edit mode you can save level savearray: f$="level\map.txt" if file exist(f$) then delete file f$ open to write 1,f$ for f=0 to 300 for g=0 to 300 s1$=str$(m(f,g,0)) : if s1$="0" then s1$="" s2$=str$(m(f,g,1)) : if s2$="0" then s2$="" s3$=str$(m(f,g,2)) : if s3$="1" then s3$="" s$=s1$+","+s2$+","+s3$ : if s$=",," then s$="" write string 1,s$ next g next f close file 1 return rem turn fog on, if available fogon: if fog available()=1 then fog on : fog distance 4000 : fog color RGB(176,200,234) : fogstatus=1 return rem turn fog off fogoff: if fog available()=1 then fog off : fogstatus=0 return rem used as part of initial level creation to smooth mountains smooth: for multiple=1 to it for x=1 to 299 for z=1 to 299 total=0 for xx=-1 to 1 for zz=-1 to 1 if xx=0 and zz=0 inc total,0 else total=total+m(x+xx,z+zz,1) endif next xx next zz av=total/8 m(x,z,1)=av next z next x for x=0 to 300 m(x,0,1)=m(x,1,1) m(x,300,1)=m(x,299,1) m(0,x,1)=m(1,x,1) m(300,x,1)=m(299,x,1) next x next multiple return rem x coord of bottom-left of a particular tile function xbl(x) v=(x-1)*xs endfunction v rem z coord of bottom-left of a particular tile function zbl(z) v=(z-1)*zs endfunction v rem x coord of centre of a particular tile function xmid(x) v=((x-1)*xs)+(xs/2.0) endfunction v rem z coord of centre of a particular tile function zmid(z) v=((z-1)*zs)+(zs/2.0) endfunction v rem x matrix tile player is standing on function xmat(x) v=x-((xm-1)/2) if v < 1 then v=1 if v+xm-1 > xw then v=xw-xm+1 endfunction v rem z matrix tile player is standing on function zmat(z) v=z-((zm-1)/2) if v < 1 then v=1 if v+zm-1 > zw then v=zw-zm+1 endfunction v rem distance between 2 positions in 2D space function range2D(ax#,az#,bx#,bz#) set vector2 1,ax#-bx#,az#-bz# : result#=length vector2(1) endfunction result# rem distance between 2 positions in 3D space function range3D(ax#,ay#,az#,bx#,by#,bz#) set vector3 2,ax#-bx#,ay#-by#,az#-bz# : result#=length vector3(2) endfunction result#