home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d1xx
/
d171
/
maze.lha
/
Maze
/
README
< prev
next >
Wrap
Text File
|
1988-11-22
|
2KB
|
62 lines
[ Editors note -- I made some changes to make Aztec accept this program.
The changes I made are marked with "PDS(n)":
PDS(1) Expression was too complex.
PDS(2,3) Aztec requires a statement after a label. This is legit
according to K&R, by the way.
Peter da Silva, 31 July 1988 ]
This is a small, everything but useful routine to create mazes. The
resulting maze is unique, i.e. there is only one way from one point of the
maze to another. The logic is quite simple: first a border of passages is
drawn around the maze (just to prevent your 8 meg. memory expansion being
mapped out), then a random starting point is selected. The maze is divided
into 2*2 squares. From the current position we pick up a random direction
and draw a line (well, 2 points actually) to the next 2*2 square, if it is
free (i.e. if there is no passage, only walls). If it is not, we check the
remaining directions. If everything fails ( we got into a dead end), we
move one step back and check if we can continue from there. If we reach our
starting point while moving back, the maze is finished.
Syntax:
maze( width, height, area)
short width,height
char *area
width = width of your maze.
height = height of your maze
*area = pointer to the buffer where the maze should be generated.
The buffer should be clear,i.e zeroed.
Normally the program assumes your buffer being a matrix of [width][height]
chars. In return you will get your buffer filled with 1's (passage) and 0's
(walls).
If you define 'bitmap' (#define bitmap at the start of your program) the
result will be an area of bits. Bit clear means passage,bit set means wall.
To make life easy, there are two macros defined:
One to check if a x,y position is passage or wall:
MAZETEST (xpos,ypos,mazewidth,pointer to buffer)
result: 0 if passage, anything else if wall.
Another to set a position to passage:
MAZESET (xpos,ypos,mazewidth,pointer to buffer)
Included are two demo programs: SpeedDemo - Draws a maze into a
low resolution screen, press any key to get a new one, and 3Ddemo, a simple
3D maze featuring: No double buffering, no smooth animation and no sound.
Use the arrow keys on the num-pad to move.
If you use this code in your own program, I would be pleased if you send me
a copy.
Happy wandering (or wondering)
Werner Gunther
G35@DHDURZ2.BITNET
P.S. This code is freely distributable, deleteable etc.,etc...