TGC Codebase Backup



Matrix 03 by Anonymous Coder

28th Feb 2005 17:58
Summary

` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com Rem Project: MatrixMaster Rem Created: 5/6/04 4:25:5



Description

` This code was downloaded from The Game Creators
` It is reproduced here with full permission
` http://www.thegamecreators.com

Rem Project: MatrixMaster
Rem Created: 5/6/04 4:25:55 PM

Rem ***** Main Source File *****
rem this program written by Richard Sardini Jr
rem my e-mail:noramdia@adelphia.net
rem my phone:814-504-6033
rem check end of program for code snippet to load matrix into your dark basic programs
set display mode 800,600,16
create bitmap 1,50,50
ink RGB(128,128,0),0:for x=0 to 50:line x,0,x,50:next x
ink RGB(0,128,0),0:for x=0 to 200:dot rnd(50),rnd(50):next x
ink RGB(255,128,0),0:for x=0 to 50:dot rnd(50),rnd(50):next x
ink RGB(128,128,255),0:for x=0 to 90:dot rnd(50),rnd(50):next x
ink RGB(255,255,255),0:for x=0 to 20:dot rnd(50),rnd(50):next x
get image 1,0,0,50,50
delete bitmap 1
hint=1:hints=21:hintdelay=750
dim hint$(21):hintc1=50:ghost=-1
hint$(1)="Green marker=unselected coordinate Red marker=selected coordinate."
hint$(2)="Press ' w ' to toggle wireframe on and off."
hint$(3)="Press ' s ' to select all visible coordinate markers."
hint$(4)="Press ' t ' to toggle or invert all visible coordinate markers."
hint$(5)="Press ' u ' to un-select all visible coordinate markers that are currently selected."
hint$(6)="Press ' + ' or ' - ' to zoom in and out or turn the mouse wheel."
hint$(7)="Press arrow keys to pan your view or press and hold mouse botton 2 and move mouse."
hint$(8)="Press and hold both mouse buttons 1 and 2 and move mouse to rotate camera view."
hint$(9)="Left click and drag mouse-(top left to bottom right)-and red box will appear to select markers in box."
hint$(10)="Left click and drag mouse-(bottom right to top left)-and yellow box will appear to toggle or invert selected markers in box."
hint$(11)="Press ' h ' to hide all unselected markers-this is handy to isolate work areas."
hint$(12)="Press ' h ' again to show all hidden markers. Use this feature to hide and prevent selecting backround markers."
hint$(13)="Press and hold mouse wheel button 3 and move mouse up and down to lower or raise selected markers respectively."
hint$(14)="Or use keyboard less than ' < ' or greater than ' > ' to lower or raise selected markers respectively."
hint$(15)="Press ' n ' anytime to start a new matrix."
hint$(16)="Set the cross hairs on your destination point and then zoom in."
hint$(17)="Press ' z ' to zip to the next hint."
hint$(18)="Press ' L ' to level the matrix back to zero."
hint$(19)="Left click on marker to toggle coordinate marker selection."
hint$(20)="Press ' g ' to toggle ghost matrix on and off"
hint$(21)="Press ' escape ' key anytime to exit MATRIX MASTER"
startover:
set text size 16
set current bitmap 0
load=0
cls rgb(0,0,0):ink RGB(255,255,0),0
set cursor screen width()/2-20,0
print "MATRIX-MASTER Matrix Editor"
ink rgb(255,255,255),0

print
redomatrix:
input "Give your matrix a name and press enter>";matname$:sleep 200
redoinput:
print "Is this matrix name ";:ink rgb(0,255,0),0:print matname$;:ink rgb(255,255,255),0:print " correct?(y/n)>"
redoinkey:
g$=inkey$()
if g$<>"n" and g$<>"y" and g$<>"" then print "Please confirm your matrix name>":sleep 500:goto redoinput
if g$="n" then goto redomatrix
if g$="y" then goto redoxsize
goto redoinkey
redoxsize:
print "Matrix name accepted":sleep 1000:cls rgb(0,0,0):ink RGB(255,255,0),0
set cursor screen width()/2-20,0
print "MATRIX-MASTER Matrix Editor"
ink rgb(255,255,255),0
print
input "Input matrix size X and press enter>";matsizex
if matsizex<1 or matsizex>10000 then print "Bad input-try again>":sleep 500:goto redoxsize
matsizex=int(matsizex)
redozsize:
input "Input matrix size Z and press enter>";matsizez
if matsizez<1 or matsizez>10000 then print "Bad input-try again>":sleep 500:goto redozsize
matsizez=int(matsizez)

