A downloadable game

Maze Adventure

Explore the maze, collect all of the keys and then get to the exit portal to progress to the next level.


Keys:

Cursor keys


Note that there is a 15 second (approx.) delay at the start of the game and before each new level as the maze is being generated

The maze generation algorithm used is a randomised depth first search (https://en.wikipedia.org/wiki/Maze_generation_algorithm#Randomized_depth-first_search) variables used in main program (all variables are global apart from x and y which are local in PROCa):

n and m - these values determine the size of the maze. m should be set to n*2+2

for a 5 x 5 maze: n = 10, m = 22

for a 4 x 4 maze: n = 8, m = 18

for a 6 x 6 maze: n = 12, m = 26

g - 2d array representing the maze. even rows/columns represent the cells (each room contains 2x2 cells). odd rows/columns represent the walls between cells

w - level number (therefore also the number of keys in the current level)

r - used to seed the pseudo random number generator

a,b - loop counters. Later used for the left/right and up/down displacements of the cursor key pressed

i,j,c - loop counters

x,y (global variables) - x,y coordinates of cell that object is being put into

k,l - x,y coordinates of current room within maze (in steps of 4, starting at 1)

s,t - x,y coordinates of player within current room

v - number of keys collected

u - key pressed

z - loop counter. Later what lies in the direction that the player has tried to go:

0 - empty space

1 - key

2 - exit portal

3 - wall

variables used in PROCa:

x,y (local variables) - x and y coordinates of current cell

v - loop counter for the directions list

z - used to choose a random direction. Later 0 if the adjacent cell has been visited, 1 if unvisited

r - is the random direction chosen

a,b - a is the left/right displacement of this direction, b is the up/down displacement

Program explanation (referring to the expanded version)

initialisation (set size of maze)

100n=10

101m=22

dimension the array (all array elements are set to 0 initially)

102DIMg(m,m)

set level to 1

103w=1

main game loop

104REPEAT

seed the pseudorandom number generator

105r=RND(-TIME)

set all "internal" cells as unvisited (leaving a border of visited cells around them)

106FORb=1TOm-1

107FORa=1TOm-1

108g(b,a)=1

109NEXT,

generate the maze (starting at the top left corner). PROCa also sets v (number of keys collected) to 0.

110PROCa(2,2)

111MODE4

disable cursor

112VDU23,1,0;0;0;0;

put the objects into the cells (w keys and 1 exit portal)

200FORi=0TOw

choose a random cell, make sure that it is empty

201REPEAT

202x=RND(n)*2

203y=RND(n)*2

204UNTILg(y,x)=0

put an object into that cell

205g(y,x)=193-(i=0)

206NEXT

display the level number

207PRINT;w

display the top left "door post"

208VDU9,227

initialise the x and y coordinates of the room

209k=1

210l=1

initialise the x and y coordinates of the player within the room

211s=5

212t=4

disable the cursor keys for editing

213*FX4,1

A% is used by the &FFF4 (OSBYTE) call later on

300A%=135

current level loop

301REPEAT

display/erase the objects in the cells in the current room

302FORj=0TO1

303FORi=0TO1

304VDU31,18*i+10,14*j+8,g(l+j*2+1,k+i*2+1)+32

305NEXT,

display/erase the walls for the current room

z is 0 for the horizontal walls and 1 for the vertical walls

306FORz=0TO1

307FORj=0TO2-z

308FORi=0TOz+1

400VDU31,i*18+2-z,j*14+z+1,17,g(l+j*2+z,k+i*2+1-z)

401FORc=z*4TO16

402VDU227,8,9+z

403NEXT

set colour back to white, display the "door post"

404VDU17,1,227

405NEXT,,

current room loop

406REPEAT

display the player

407VDU31,s,t,227

valid move loop

500REPEAT

valid key press loop

501REPEAT

502u=GET-136

503b=(u=3)-(u=2)

504a=(u=0)-(u=1)

505UNTILa+b

check what lies in the direction that the player has tried to go

506VDU31,s+a,t+b

&FFF4 (OSBYTE) call with A%=135 returns the character at the current cursor position

507z=(USR(&FFF4)AND768)/256

0 - empty space

1 - key

2 - exit portal

3 - wall

exit loop when z = 0 OR z = 1 OR z = 2 AND all keys have been collected, otherwise can't go in that direction

508UNTILz+(v=w)<2

erase the player

600VDU31,s,t,32

update player x and y coordinates

601s=s+a

602t=t+b

if key collected then remove it from the cell, increment keys collected, beep, change palette to green if all keys have been collected, display keys collected

603IFz=1THENg(l+t DIV7,k+s DIV9)=0:v=v+1:VDU7,19,1,7+(v=w)*5;0;31,38+(v>9),0:PRINT;v

exit loop when player has exited room or has reached exit portal

700UNTILs=0ORs=38ORt=0ORt=30ORz=2

if exited room from left/right enter new room from right/left

701s=s-a*37

if exited room from above/below enter new room from below/above

702t=t-b*29

update room coordinates

703l=l+b*4

704k=k+a*4

exit loop if reached exit portal (level completed)

705UNTILz=2

increment level

706w=w+1

flash screen green/magenta

707VDU19,1,10;0;

play sound effect for end of level

708GOSUB1000

exit loop when final level has been completed (not enough cells to put all of the objects in next level)

709UNTILw=n*n

710END

maze generation algorithm

800DEFPROCa(x,y)

set cell as visited

801g(y,x)=0

if PROCa has been called from the main program then define the graphics characters, set the beep to a higher pitch

802IFr<0THEN!&C08=&FD070000:!&C0C=&A7:!&C10=&A5BD81FF:!&C14=&FF81BDA5:!&C18=-1:!&C1C=-1:?&265=200

set the 4 directions to choose from

1 - up

3 - left

5 - right

7 - down

900!&70=&7050301

check the directions in a random order, looking for the 1st one where the cell in that direction is unvisited

901v=4

902REPEAT

RND(12) is used because 12 is the LCM of 1, 2, 3 and 4

903z=RND(12)MODv

r is the direction chosen

904r=z?&70

replace that direction in the list with the one at the end of the list

905z?&70=v?&6F

906b=r DIV3-1

907a=r MOD3-1

908z=g(y+b*2,x+a*2)

lose the direction at the end of the list

909v=v-1

exit loop when the directions list is empty or when we've found a direction that we can go in

910UNTILv=0ORz

if we've found a valid direction then remove the wall through to that cell and generate more maze in that direction (i.e. recursive call to PROCa). When we come back, look for valid directions again.

if there were no valid directions found then backtrack

if called from GOSUB1000 then z will be 2 so play sound effect for end of level

1000IFz=1THENg(y+b,x+a)=0:PROCa(x+a*2,y+b*2):GOTO900ELSEIFz=0THENENDPROC ELSEFORz=0TO255:SOUND1ANDz,-15,z,0:NEXT:RETURN

Download

Download
MAZE.ssd 200 kB
Download
MAZE.txt 1 kB
Download
MAZEFULL.txt 1 kB
Download
README.txt 6 kB

Install instructions

The emulator that I used is an online one: JSBeeb - https://bbc.godbolt.org

Simply copy and paste the source code into it and then type RUN

Leave a comment

Log in with itch.io to leave a comment.