Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Program that will generate a maze for a wizardry 1 style game.

Author
Message
jasuk70
21
Years of Service
User Offline
Joined: 3rd Dec 2002
Location: Hemel Hempstead
Posted: 28th Dec 2002 21:11
When saved it will produce a array which it writes to disk. This was my first program i had written so excues the gosubs. There will be a following program which will allow you to run round the maze but doesnt do the RPG stuff yet.


rem
rem Tyrant RPG Engine Tool
rem
rem Version 0.01
rem
rem Date Started 08/12/2002
rem
rem Maze Generator
rem
rem Mazes are an array of NumColsxNumRows Blocks
rem
rem 00 = Empty
rem 01 = Wall
rem 02 = Door
rem 03 = Chest
rem 04 = Trap
rem 05 = Entrance
rem 06 = Stairs Up
rem 07 = Stairs Down
rem 08 = Random Treasure
rem 100+n= Encounter Number, Where n=Encounter
rem

rem
rem Setup Variables
rem
SET TEXT FONT "Courier New"
SET TEXT SIZE 15
SET TEXT OPAQUE

#CONSTANT NumCols 20
#CONSTANT NumRows 20

` The Array containing all the maze data
DIM MazeArray(NumCols,NumRows)
` These are the offset for drawing the Grid for the top right hand corner
BaseGridX=150
BaseGridY=150
` These represent the Height and Width of each grid square to
` be drawn on screen.
GridSqHeight=20
GridSqWidth=20
` Set the Current square in the grid we are working on.
CurrentX=1
CurrentY=1
EldX=-1
EldY=-1
` Set the current Menu position To Empty space, plus set up menu vars.
CurrentMenu=1
FontHeight=TEXT HEIGHT("Random Treasure")
FontWidth=TEXT WIDTH("Random Treasure")
Offset=FontHeight*2
Option=-1
EldOption=-1
ObjectType=0
EldObjextType=1
` Blank out the Maze Array to Empty Spaces
FOR X=1 TO NumCols
FOR Y=1 TO NumRows
MazeArray(X,Y)=0
NEXT Y
NEXT X
` Setup the Menu text
DIM Menu$(13)
Menu$(0)=" Empty Space "
Menu$(1)=" Wall "
Menu$(2)=" Door "
Menu$(3)=" Chest "
Menu$(4)=" Trap "
Menu$(5)=" Entrance "
Menu$(6)=" Stairs Up "
Menu$(7)=" Stairs Down "
Menu$(8)="Random Treasure"
Menu$(9)=" Encounter "
Menu$(10)=" SAVE "
Menu$(11)=" LOAD "
Menu$(12)=" QUIT "

rem
rem Setup Screen
rem

GOSUB SetupScreen

rem
rem Main Program Loop
rem

DO
GOSUB CheckMouse
GOSUB ActionGrid
GOSUB ActionMenu
LOOP

rem
rem SUBROUTINES
rem

rem
rem Set up the screen for the initial display of the maze
rem
SetupScreen:
CLS
SET CURSOR 0,0
PRINT "Tyrant RPG Engine Maze Generator"
PRINT
PRINT Menu$(0)
INK RGB(150,150,150),0
FOR Lp=1 TO 12
PRINT Menu$(Lp)
NEXT Lp
` Drawer Menu Grid
FOR Lp=0 TO 12
YStart=Offset+(Lp*FontHeight)
YEnd =Offset+((Lp+1)*FontHeight)
Line 0,YStart,FontWidth,YStart
Line FontWidth,YStart,FontWidth,YEnd
LINE FontWidth,YEnd,0,YEnd
Line 0,YEnd,0,YStart
Next Lp
INK RGB(255,255,255),0
GOSUB RefreshMaze
RETURN

rem
rem fresh the maze Drawn on the screen
rem
RefreshMaze:
` Draw the Basic Grid on screen in dull colour first
INK RGB(150,150,150),0
FOR X=1 TO NumCols+1
` Calculate the Start and end of the line Plus the row,
XCoord=BaseGridX+(GridSqWidth*(X-1))
YStart=BaseGridY
YEnd =BaseGridY+(NumRows*GridSqHeight)
LINE XCoord,YStart,XCoord,YEnd
NEXT X

FOR Y=1 TO NumRows+1
` Calculate the Start and end of the line Plus the row,
XStart=BaseGridX
XEnd =BaseGridX+(NumCols*GridSqWidth)
YCoord=BaseGridY+(GridSqHeight*(Y-1))
LINE XStart,YCoord,XEnd,YCoord
NEXT Y
INK RGB(255,255,255),0
FOR DispX=0 TO NumCols-1
FOR DispY=0 TO NumRows-1
GOSUB DisplayGridObject
NEXT DispY
Next DispX
RETURN