redoxseg:
input "Input matrix segment X and press enter>";matsegx
if matsegx<1 or matsegx>matsizex/2 then print "Bad input-try again>":sleep 500:goto redoxseg
matsegx=int(matsegx)
redozseg:
input "Input matrix segment Z and press enter>";matsegz
if matsegz<1 or matsegz>matsizez/2 then print "Bad input-try again>":sleep 500:goto redozseg
matsegz=int(matsegz)

print "Matrix parameters accepted"

print "Working...";
sleep 500
backdrop on
dim height((matsegx+1)*(matsegz+1))
dim xpos((matsegx+1)*(matsegz+1)):dim zpos((matsegz+1)*(matsegx+1))
loaded:

if matsizex>500 and matsizez>500 then size=6 else size=2
if matsizex>2000 and matsizez>2000 then size=10
if matsizex>5000 and matsizez>5000 then size=30

dim objstat((matsegx+1)*(matsegz+1))
matsegx1=matsizex/matsegx:matsegz1=matsizez/matsegz
banding=0:mx1=0:mx2=0:my1=0:my2=0:hide=-1

objnum=1
for z=0 to matsegz
for x=0 to matsegx
objstat(objnum)=-1
finalcount=objnum
inc objnum
next x
print ".";
next z

sync on
autocam off
make matrix 1,matsizex,matsizez,matsegx,matsegz
prepare matrix texture 1,1,1,1
update matrix 1
make object cube 50000,10:position object 50000,-10,0,-10:color object 50000,RGB(0,255,255)

if load=1
for x=1 to finalcount
read long 1,xpos(x)
read long 1,zpos(x)
read long 1,height(x)
next x
close file 1
endif
load=0

objnum=1
for z=0 to matsegz
for x=0 to matsegx
make object sphere objnum,size:color object objnum,rgb(0,255,0)
position object objnum,x*matsegx1,height(objnum),z*matsegz1
set matrix height 1,x,z,height(objnum)
if load=1 then goto skipassign
xpos(objnum)=x:zpos(objnum)=z
skipassign:
inc objnum
next x
next z
update matrix 1

set camera range 1,100000
position camera 0,200,0
point camera 0,0,200

mousexold#=mousex():mouseyold#=mousey()

mainloop:
do

dec hintdelay
if hintdelay<0 then hintdelay=850:inc hint
if hint>hints then hint=1
if inkey$()="z"
inc hint
if hint>hints then hint=1
hintdelay=1200
sleep 200
endif

if inkey$()="n"
sync off:backdrop off:set matrix wireframe on 1
set cursor 0,0:cls rgb(0,0,0):ink RGB(255,255,255),0
print "Confirm! Do you want to start a new matrix?(y/n)"
print "You may want to answer no and save this matrix first lest it be lost."
sleep 500
getagain5:
g$=inkey$()
if g$<>"y" and g$<>"n" then goto getagain5
if g$="y"
for x=1 to finalcount:delete object x:next x:delete object 50000
delete matrix 1
undim xpos(finalcount):undim zpos(finalcount)
undim height(finalcount):undim objstat(finalcount)
sleep 200
goto startover
endif
if g$="n"
sync on:backdrop on
endif
sleep 500
set matrix wireframe off 1
endif

if inkey$()="g"
ghost=ghost*-1
if ghost=1
ghost matrix on 1
endif
if ghost=-1
ghost matrix off 1
endif
sleep 200
endif



if inkey$()="l"
sync off:backdrop off
cls rgb(0,0,0):ink rgb(255,255,255),0
print "Are you sure you want to level your matrix back to zero?(y/n)"
sleep 200
getagain6:
g$=inkey$()
if g$<>"y" and g$<>"n" then goto getagain6
if g$="y"
for x=1 to finalcount
height(x)=0
set matrix height 1,xpos(x),zpos(x),height(x)
position object x,xpos(x)*matsegx1,height(x),zpos(x)*matsegz1
objstat(x)=-1:color object x,rgb(0,255,0)
next x
update matrix 1
endif
sync on:backdrop on
endif

if inkey$()="1" then goto savematrix
if inkey$()="2" then goto loadmatrix

base=get ground height(1,0,0):position object 50000,-10,base,-10
mousexnew#=mousexold#-mousex():mouseynew#=mouseyold#-mousey()

