Rem Project: Sinister_Matrix_Maker
Rem Created: 1/07/2008 9:10:33 AM
Rem Created by: sinisterstuf
 
Rem ***** Main Source File *****
 
SET DISPLAY MODE 1024,768,32
SYNC ON : SYNC RATE 120
SET WINDOW LAYOUT 0,1,1
SET WINDOW TITLE "sinister Matrix Maker"
SET TEXT FONT "Verdana"
SET TEXT SIZE 24
DISABLE ESCAPEKEY
 
name$=""
safe=0
width=50
length=50
xtiles=10
ztiles=10
maxheight=5
smoothing=3
 
GOTO main_menu
 
main_menu:
WAIT 100
DO
   CLS
   SETGREY(255)
   SET TEXT SIZE 42 : TEXT 300,145,"SINISTER"
   SET TEXT SIZE 32 : TEXT 300,185,"MATRIX EDITOR"
   SET TEXT SIZE 28
   `Darkens highlighted menu items
   MENUHOVER(200, 300, "Create New Matrix")
   MENUHOVER(200, 350, "Load Saved Matrix")
   MENUHOVER(200, 400, "Exit")
   `Determines the outcome of clicking in the menu
   IF MOUSECLICK()=1 AND MOUSEPOS(200, 315, 300, 325)=1 THEN GOTO new_matrix
   IF MOUSECLICK()=1 AND MOUSEPOS(200, 315, 350, 375)=1 THEN GOTO load_matrix
   IF MOUSECLICK()=1 AND MOUSEPOS(200, 315, 400, 425)=1 THEN END
   SYNC
LOOP
RETURN
 
new_matrix:
   WAIT 100
   BACKDROP OFF
   DO
      CLS
      SETGREY(255)
      SET TEXT SIZE 32 : TEXT 300,100,"CREATE NEW MATRIX"
      SET TEXT SIZE 28
      MENUHOVER(50,200,"Name: "+name$)
      MENUHOVER(50,250,"Width: "+str$(width))
      MENUHOVER(50,300,"Length: "+str$(length))
      MENUHOVER(50,350,"xTiles: "+str$(xtiles))
      MENUHOVER(50,400,"zTiles: "+str$(ztiles))
      MENUHOVER(50,450,"maxHeight: "+str$(maxheight))
      MENUHOVER(50,500,"smoothing: "+str$(smoothing))
      MENUHOVER(100,700,"DONE")
      IF MOUSECLICK()=1 AND MOUSEPOS(50,165,200,225)=1 THEN name$=INPUTBOX(135,200) : safe=1
      IF MOUSECLICK()=1 AND MOUSEPOS(50,165,250,275)=1 THEN width=int(val(INPUTBOX(135,250)))
      IF MOUSECLICK()=1 AND MOUSEPOS(50,165,300,325)=1 THEN length=int(val(INPUTBOX(148,300)))
      IF MOUSECLICK()=1 AND MOUSEPOS(50,165,350,375)=1 THEN xtiles=int(val(INPUTBOX(134,350)))
      IF MOUSECLICK()=1 AND MOUSEPOS(50,165,400,425)=1 THEN ztiles=int(val(INPUTBOX(132,400)))
      IF MOUSECLICK()=1 AND MOUSEPOS(50,165,450,475)=1 THEN maxheight=int(val(INPUTBOX(193,450)))
      IF MOUSECLICK()=1 AND MOUSEPOS(50,165,500,525)=1 THEN smoothing=int(val(INPUTBOX(189,500)))
      IF smoothing<1 THEN smoothing=1
      IF smoothing>9 THEN smoothing=9
      IF MOUSECLICK()=1 AND MOUSEPOS(100,215,700,735)=1 AND LEN(name$)>1 AND safe=1 THEN GOTO setup_matrix
      IF MOUSECLICK()=1 AND MOUSEPOS(100,215,700,735)=1 AND LEN(name$)<1 THEN safe=3
      IF safe=3 THEN MESSAGEBOX(15,300,15,45) : TEXT 16,16,"field is empty: [NAME]"
      IF LEN(name$)>20 THEN safe=2
      IF safe=2 THEN MESSAGEBOX(15,660,15,45) : TEXT 16,16,"filename exceeds maximum number of characters[20]"
      IF ESCAPEKEY()=1 THEN GOTO main_menu
      SYNC
   LOOP
RETURN
 