rem Check to see if mouse is over a maze block.
CheckMouse:
XStart=BaseGridX
XEnd =BaseGridX+(NumCols*GridSqWidth)-1
YStart=BaseGridY
YEnd =BaseGridY+(NumRows*GridSqHeight)-1
Mx=MOUSEX()
My=MOUSEY()
Button=MOUSECLICK()
OverGrid=0
OverMenu=0
` If mouse is on the Grid then set the cordinates of the Grid that
` the mouse is over
IF Mx>=XStart AND Mx=YStart AND My=MenuYStart AND MyEldX OR CurrentYEldY
GOSUB DrawEldGrid
GOSUB DrawGrid
EldX=CurrentX
EldY=CurrentY
ENDIF
IF OverGrid AND Button
IF ObjectType=9
SET CURSOR 250,100
INPUT "Enter Encounter Number>",EncNo
SET CURSOR 250,100
PRINT " "
ObjectType=199+EncNo
ENDIF
MazeArray(CurrentX,CurrentY)=ObjectType
IF ObjectType>=200 THEN ObjectType=9
DispX=CurrentX
DispY=CurrentY
GOSUB DisplayGridObject
ENDIF
RETURN

rem Action Mouse for Menu
ActionMenu:
IF EldOptionOption
EldOpt=EldOption
GOSUB DrawEldMenu
GOSUB DrawMenu
EldOption=Option
ENDIF
IF OverMenu AND Button
IF Option>9
SELECT Option
CASE 10
GOSUB SaveMaze
ENDCASE
CASE 11
GOSUB LoadMaze
ENDCASE
CASE 12
END
ENDCASE
ENDSELECT
ELSE
ObjectType=Option
IF EldObjectTypeObjectType
SET CURSOR 0,(2*FontHeight)+(EldObjectType*FontHeight)
INK RGB(150,150,150),0
Opt=EldObjectType
GOSUB DisplayMenuOption
EldOpt=EldObjectType
GOSUB DrawEldMenu
ENDIF
SET CURSOR 0,(2*FontHeight)+(ObjectType*FontHeight)
Opt=ObjectType
GOSUB DisplayMenuOption
GOSUB DrawMenu
EldObjectType=ObjectType
ENDIF
ENDIF
RETURN

rem Display the menu option
DisplayMenuOption:
PRINT Menu$(Opt)
RETURN

rem Display greyed out menu box
DrawEldMenu:
IF EldOpt>=0
INK RGB(150,150,150),0
YStart=Offset+(EldOpt*FontHeight)
YEnd =Offset+((EldOpt+1)*FontHeight)
LINE 0,YStart,FontWidth,YStart
LINE FontWidth,YStart,FontWidth,YEnd
LINE FontWidth,YEnd,0,YEnd
LINE 0,YEnd,0,YStart
INK RGB(255,255,255),0
ENDIF
RETURN

rem Display white menu box
DrawMenu:
IF Option>=0
YStart=Offset+(Option*FontHeight)
YEnd =Offset+((Option+1)*FontHeight)
LINE 0,YStart,FontWidth,YStart
LINE FontWidth,YStart,FontWidth,YEnd
LINE FontWidth,YEnd,0,YEnd
LINE 0,YEnd,0,YStart
ENDIF
RETURN