if upkey()=1 or mouseclick()=2 and mouseynew#>0
pitch camera down 2
endif

if downkey()=1 or mouseclick()=2 and mouseynew#<0
pitch camera up 2
endif

if leftkey()=1 or mouseclick()=2 and mousexnew#>0
turn camera left 2
endif

if rightkey()=1 or mouseclick()=2 and mousexnew#<0
turn camera right 2
endif
if mousezold<mousez() or inkey$()="+"
move camera 20*size
endif
if mousezold>mousez() or inkey$()="-"
move camera -20*size
endif

if banding=1 then goto skiptilt
if mouseclick()=3 and mousexnew#>0
roll camera left 2
endif
if mouseclick()=3 and mousexnew#<0
roll camera right 2
endif

skiptilt:

if banding=1 then goto skipfirst
if mouseclick()=1
mx1=mousex():my1=mousey():banding=1
endif

skipfirst:

if banding=1 then mx2=mousex():my2=mousey()
if mx1>mx2 and my1<my2 or mx1<mx2 and my1>my2 then banding=0

if banding=1 and mouseclick()=0
if mx1<mx2
for x=1 to finalcount
ox=object screen x(x):oy=object screen y(x)
if object visible(x)=1
if ox>mx1 and ox<mx2 and oy>my1 and oy<my2
objstat(x)=1:color object x,rgb(255,0,0)
endif
endif
next x
endif
if mx1>mx2
for x=1 to finalcount
ox=object screen x(x):oy=object screen y(x)
if object visible(x)=1
if ox<mx1 and ox>mx2 and oy<my1 and oy>my2
objstat(x)=objstat(x)*-1
if objstat(x)=1 then color object x,rgb(255,0,0)
if objstat(x)=-1 then color object x,rgb(0,255,0)
endif
endif
next x
endif
banding=0
endif

if banding=1 and mx1<>mx2 and my1<>my2 then goto skipselect

if mousexnew#=0 and mouseynew#=0
if mouseclick()=1 and mx1=mx2 and banding=1 and mx1=mx2 and my1=my2
for x=1 to finalcount
if object in screen(x)=1
if object visible(x)=1
sx=object screen x(x):sy=object screen y(x)
if mousex()>sx-5 and mousex()<sx+5 and mousey()>sy-5 and mousey()<sy+5
objstat(x)=objstat(x)*-1
if objstat(x)=1 then color object x,rgb(255,0,0)
if objstat(x)=-1 then color object x,rgb(0,255,0)
sleep 200
x=finalcount:banding=0
endif
endif
endif
next x
sleep 200
endif
endif
skipselect:

if mouseclick()=4 and mouseynew#>0 or inkey$()="."
for x=1 to finalcount
if objstat(x)=1
gh#=get matrix height(1,xpos(x),zpos(x))
inc height(x),(size/2+1)
set matrix height 1,xpos(x),zpos(x),height(x)
position object x,xpos(x)*matsegx1,height(x),zpos(x)*matsegz1
endif
next x
update matrix 1
endif

if mouseclick()=4 and mouseynew#<0 or inkey$()=","
for x=1 to finalcount
if objstat(x)=1
dec height(x),(size/2+1)
set matrix height 1,xpos(x),zpos(x),height(x)
position object x,xpos(x)*matsegx1,height(x),zpos(x)*matsegz1
endif
next x
update matrix 1
endif
if inkey$()="u"
for x=1 to finalcount
if objstat(x)=1
objstat(x)=-1
color object x,rgb(0,255,0)
endif
next x
endif

if inkey$()="s"
for x=1 to finalcount
if object visible(x)=1 then objstat(x)=1:color object x,rgb(255,0,0)
next x
endif

if inkey$()="t"
for x=1 to finalcount
if object visible(x)=1
objstat(x)=objstat(x)*-1
if objstat(x)=1 then color object x,rgb(255,0,0)
if objstat(x)=-1 then color object x,rgb(0,255,0)
endif
next x
sleep 200
endif
if inkey$()="h"
hide=hide*-1
if hide=1
for x=1 to finalcount
if objstat(x)=-1
hide object x
endif
next x
endif
if hide=-1
for x=1 to finalcount
if objstat(x)=-1
if object visible(x)=0 then show object x
endif
next x
endif
sleep 200
endif

mousexold#=mousex():mouseyold#=mousey():mousezold=mousez()