load_matrix:
WAIT 100
BACKDROP OFF
CLS : SETGREY(255) : SET TEXT SIZE 20
IF FILE EXIST("Sinister_Matrix_Maker.exe")=1 AND PATH EXIST("Saves")=1 THEN CD "Saves"
IF FILE EXIST("Sinister_Matrix_Maker.exe")=1 AND PATH EXIST("Saves")=0 THEN GOTO no_saves
PERFORM CHECKLIST FOR FILES
IF CHECKLIST QUANTITY()<=3 THEN GOTO no_saves
totlsavs=CHECKLIST QUANTITY()
DIM savelist$(totlsavs)
FOR count=1 TO totlsavs
   savelist$(count)=CHECKLIST STRING$(count)
NEXT count
PRINT "Choose your save file (.sav) [DO NOT CHOOSE .mat OR AN ERROR WILL OCCUR!!!]"
SYNC
DO
   count=3 : txtpos=30
   REPEAT
      MENUHOVER(10, txtpos, savelist$(count))
      IF MOUSECLICK()=1 AND MOUSEPOS(10, 135, txtpos, txtpos+20)
         CLS : SETGREY(255) : PRINT "                     >>LOADING<<" : SYNC
         OPEN TO READ 1, savelist$(count)
         READ STRING 1, name$
         READ BYTE 1,width
         READ BYTE 1,length
         READ BYTE 1,xtiles
         READ BYTE 1,ztiles
         READ BYTE 1,maxheight
         READ BYTE 1,smoothing
         CLOSE FILE 1
         DIM matrixdata#(10,xtiles,ztiles
         LOAD ARRAY name$+".mat",matrixdata#(0)
         PRINT "                  >>Click to Continue<<"
         SYNC
         WAIT MOUSE
         GOTO preview_mode
      ENDIF
      INC txtpos, 20
      INC count
      SYNC
      WAIT 100
   UNTIL count=totlsavs
   IF ESCAPEKEY()=1 THEN GOTO main_menu
LOOP
RETURN
 
save_matrix:
IF FILE EXIST("Sinister_Matrix_Maker.exe")=1 AND PATH EXIST("Saves")=0 THEN MAKE DIRECTORY "Saves" : CD "Saves" : MAKE FILE "zzz.zzz"
IF FILE EXIST("Sinister_Matrix_Maker.exe")=1 AND PATH EXIST("Saves")=1 THEN CD "Saves"
IF FILE EXIST(name$+".sav") THEN DELETE FILE name$+".sav"
IF FILE EXIST(name$+".mat") THEN DELETE FILE name$+".mat"
OPEN TO WRITE 1, name$+".sav"
WRITE STRING 1, name$
WRITE BYTE 1,width
WRITE BYTE 1,length
WRITE BYTE 1,xtiles
WRITE BYTE 1,ztiles
WRITE BYTE 1,maxheight
WRITE BYTE 1,smoothing
CLOSE FILE 1
SAVE ARRAY name$+".mat",matrixdata#(0)
CLS
PRINT "SAVED"
PRINT "Click To Continue"
SYNC
WAIT MOUSE
GOTO main_menu
RETURN
 
no_saves:
   PRINT "              There are no saved matrices"
   PRINT "                 Please create a matrix"
   PRINT "                >>Click to Continue<<"
   SYNC
   WAIT MOUSE : CLS : WAIT 100
   GOTO main_menu
RETURN
 
setup_matrix:
   DIM matrixsmoothed(xtile,ztiles)
   DIM matrixdata#(10,xtiles,ztiles)
   FOR a=0 TO xtiles
      FOR b=0 TO ztiles
         matrixdata#(1,a,b)=RND(maxheight)
      NEXT b
      RANDOMIZE a
   NEXT a
   FOR a=1 TO xtiles
      FOR b=1 TO ztiles
         matrixsmoothed(a,b)=3
      NEXT b
   NEXT a
   GOTO make_matrix
RETURN
 