rem Display eld Grid Box
DrawEldGrid:
IF EldX>=0 OR EldY>=0
XStart=BaseGridX+(EldX*GridSqWidth)
XEnd =BaseGridX+((EldX+1)*GridSqWidth)
YStart=BaseGridY+(EldY*GridSqHeight)
YEnd =BaseGridY+((EldY+1)*GridSqHeight)
INK RGB(150,150,150),0
LINE XStart,YStart,XEnd,YStart
LINE XEnd,YStart,XEnd,YEnd
LINE XEnd,YEnd,XStart,YEnd
LINE XStart,YEnd,XStart,YStart
INK RGB(255,255,255),0
ENDIF
RETURN

rem Display Grid Box
DrawGrid:
IF CurrentX>=0 OR CurrentY>=0
XStart=BaseGridX+(CurrentX*GridSqWidth)
XEnd =BaseGridX+((CurrentX+1)*GridSqWidth)
YStart=BaseGridY+(CurrentY*GridSqHeight)
YEnd =BaseGridY+((CurrentY+1)*GridSqHeight)
LINE XStart,YStart,XEnd,YStart
LINE XEnd,YStart,XEnd,YEnd
LINE XEnd,YEnd,XStart,YEnd
LINE XStart,YEnd,XStart,YStart
ENDIF
RETURN

rem Display the Object Type at the CurrentX,CurrentY position.
DisplayGridObject:
GridObject=MazeArray(DispX,DispY)
XStart=BaseGridX+(DispX*GridSqWidth)
XEnd =BaseGridX+((DispX+1)*GridSqWidth)
YStart=BaseGridY+(DispY*GridSqHeight)
YEnd =BaseGridY+((DispY+1)*GridSqHeight)
SELECT GridObject
CASE 0
` Empty Space
INK RGB(255,255,255),0
BOX XStart,YStart,XEnd,YEnd
ENDCASE
CASE 1
` Wall
INK 0,0
BOX XStart,YStart,XEnd,YEnd
ENDCASE
CASE 2
` Door
INK RGB(150,150,150),0
BOX XStart,YStart,XEnd,YEnd
INK 0,0
SET TEXT TRANSPARENT
TEXT XStart+7,YStart+2,"D"
SET TEXT OPAQUE
ENDCASE
CASE 3
` Chest
INK RGB(0,150,0),0
BOX XStart,YStart,XEnd,YEnd
INK 0,0
SET TEXT TRANSPARENT
TEXT XStart+7,YStart+2,"C"
SET TEXT OPAQUE
ENDCASE
CASE 4
` Trap
INK RGB(150,0,0),0
BOX XStart,YStart,XEnd,YEnd
INK 0,0
SET TEXT TRANSPARENT
TEXT XStart+7,YStart+2,"T"
SET TEXT OPAQUE
ENDCASE
CASE 5
` Entrance
INK 0,0
SET TEXT TRANSPARENT
TEXT XStart+7,YStart+2,"e"
SET TEXT OPAQUE
ENDCASE
CASE 6
` Stairs Up
INK 0,0
SET TEXT TRANSPARENT
TEXT XStart+7,YStart+2,"^"
SET TEXT OPAQUE
ENDCASE
CASE 7
` Stairs Down
INK 0,0
SET TEXT TRANSPARENT
TEXT XStart+7,YStart+2,"v"
SET TEXT OPAQUE
ENDCASE
CASE 8
` Random Treasure
INK RGB(0,0,150),0
BOX XStart,YStart,XEnd,YEnd
INK RGB(255,255,255),0
SET TEXT TRANSPARENT
TEXT XStart+7,YStart+2,"£"
SET TEXT OPAQUE
ENDCASE
CASE DEFAULT
` Encounter
INK RGB(255,255,225),0
BOX XStart,YStart,XEnd,YEnd
INK 0,0
SET TEXT TRANSPARENT
IF GridObject
jasuk70
21
Years of Service
User Offline
Joined: 3rd Dec 2002
Location: Hemel Hempstead
Posted: 28th Dec 2002 21:11
Hmm, not having much luck with posting code at the moment, will try again:

Login to post a reply

Server time is: 2024-11-24 07:20:58
Your offset time is: 2024-11-24 07:20:58