if inkey$()="w"
if matrix wireframe state(1)=1 then set matrix wireframe off 1 else set matrix wireframe on 1
sleep 200
endif
ink RGB(0,255,255),0
set cursor screen width()/2-120,0
print "MATRIX MASTER - by Richard Sardini"
ink RGB(0,128,255),0
set cursor screen width()/2-80,40
print "You are editing matix> ";:ink rgb(255,255,0),0:print matname$:ink rgb(255,255,255),0

xl=screen width()/2:yl=screen height()/2
ink RGB(192,192,192),0
line xl,200,xl,screen height()-200
line 250,yl,screen width()-250,yl
ink rgb(255,255,255),0
if banding=1
if mx1<mx2 then ink RGB(255,0,128),0 else ink RGB(255,255,0),0
line mx1,my1,mx2,my1:line mx1,my2,mx1,my1
line mx2,my1,mx2,my2:line mx1,my2,mx2,my2
ink rgb(255,255,255),0
endif
cnt1=0
for x=1 to finalcount
if objstat(x)=1
print "X->";xpos(x);" Z->";zpos(x);" Height->";height(x)
inc cnt1
if cnt1>15 then x=finalcount
endif
next x
inc hintc1,8:if hintc1>255 then hintc1=100
hintcolor=rgb(0,hintc1,0)

ink hintcolor,0
text int(screen width()/30),screen height()-100,hint$(hint)
set cursor screen width()/5,screen height()-60
ink rgb(255,255,255),0
print "Press: 1-Save, 2-Load, Z-Zip to next hint"

sync
loop

savematrix:
backdrop off
sync off:cls rgb(0,0,0)
ink rgb(255,255,255),0
savematrix1:
if file exist(matname$)=1
sleep 500
print "File already exist - Would you like to overwrite this file or rename your matrix?"

print "Press 2 to overwrite or 3 to rename this matrix"
getagain:
g$=inkey$()
if g$<>"2" and g$<>"3" then sleep 200:goto getagain
if g$="3"
sleep 200
print "What is the new file name?";:input matname$
sleep 200
goto savematrix1
endif
if g$="2" then delete file matname$:sleep 200
endif
open to write 1,matname$
write long 1,matsizex:write long 1,matsizez:write long 1,matsegx:write long 1,matsegz
write long 1,finalcount
for x=1 to finalcount
write long 1,xpos(x)
write long 1,zpos(x)
write long 1,height(x)
next x
close file 1
print "File saved: Press any key to return to editor"
sleep 500
wait key
sleep 200
sync on
backdrop on
goto mainloop



loadmatrix:
backdrop off
sync off:cls rgb(0,0,0)
ink rgb(255,255,255),0

print "Current matrix will be lost. Proceed(Y/N)?"
getinput:
g$=inkey$()
if g$="n" or g$="N" then sync on:backdrop on:goto mainloop
if g$<>"y" then goto getinput
delete matrix 1
for x=1 to finalcount
delete object x
next x
delete object 50000
undim xpos(finalcount):undim zpos(finalcount)
undim height(finalcount):undim objstat(finalcount)
redomatrixname:
input "File name to load?";matname$
if matname$="exit" then goto startover
if file exist(matname$)=0
print "File does not exist: Try again or type exit"
sleep 500
goto redomatrixname
endif
if file exist(matname$)=1
open to read 1,matname$
read long 1,matsizex:read long 1,matsizez
read long 1,matsegx:read long 1,matsegz
read long 1,finalcount
dim height(finalcount):dim xpos(finalcount):dim zpos(finalcount)
load=1
endif
sync on
backdrop on

goto loaded


remstart

This is the code snippet you will need to re-load your matrix into your DB programs

open to read 1,<filenamehere>
read long 1,matsizex:read long 1,matsizez
read long 1,matsegx:read long 1,matsegz
read long 1,finalcount
dim height(finalcount):dim xpos(finalcount):dim zpos(finalcount)
for x=1 to finalcount
read long 1,xpos(x)
read long 1,zpos(x)
read long 1,height(x)
next x
close file 1
make matrix 1,matsizex,matsizez,matsegx,matsegz
for x=1 to finalcount
set matrix height 1,xpos(x),zpos(x),height(x)
next x
update matrix 1