Rem this is my super duper matrix smoothing algorithm!!!
make_matrix:
   CLS
   SETGREY(255)
   TEXT 10,10,"CREATING MATRIX: "+str$(done)+"%" : SYNC
   FOR c=2 TO 9
      FOR a=0 TO xtiles
         FOR b=0 TO ztiles
            IF b>0 AND b<ztiles
               matrixdata#(10,a,b)=(matrixdata#((c-1),a,b)+matrixdata#((c-1),a,(b+1))+matrixdata#((c-1),a,(b-1)))
            ELSE
               IF b=0 THEN matrixdata#(10,a,b)=(matrixdata#(c-1,a,b)+matrixdata#(c-1,a,b)+matrixdata#(c-1,a,(b+1)))
               IF b=ztiles THEN matrixdata#(10,a,b)=(matrixdata#(c-1,a,b)+matrixdata#(c-1,a,b)+matrixdata#(c-1,a,(b-1)))
            ENDIF
         NEXT b
      NEXT a
      FOR b=0 TO ztiles
         FOR a=0 TO xtiles
            IF a>0 AND b<xtiles
               matrixdata#(10,a,b)=(matrixdata#(10,a,b)+matrixdata#(c-1,a,b)+matrixdata#(c-1,(a+1),b)+matrixdata#(c-1,(a-1),b))
            ELSE
               IF a=0 THEN matrixdata#(10,a,b)=(matrixdata#(10,a,b)+matrixdata#(c-1,a,b)+matrixdata#(c-1,(a+1),b))
               IF a=xtiles THEN matrixdata#(10,a,b)=(matrixdata#(10,a,b)+matrixdata#(c-1,a,b)+matrixdata#(c-1,a,b)+matrixdata#(c-1,(a-1),b))
            ENDIF
         NEXT a
      NEXT b
      FOR a=0 TO xtiles
         FOR b=0 TO ztiles
               matrixdata#(c,a,b)=(matrixdata#(10,a,b)/4)
         NEXT b
      NEXT a
      INC done,10 : CLS : TEXT 10,10,"CREATING MATRIX: "+str$(done)+"%" : SYNC
   NEXT c
   FOR a=0 TO xtiles
      FOR b=0 TO ztiles
         matrixdata#(10,a,b)=matrixdata#(smoothing,a,b)
      NEXT b
   NEXT a
   CLS
   TEXT 10,10,"DONE"
   TEXT 15,30,"Click To Continue"
   SYNC
   WAIT MOUSE
   GOTO preview_mode
RETURN
 
preview_mode:
IF MATRIX EXIST(1) THEN DELETE MATRIX 1
   BACKDROP ON
   COLOR BACKDROP 0
   CLS
   MAKE MATRIX 1,width,length,xtiles,ztiles
   POSITION CAMERA 55,35,-100
   POINT CAMERA 0,0,0
   FOR a=0 TO (xtiles)
      FOR b=0 TO (ztiles)
         SET MATRIX HEIGHT 1,a,b,matrixdata#(smoothing,a,b)
      NEXT b
   NEXT a
   UPDATE MATRIX 1
   DO
      SETGREY(255)
      TEXT 300,100,"PREVIEW MODE"
      TEXT 0,0,"Use Arrowkeys To Zoom"
      TEXT 0,700,"Press Enter To Save The Matrix"
      camrot#=CAMERA ANGLE Y()
      ROTATE CAMERA 0,(camrot#+90),0
      MOVE CAMERA 0.5
      ROTATE CAMERA 0,(camrot#-90),0
      POINT CAMERA 0,0,0
      IF UPKEY()=1 THEN MOVE CAMERA 1
      IF DOWNKEY()=1 THEN XROTATE CAMERA 17 : MOVE CAMERA -1
      IF RETURNKEY()=1 THEN GOTO save_matrix
      IF ESCAPEKEY()=1 THEN DELETE MATRIX 1 : GOTO main_menu
      SYNC
   LOOP
RETURN
 
clearup:
END
RETURN
 
 
FUNCTION MENUHOVER(x,y,txt$)   `If the mouse hovers over a menu item the item darkens
   IF MOUSEPOS(x,x+150,y,y+20)=1
      SETGREY(150)
      TEXT x,y,txt$
   ELSE
      SETGREY(255)
      TEXT x,y,txt$
   ENDIF
ENDFUNCTION
 
FUNCTION SETGREY(a)              `Decreases R, G & B by an equal, specified amount
   INK RGB(a,a,a),RGB(0,0,0)
ENDFUNCTION
 
FUNCTION MOUSEPOS(x1,x2,y1,y2)`Determines whether the mouse is within the specified area
   IF MOUSEX()>x1 AND MOUSEX()<x2 AND MOUSEY()>y1 AND MOUSEY()<y2
      pos=1
   ELSE
      pos=0
   ENDIF
ENDFUNCTION pos
 
FUNCTION MESSAGEBOX(x1,x2,y1,y2) `Makes a small box for messages
   SETGREY(200)
   BOX (x1-2),(y1-2),(x2+2),(y2+2)
   SETGREY(100)
   BOX x1,y1,x2,y2
   SETGREY(255)
ENDFUNCTION
 
FUNCTION INPUTBOX(x,y) `Get's a value typed at a spcified point on the screen
   SETGREY(0)
   BOX x,y,(x+265),(y+35)
   SETGREY(255)
   SET CURSOR x,y
   INPUT var$
   safe=1
ENDFUNCTION var$