This one replaces gosubs and uses a lot of functions.
` Tyrant RPG Engine
`
` Version 0.01
`
` Date Started 13/12/2002
`
` Maze Engine
`
` Mazes are an array of 20x20 Blocks
`
` 00 = Empty
` 01 = Wall
` 02 = Door
` 03 = Chest
` 04 = Trap
` 05 = Entrance
` 06 = Stairs Up
` 07 = Stairs Down
` 08 = Random Treasure
` 100+n= Encounter Number, Where n=Encounter
`
` Direction Numbers
`
` 1-^
` 2->
` 3-v
` 4-<
`
`
` Setup Variables
`
SET TEXT FONT "Courier New"
SET TEXT SIZE 15
SET TEXT OPAQUE
#CONSTANT NumCols 20
#CONSTANT NumRows 20
#CONSTANT OffsetX 0
#CONSTANT OffsetY 0
` The Array containing all the maze data
DIM MazeArray(NumCols+1,NumRows+1)
DIM MazeView(3,3)
` Initialse Maze Data
GOSUB LoadMaze
GenerateView(CurrentX,CurrentY,Direction)
DO
GOSUB CheckKeys
LOOP
END
`
` SUBROUTINES
`
rem Check Keys routine for moving around.
CheckKeys:
IF UPKEY()
SELECT Direction
CASE 1
NewSq=MazeArray(CurrentX,CurrentY-1)
IF NewSq<>1 AND NewSq<>2
CurrentY=CurrentY-1
ENDIF
ENDCASE
CASE 2
NewSq=MazeArray(CurrentX+1,CurrentY)
IF NewSq<>1 AND NewSq<>2
CurrentX=CurrentX+1
ENDIF
ENDCASE
CASE 3
NewSq=MazeArray(CurrentX,CurrentY+1)
IF NewSq<>1 AND NewSq<>2
CurrentY=CurrentY+1
ENDIF
ENDCASE
CASE 4
NewSq=MazeArray(CurrentX-1,CurrentY)
IF NewSq<>1 AND NewSq<>2
CurrentX=CurrentX-1
ENDIF
ENDCASE
ENDSELECT
GenerateView(CurrentX,CurrentY,Direction)
WHILE UPKEY()
ENDWHILE
ENDIF
IF DOWNKEY()
SELECT Direction
CASE 1
NewSq=MazeArray(CurrentX,CurrentY+1)
IF NewSq<>1 AND NewSq<>2
CurrentY=CurrentY+1
ENDIF
ENDCASE
CASE 2
NewSq=MazeArray(CurrentX-1,CurrentY)
IF NewSq<>1 AND NewSq<>2
CurrentX=CurrentX-1
ENDIF
ENDCASE
CASE 3
NewSq=MazeArray(CurrentX,CurrentY-1)
IF NewSq<>1 AND NewSq<>2
CurrentY=CurrentY-1
ENDIF
ENDCASE
CASE 4
NewSq=MazeArray(CurrentX+1,CurrentY)
IF NewSq<>1 AND NewSq<>2
CurrentX=CurrentX+1
ENDIF
ENDCASE
ENDSELECT
GenerateView(CurrentX,CurrentY,Direction)
WHILE DOWNKEY()
ENDWHILE
ENDIF
IF SPACEKEY()
SELECT Direction
CASE 1
NewSq=MazeArray(CurrentX,CurrentY-1)
IF NewSq=2
CurrentY=CurrentY-2
ENDIF
ENDCASE
CASE 2
NewSq=MazeArray(CurrentX+1,CurrentY)
IF NewSq=2
CurrentX=CurrentX+2
ENDIF
ENDCASE
CASE 3
NewSq=MazeArray(CurrentX,CurrentY+1)
IF NewSq=2
CurrentY=CurrentY+2
ENDIF
ENDCASE
CASE 4
NewSq=MazeArray(CurrentX-1,CurrentY)
IF NewSq=2
CurrentX=CurrentX-2
ENDIF
ENDCASE
ENDSELECT
GenerateView(CurrentX,CurrentY,Direction)
WHILE SPACEKEY()
ENDWHILE
ENDIF
IF RIGHTKEY()
Direction=Direction+1
IF Direction>4 THEN Direction=1
GenerateView(CurrentX,CurrentY,Direction)
WHILE RIGHTKEY()=1
ENDWHILE
ENDIF
IF LEFTKEY()
Direction=Direction-1
IF Direction<1 THEN Direction=4
GenerateView(CurrentX,CurrentY,Direction)
WHILE LEFTKEY()=1
ENDWHILE
ENDIF
IF ESCAPEKEY() THEN END
RETURN
rem Load maze
LoadMaze:
CurrentX=-1
IF FILE EXIST("level0")
ELSE
PRINT "FATAL ERROR, Unable to load level0 maze map"
WAIT KEY
END
ENDIF
OPEN TO READ 1,"level0"
FOR Xarr=0 TO NumCols-1
FOR Yarr=0 TO NumRows-1
READ BYTE 1,MazeArray(Xarr,Yarr)
IF MazeArray(Xarr,Yarr)=5
CurrentX=Xarr
CurrentY=Yarr
Direction=1
ENDIF
NEXT Yarr
NEXT Xarr
CLOSE FILE 1
IF CurrentX=-1
PRINT "FATAL ERROR, Maze Data level0 doesnt contain a start point"
WAIT KEY
END
ENDIF
RETURN
`===================================================================
`= FUNCTIONS =
`===================================================================
FUNCTION GenerateView( CurrentX AS INTEGER, CurrentY AS INTEGER, Direction AS INTEGER )
SELECT Direction
CASE 1
MazeView(0,0)=MazeArray(CurrentX-1,CurrentY-2)
MazeView(1,0)=MazeArray(CurrentX,CurrentY-2)
MazeView(2,0)=MazeArray(CurrentX+1,CurrentY-2)
MazeView(0,1)=MazeArray(CurrentX-1,CurrentY-1)
MazeView(1,1)=MazeArray(CurrentX,CurrentY-1)
MazeView(2,1)=MazeArray(CurrentX+1,CurrentY-1)
MazeView(0,2)=MazeArray(CurrentX-1,CurrentY)
MazeView(1,2)=MazeArray(CurrentX,CurrentY)
MazeView(2,2)=MazeArray(CurrentX+1,CurrentY)
ENDCASE
CASE 2
MazeView(0,0)=MazeArray(CurrentX+2,CurrentY-1)
MazeView(1,0)=MazeArray(CurrentX+2,CurrentY)
MazeView(2,0)=MazeArray(CurrentX+2,CurrentY+1)
MazeView(0,1)=MazeArray(CurrentX+1,CurrentY-1)
MazeView(1,1)=MazeArray(CurrentX+1,CurrentY)
MazeView(2,1)=MazeArray(CurrentX+1,CurrentY+1)
MazeView(0,2)=MazeArray(CurrentX,CurrentY-1)
MazeView(1,2)=MazeArray(CurrentX,CurrentY)
MazeView(2,2)=MazeArray(CurrentX,CurrentY+1)
ENDCASE
CASE 3
MazeView(0,0)=MazeArray(CurrentX+1,CurrentY+2)
MazeView(1,0)=MazeArray(CurrentX,CurrentY+2)
MazeView(2,0)=MazeArray(CurrentX-1,CurrentY+2)
MazeView(0,1)=MazeArray(CurrentX+1,CurrentY+1)
MazeView(1,1)=MazeArray(CurrentX,CurrentY+1)
MazeView(2,1)=MazeArray(CurrentX-1,CurrentY+1)
MazeView(0,2)=MazeArray(CurrentX+1,CurrentY)
MazeView(1,2)=MazeArray(CurrentX,CurrentY)
MazeView(2,2)=MazeArray(CurrentX-1,CurrentY)
ENDCASE
CASE 4
MazeView(0,0)=MazeArray(CurrentX-2,CurrentY+1)
MazeView(1,0)=MazeArray(CurrentX-2,CurrentY)
MazeView(2,0)=MazeArray(CurrentX-2,CurrentY-1)
MazeView(0,1)=MazeArray(CurrentX-1,CurrentY+1)
MazeView(1,1)=MazeArray(CurrentX-1,CurrentY)
MazeView(2,1)=MazeArray(CurrentX-1,CurrentY-1)
MazeView(0,2)=MazeArray(CurrentX,CurrentY+1)
MazeView(1,2)=MazeArray(CurrentX,CurrentY)
MazeView(2,2)=MazeArray(CurrentX,CurrentY-1)
ENDCASE
ENDSELECT
DisplayView()
SET CURSOR 0,400
PRINT
PRINT "Current X=";CurrentX
PRINT "Current Y=";CurrentY
PRINT
PRINT "Direction Facing = ";
SELECT Direction
CASE 1
PRINT "^"
ENDCASE
CASE 2
PRINT ">"
ENDCASE
CASE 3
PRINT "v"
ENDCASE
CASE 4
PRINT "<"
ENDCASE
ENDSELECT
PRINT
FOR Yarr=0 TO 2
FOR Xarr=0 TO 2
PRINT MazeView(Xarr,Yarr);",";
NEXT Xarr
PRINT " "
NEXT Yarr
ENDFUNCTION
FUNCTION DisplayView()
DisplayBox()
IF MazeView(0,2)=1 THEN NearLeftWall()
IF MazeView(0,2)=2 THEN NearLeftDoor()
IF MazeView(2,2)=1 THEN NearRightWall()
IF MazeView(2,2)=2 THEN NearRightDoor()
IF MazeView(0,1)=1 AND (MazeView(1,1)<>1 AND MazeView(1,1)<>2) THEN LeftWall()
IF MazeView(0,1)=2 AND (MazeView(1,1)<>1 AND MazeView(1,1)<>2) THEN LeftDoor()
IF MazeView(0,1)=1 AND (MazeView(0,2)<>1 AND MazeView(0,2)<>2) THEN LeftWallEmpty()
IF MazeView(0,1)=2 AND (MazeView(0,2)<>1 AND MazeView(0,2)<>2) THEN LeftDoorEmpty()
IF MazeView(1,1)=1 THEN CentreWall()
IF MazeView(1,1)=2 THEN CentreDoor()
IF MazeView(2,1)=1 AND (MazeView(1,1)<>1 AND MazeView(1,1)<>2) THEN RightWall()
IF MazeView(2,1)=2 AND (MazeView(1,1)<>1 AND MazeView(1,1)<>2) THEN RightDoor()
IF MazeView(2,1)=1 AND (MazeView(2,2)<>1 AND MazeView(2,2)<>2) THEN RightWallEmpty()
IF MazeView(2,1)=2 AND (MazeView(2,2)<>1 AND MazeView(2,2)<>2) THEN RightDoorEmpty()
IF MazeView(0,0)=1 AND (MazeView(1,0)<>1 AND MazeView(1,0)<>2) AND (MazeView(1,1)<>1 AND MazeView(1,1)<>2) THEN FarLeftWall()
IF MazeView(0,0)=2 AND (MazeView(1,0)<>1 AND MazeView(1,0)<>2) AND (MazeView(1,1)<>1 AND MazeView(1,1)<>2) THEN FarLeftDoor()
IF MazeView(0,0)=1 AND (MazeView(0,1)<>1 AND MazeView(0,1)<>2) THEN FarLeftWallSection1()
IF MazeView(0,0)=2 AND (MazeView(0,1)<>1 AND MazeView(0,1)<>2) THEN FarLeftDoorSection1()
IF MazeView(0,0)=1 AND (MazeView(0,1)<>1 AND MazeView(0,1)<>2) AND (MazeView(0,2)<>1 AND MazeView(0,2)<>2) THEN FarLeftWallSection2()
IF MazeView(0,0)=2 AND (MazeView(0,1)<>1 AND MazeView(0,1)<>2) AND (MazeView(0,2)<>1 AND MazeView(0,2)<>2) THEN FarLeftDoorSection2()
IF MazeView(1,0)=1 AND (MazeView(1,1)<>1 AND MazeView(1,1)<>2) THEN FarCentreWall()
IF MazeView(1,0)=2 AND (MazeView(1,1)<>1 AND MazeView(1,1)<>2) THEN FarCentreDoor()
IF MazeView(2,0)=1 AND (MazeView(1,0)<>1 AND MazeView(1,0)<>2) AND (MazeView(1,1)<>1 AND MazeView(1,1)<>2) THEN FarRightWall()
IF MazeView(2,0)=2 AND (MazeView(1,0)<>1 AND MazeView(1,0)<>2) AND (MazeView(1,1)<>1 AND MazeView(1,1)<>2) THEN FarRightDoor()
IF MazeView(2,0)=1 AND (MazeView(2,1)<>1 AND MazeView(2,1)<>2) THEN FarRightWallSection1()
IF MazeView(2,0)=2 AND (MazeView(2,1)<>1 AND MazeView(2,1)<>2) THEN FarRightDoorSection1()
IF MazeView(2,0)=1 AND (MazeView(2,1)<>1 AND MazeView(2,1)<>2) AND (MazeView(2,2)<>1 AND MazeView(2,2)<>2) THEN FarRightWallSection2()
IF MazeView(2,0)=2 AND (MazeView(2,1)<>1 AND MazeView(2,1)<>2) AND (MazeView(2,2)<>1 AND MazeView(2,2)<>2) THEN FarRightDoorSection2()
ENDFUNCTION
FUNCTION DisplayBox()
OLINE(0,0,300,0)
OLINE(300,0,300,300)
OLINE(300,300,0,300)
OLINE(0,300,0,0)
INK 0,0
OBOX(1,1,300,300)
INK RGB(255,255,255),0
ENDFUNCTION
FUNCTION NearLeftWall()
OLINE(0,0,30,30)
OLINE(30,30,30,270)
OLINE(30,270,0,300)
ENDFUNCTION
FUNCTION NearLeftDoor()
NearLeftWall()
OLINE(0,20,10,30)
OLINE(10,30,10,290)
ENDFUNCTION
FUNCTION NearRightWall()
OLINE(300,0,270,30)
OLINE(270,30,270,270)
OLINE(270,270,300,300)
ENDFUNCTION
FUNCTION NearRightDoor()
NearRightWall()
OLINE(300,20,290,30)
OLINE(290,30,290,290)
ENDFUNCTION
FUNCTION LeftWall()
OLINE(30,30,90,90)
OLINE(90,90,90,210)
OLINE(90,210,30,270)
OLINE(30,270,30,30)
ENDFUNCTION
FUNCTION LeftDoor()
LeftWall()
OLINE(45,255,45,65)
OLINE(45,65,80,100)
OLINE(80,100,80,220)
OELLIPSE(58,165,3,4)
ENDFUNCTION
FUNCTION CentreWall()
OLINE(30,30,30,270)
OLINE(30,270,270,270)
OLINE(270,270,270,30)
OLINE(270,30,30,30)
ENDFUNCTION
FUNCTION CentreDoor()
CentreWall()
OLINE(90,270,90,50)
OLINE(90,50,210,50)
OLINE(210,50,210,270)
OCIRCLE(110,160,5)
ENDFUNCTION
FUNCTION RightWall()
OLINE(270,30,210,90)
OLINE(210,90,210,210)
OLINE(210,210,270,270)
OLINE(270,30,270,30)
ENDFUNCTION
FUNCTION RightDoor()
RightWall()
OLINE(255,255,255,65)
OLINE(255,65,220,100)
OLINE(220,100,220,220)
OELLIPSE(225,160,2,3)
ENDFUNCTION
FUNCTION LeftWallEmpty()
OLINE(0,30,30,30)
OLINE(30,30,30,270)
OLINE(30,270,0,270)
ENDFUNCTION
FUNCTION LeftDoorEmpty
LeftWallEmpty()
OLINE(0,50,3,50)
OLINE(3,50,3,270)
ENDFUNCTION
FUNCTION RightWallEmpty()
OLINE(300,30,270,30)
OLINE(270,30,270,270)
OLINE(270,270,300,270)
ENDFUNCTION
FUNCTION RightDoorEmpty()
RightWallEmpty()
OLINE(300,50,297,50)
OLINE(297,50,297,270)
ENDFUNCTION
FUNCTION FarLeftWall()
OLINE(90,90,120,120)
OLINE(120,120,120,180)
OLINE(120,180,90,210)
OLINE(90,210,90,90)
ENDFUNCTION
FUNCTION FarLeftDoor()
FarLeftWall()
OLINE(97,203,97,105)
OLINE(97,105,113,121)
OLINE(113,121,113,187)
OELLIPSE(100,154,1,2)
ENDFUNCTION
FUNCTION FarLeftWallSection1()
OLINE(30,90,90,90)
OLINE(90,90,90,210)
OLINE(90,210,30,210)
ENDFUNCTION
FUNCTION FarLeftDoorSection1()
FarLeftWallSection1()
OLINE(30,100,62,100)
OLINE(62,100,62,210)
ENDFUNCTION
FUNCTION FarLeftWallSection2()
OLINE(30,90,0,90)
OLINE(30,210,0,210)
ENDFUNCTION
FUNCTION FarLeftDoorSection2()
FarLeftWallSection2()
OLINE(30,100,2,100)
OLINE(2,100,2,210)
OCIRCLE(10,155,3)
ENDFUNCTION
FUNCTION FarCentreWall()
OLINE(90,90,90,210)
OLINE(90,210,210,210)
OLINE(210,210,210,90)
OLINE(210,90,90,90)
ENDFUNCTION
FUNCTION FarCentreDoor()
FarCentreWall()
OLINE(120,210,120,100)
OLINE(120,100,180,100)
OLINE(180,100,180,210)
OCIRCLE(130,155,3)
ENDFUNCTION
FUNCTION FarRightWall()
OLINE(210,90,180,120)
OLINE(180,120,180,180)
OLINE(180,180,210,210)
OLINE(210,210,210,90)
ENDFUNCTION
FUNCTION FarRightDoor()
FarRightWall()
OLINE(203,203,203,105)
OLINE(203,105,187,121)
OLINE(187,121,187,187)
OELLIPSE(189,154,1,2)
ENDFUNCTION
FUNCTION FarRightWallSection1()
OLINE(270,90,210,90)
OLINE(210,90,210,210)
OLINE(210,210,270,210)
ENDFUNCTION
FUNCTION FarRightDoorSection1()
FarRightWallSection1()
OLINE(270,100,238,100)
OLINE(238,100,238,210)
OCIRCLE(248,155,3)
ENDFUNCTION
FUNCTION FarRightWallSection2()
OLINE(270,90,300,90)
OLINE(270,210,300,210)
ENDFUNCTION
FUNCTION FarRightDoorSection2()
FarRightWallSection2()
OLINE(270,100,298,100)
OLINE(298,100,298,210)
ENDFUNCTION
FUNCTION OLINE( X1 AS INTEGER,Y1 AS INTEGER,X2 AS INTEGER,Y2 AS INTEGER )
LINE OffsetX+X1,OffsetY+Y1,OffsetX+X2,OffsetY+Y2
ENDFUNCTION
FUNCTION OCIRCLE( X AS INTEGER,Y AS INTEGER,Radius AS INTEGER )
CIRCLE OffsetX+X,OffsetY+Y,Radius
ENDFUNCTION
FUNCTION OELLIPSE( X AS INTEGER,Y AS INTEGER, XRadius AS INTEGER,YRadius AS INTEGER )
ELLIPSE OffsetX+X,OffsetY+Y,XRadius,YRadius
ENDFUNCTION
FUNCTION OBOX( X1 AS INTEGER,Y1 AS INTEGER,X2 AS INTEGER,Y2 AS INTEGER )
BOX OffsetX+X1,OffsetY+Y1,OffsetX+X2,OffsetY+Y2
ENDFUNCTION