endrem



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    ` This code was downloaded from The Game Creators
` It is reproduced here with full permission
` http://www.thegamecreators.com

Rem Project: MatrixMaster
Rem Created: 5/6/04 4:25:55 PM

Rem ***** Main Source File *****
rem this program written by Richard Sardini Jr
rem my e-mail:noramdia@adelphia.net
rem my phone:814-504-6033
rem check end of program for code snippet to load matrix into your dark basic programs
set display mode 800,600,16
create bitmap 1,50,50
ink RGB(128,128,0),0:for x=0 to 50:line x,0,x,50:next x
ink RGB(0,128,0),0:for x=0 to 200:dot rnd(50),rnd(50):next x
ink RGB(255,128,0),0:for x=0 to 50:dot rnd(50),rnd(50):next x
ink RGB(128,128,255),0:for x=0 to 90:dot rnd(50),rnd(50):next x
ink RGB(255,255,255),0:for x=0 to 20:dot rnd(50),rnd(50):next x
get image 1,0,0,50,50
delete bitmap 1
hint=1:hints=21:hintdelay=750
dim hint$(21):hintc1=50:ghost=-1
hint$(1)="Green marker=unselected coordinate   Red marker=selected coordinate."
hint$(2)="Press ' w ' to toggle wireframe on and off."
hint$(3)="Press ' s ' to select all visible coordinate markers."
hint$(4)="Press ' t ' to toggle or invert all visible coordinate markers."
hint$(5)="Press ' u ' to un-select all visible coordinate markers that are currently selected."
hint$(6)="Press ' + ' or ' - ' to zoom in and out or turn the mouse wheel."
hint$(7)="Press arrow keys to pan your view or press and hold mouse botton 2 and move mouse."
hint$(8)="Press and hold both mouse buttons 1 and 2 and move mouse to rotate camera view."
hint$(9)="Left click and drag mouse-(top left to bottom right)-and red box will appear to select markers in box."
hint$(10)="Left click and drag mouse-(bottom right to top left)-and yellow box will appear to toggle or invert selected markers in box."
hint$(11)="Press ' h ' to hide all unselected markers-this is handy to isolate work areas."
hint$(12)="Press ' h ' again to show all hidden markers. Use this feature to hide and prevent selecting backround markers."
hint$(13)="Press and hold mouse wheel button 3 and move mouse up and down to lower or raise selected markers respectively."
hint$(14)="Or use keyboard less than ' < ' or greater than ' > ' to lower or raise selected markers respectively."
hint$(15)="Press ' n ' anytime to start a new matrix."
hint$(16)="Set the cross hairs on your destination point and then zoom in."
hint$(17)="Press ' z ' to zip to the next hint."
hint$(18)="Press ' L ' to level the matrix back to zero."
hint$(19)="Left click on marker to toggle coordinate marker selection."
hint$(20)="Press ' g ' to toggle ghost matrix on and off"
hint$(21)="Press ' escape ' key anytime to exit MATRIX MASTER"
startover:
set text size 16
set current bitmap 0
load=0
cls rgb(0,0,0):ink RGB(255,255,0),0
set cursor screen width()/2-20,0
print "MATRIX-MASTER Matrix Editor"
ink rgb(255,255,255),0

print
redomatrix:
input "Give your matrix a name and press enter>";matname$:sleep 200
redoinput:
print "Is this matrix name ";:ink rgb(0,255,0),0:print matname$;:ink rgb(255,255,255),0:print " correct?(y/n)>"
redoinkey:
g$=inkey$()
if g$<>"n" and g$<>"y" and g$<>"" then print "Please confirm your matrix name>":sleep 500:goto redoinput
if g$="n" then goto redomatrix
if g$="y" then goto redoxsize
goto redoinkey
redoxsize:
print "Matrix name accepted":sleep 1000:cls rgb(0,0,0):ink RGB(255,255,0),0
set cursor screen width()/2-20,0
print "MATRIX-MASTER Matrix Editor"
ink rgb(255,255,255),0
print
input "Input matrix size X and press enter>";matsizex
if matsizex<1 or matsizex>10000 then print "Bad input-try again>":sleep 500:goto redoxsize
matsizex=int(matsizex)
redozsize:
input "Input matrix size Z and press enter>";matsizez
if matsizez<1 or matsizez>10000 then print "Bad input-try again>":sleep 500:goto redozsize
matsizez=int(matsizez)

redoxseg:
input "Input matrix segment X and press enter>";matsegx
if matsegx<1 or matsegx>matsizex/2 then print "Bad input-try again>":sleep 500:goto redoxseg
matsegx=int(matsegx)
redozseg:
input "Input matrix segment Z and press enter>";matsegz
if matsegz<1 or matsegz>matsizez/2 then print "Bad input-try again>":sleep 500:goto redozseg
matsegz=int(matsegz)

print "Matrix parameters accepted"

print "Working...";
sleep 500
backdrop on
dim height((matsegx+1)*(matsegz+1))
dim xpos((matsegx+1)*(matsegz+1)):dim zpos((matsegz+1)*(matsegx+1))
loaded:

if matsizex>500 and matsizez>500 then size=6 else size=2
if matsizex>2000 and matsizez>2000 then size=10
if matsizex>5000 and matsizez>5000 then size=30

dim objstat((matsegx+1)*(matsegz+1))
matsegx1=matsizex/matsegx:matsegz1=matsizez/matsegz
banding=0:mx1=0:mx2=0:my1=0:my2=0:hide=-1

objnum=1
for z=0 to matsegz
   for x=0 to matsegx
      objstat(objnum)=-1
      finalcount=objnum
      inc objnum
   next x
   print ".";
next z

sync on
autocam off
make matrix 1,matsizex,matsizez,matsegx,matsegz
prepare matrix texture 1,1,1,1
update matrix 1
make object cube 50000,10:position object 50000,-10,0,-10:color object 50000,RGB(0,255,255)

if load=1
   for x=1 to finalcount
      read long 1,xpos(x)
      read long 1,zpos(x)
      read long 1,height(x)
   next x
   close file 1
endif
load=0

objnum=1
for z=0 to matsegz
   for x=0 to matsegx
      make object sphere objnum,size:color object objnum,rgb(0,255,0)
      position object objnum,x*matsegx1,height(objnum),z*matsegz1
      set matrix height 1,x,z,height(objnum)
      if load=1 then goto skipassign
      xpos(objnum)=x:zpos(objnum)=z
      skipassign:
      inc objnum
   next x
next z
update matrix 1

set camera range 1,100000
position camera 0,200,0
point camera 0,0,200

mousexold#=mousex():mouseyold#=mousey()

mainloop:
do

dec hintdelay
if hintdelay<0 then hintdelay=850:inc hint
if hint>hints then hint=1
if inkey$()="z"
   inc hint
   if hint>hints then hint=1
   hintdelay=1200
   sleep 200
endif

if inkey$()="n"
   sync off:backdrop off:set matrix wireframe on 1
   set cursor 0,0:cls rgb(0,0,0):ink RGB(255,255,255),0
   print "Confirm! Do you want to start a new matrix?(y/n)"
   print "You may want to answer no and save this matrix first lest it be lost."
   sleep 500
   getagain5:
   g$=inkey$()
   if g$<>"y" and g$<>"n" then goto getagain5
   if g$="y"
      for x=1 to finalcount:delete object x:next x:delete object 50000
      delete matrix 1
      undim xpos(finalcount):undim zpos(finalcount)
      undim height(finalcount):undim objstat(finalcount)
      sleep 200
      goto startover
   endif
   if g$="n"
      sync on:backdrop on
   endif
   sleep 500
   set matrix wireframe off 1
endif

if inkey$()="g"
   ghost=ghost*-1
   if ghost=1
      ghost matrix on 1
   endif
   if ghost=-1
      ghost matrix off 1
   endif
   sleep 200
endif



if inkey$()="l"
   sync off:backdrop off
   cls rgb(0,0,0):ink rgb(255,255,255),0
   print "Are you sure you want to level your matrix back to zero?(y/n)"
   sleep 200
   getagain6:
   g$=inkey$()
   if g$<>"y" and g$<>"n" then goto getagain6
   if g$="y"
      for x=1 to finalcount
         height(x)=0
         set matrix height 1,xpos(x),zpos(x),height(x)
         position object x,xpos(x)*matsegx1,height(x),zpos(x)*matsegz1
         objstat(x)=-1:color object x,rgb(0,255,0)
      next x
      update matrix 1
   endif
   sync on:backdrop on
endif

if inkey$()="1" then goto savematrix
if inkey$()="2" then goto loadmatrix

base=get ground height(1,0,0):position object 50000,-10,base,-10
mousexnew#=mousexold#-mousex():mouseynew#=mouseyold#-mousey()

if upkey()=1 or mouseclick()=2 and mouseynew#>0
   pitch camera down 2
endif

if downkey()=1 or mouseclick()=2 and mouseynew#<0
   pitch camera up 2
endif

if leftkey()=1 or mouseclick()=2 and mousexnew#>0
   turn camera left 2
endif

if rightkey()=1 or mouseclick()=2 and mousexnew#<0
   turn camera right 2
endif
if mousezold<mousez() or inkey$()="+"
   move camera 20*size
endif
if mousezold>mousez() or inkey$()="-"
   move camera -20*size
endif

if banding=1 then goto skiptilt
if mouseclick()=3 and mousexnew#>0
   roll camera left 2
endif
if mouseclick()=3 and mousexnew#<0
   roll camera right 2
endif

skiptilt:

if banding=1 then goto skipfirst
if mouseclick()=1
   mx1=mousex():my1=mousey():banding=1
endif

skipfirst:

if banding=1 then mx2=mousex():my2=mousey()
if mx1>mx2 and my1<my2 or mx1<mx2 and my1>my2 then banding=0

if banding=1 and mouseclick()=0
   if mx1<mx2
      for x=1 to finalcount
         ox=object screen x(x):oy=object screen y(x)
         if object visible(x)=1
            if ox>mx1 and ox<mx2 and oy>my1 and oy<my2
               objstat(x)=1:color object x,rgb(255,0,0)
            endif
         endif
      next x
   endif
   if mx1>mx2
      for x=1 to finalcount
         ox=object screen x(x):oy=object screen y(x)
         if object visible(x)=1
            if ox<mx1 and ox>mx2 and oy<my1 and oy>my2
               objstat(x)=objstat(x)*-1
               if objstat(x)=1 then color object x,rgb(255,0,0)
               if objstat(x)=-1 then color object x,rgb(0,255,0)
            endif
         endif
      next x
   endif
   banding=0
endif

if banding=1 and mx1<>mx2 and my1<>my2 then goto skipselect

if mousexnew#=0 and mouseynew#=0
   if mouseclick()=1 and mx1=mx2 and banding=1 and mx1=mx2 and my1=my2
      for x=1 to finalcount
         if object in screen(x)=1
            if object visible(x)=1
               sx=object screen x(x):sy=object screen y(x)
               if mousex()>sx-5 and mousex()<sx+5 and mousey()>sy-5 and mousey()<sy+5
                  objstat(x)=objstat(x)*-1
                  if objstat(x)=1 then color object x,rgb(255,0,0)
                  if objstat(x)=-1 then color object x,rgb(0,255,0)
                  sleep 200
                  x=finalcount:banding=0
               endif
            endif
         endif
      next x
      sleep 200
   endif
endif
skipselect:

if mouseclick()=4 and mouseynew#>0 or inkey$()="."
   for x=1 to finalcount
      if objstat(x)=1
         gh#=get matrix height(1,xpos(x),zpos(x))
         inc height(x),(size/2+1)
         set matrix height 1,xpos(x),zpos(x),height(x)
         position object x,xpos(x)*matsegx1,height(x),zpos(x)*matsegz1
      endif
   next x
   update matrix 1
endif

if mouseclick()=4 and mouseynew#<0 or inkey$()=","
   for x=1 to finalcount
      if objstat(x)=1
         dec height(x),(size/2+1)
         set matrix height 1,xpos(x),zpos(x),height(x)
         position object x,xpos(x)*matsegx1,height(x),zpos(x)*matsegz1
      endif
   next x
   update matrix 1
endif
if inkey$()="u"
   for x=1 to finalcount
      if objstat(x)=1
         objstat(x)=-1
         color object x,rgb(0,255,0)
      endif
   next x
endif

if inkey$()="s"
   for x=1 to finalcount
      if object visible(x)=1 then objstat(x)=1:color object x,rgb(255,0,0)
   next x
endif

if inkey$()="t"
   for x=1 to finalcount
      if object visible(x)=1
         objstat(x)=objstat(x)*-1
         if objstat(x)=1 then color object x,rgb(255,0,0)
         if objstat(x)=-1 then color object x,rgb(0,255,0)
      endif
   next x
   sleep 200
endif
if inkey$()="h"
   hide=hide*-1
   if hide=1
      for x=1 to finalcount
         if objstat(x)=-1
            hide object x
         endif
      next x
   endif
   if hide=-1
      for x=1 to finalcount
         if objstat(x)=-1
            if object visible(x)=0 then show object x
         endif
      next x
   endif
   sleep 200
endif

mousexold#=mousex():mouseyold#=mousey():mousezold=mousez()

if inkey$()="w"
   if matrix wireframe state(1)=1 then set matrix wireframe off 1 else set matrix wireframe on 1
   sleep 200
endif
ink RGB(0,255,255),0
set cursor screen width()/2-120,0
print "MATRIX MASTER - by Richard Sardini"
ink RGB(0,128,255),0
set cursor screen width()/2-80,40
print "You are editing matix> ";:ink rgb(255,255,0),0:print matname$:ink rgb(255,255,255),0

xl=screen width()/2:yl=screen height()/2
ink RGB(192,192,192),0
line xl,200,xl,screen height()-200
line 250,yl,screen width()-250,yl
ink rgb(255,255,255),0
if banding=1
   if mx1<mx2 then ink RGB(255,0,128),0 else ink RGB(255,255,0),0
   line mx1,my1,mx2,my1:line mx1,my2,mx1,my1
   line mx2,my1,mx2,my2:line mx1,my2,mx2,my2
   ink rgb(255,255,255),0
endif
cnt1=0
for x=1 to finalcount
   if objstat(x)=1
      print "X->";xpos(x);"  Z->";zpos(x);"  Height->";height(x)
      inc cnt1
      if cnt1>15 then x=finalcount
   endif
next x
inc hintc1,8:if hintc1>255 then hintc1=100
hintcolor=rgb(0,hintc1,0)

ink hintcolor,0
text int(screen width()/30),screen height()-100,hint$(hint)
set cursor screen width()/5,screen height()-60
ink rgb(255,255,255),0
print "Press: 1-Save, 2-Load, Z-Zip to next hint"

sync
loop

savematrix:
backdrop off
sync off:cls rgb(0,0,0)
ink rgb(255,255,255),0
savematrix1:
if file exist(matname$)=1
   sleep 500
   print "File already exist - Would you like to overwrite this file or rename your matrix?"

   print "Press 2 to overwrite or 3 to rename this matrix"
   getagain:
   g$=inkey$()
   if g$<>"2" and g$<>"3" then sleep 200:goto getagain
   if g$="3"
      sleep 200
      print "What is the new file name?";:input matname$
      sleep 200
      goto savematrix1
   endif
   if g$="2" then delete file matname$:sleep 200
endif
open to write 1,matname$
write long 1,matsizex:write long 1,matsizez:write long 1,matsegx:write long 1,matsegz
write long 1,finalcount
for x=1 to finalcount
   write long 1,xpos(x)
   write long 1,zpos(x)
   write long 1,height(x)
next x
close file 1
print "File saved: Press any key to return to editor"
sleep 500
wait key
sleep 200
sync on
backdrop on
goto mainloop



loadmatrix:
backdrop off
sync off:cls rgb(0,0,0)
ink rgb(255,255,255),0

print "Current matrix will be lost.  Proceed(Y/N)?"
getinput:
g$=inkey$()
if g$="n" or g$="N" then sync on:backdrop on:goto mainloop
if g$<>"y" then goto getinput
delete matrix 1
for x=1 to finalcount
delete object x
next x
delete object 50000
undim xpos(finalcount):undim zpos(finalcount)
undim height(finalcount):undim objstat(finalcount)
redomatrixname:
input "File name to load?";matname$
if matname$="exit" then goto startover
if file exist(matname$)=0
   print "File does not exist: Try again or type exit"
   sleep 500
   goto redomatrixname
endif
if file exist(matname$)=1
   open to read 1,matname$
   read long 1,matsizex:read long 1,matsizez
   read long 1,matsegx:read long 1,matsegz
   read long 1,finalcount
   dim height(finalcount):dim xpos(finalcount):dim zpos(finalcount)
   load=1
endif
sync on
backdrop on

goto loaded


   remstart

   This is the code snippet you will need to re-load your matrix into your DB programs

open to read 1,<filenamehere>
read long 1,matsizex:read long 1,matsizez
read long 1,matsegx:read long 1,matsegz
read long 1,finalcount
dim height(finalcount):dim xpos(finalcount):dim zpos(finalcount)
for x=1 to finalcount
   read long 1,xpos(x)
   read long 1,zpos(x)
   read long 1,height(x)
next x
close file 1
make matrix 1,matsizex,matsizez,matsegx,matsegz
for x=1 to finalcount
   set matrix height 1,xpos(x),zpos(x),height(x)
next x
update matrix 1

endrem