3-D Maze Escape

Type
Game
Category
First-person maze game
Author
David Bohlke
Published in
Antic, April 1983 (Vol. 2, No. 1), In the Public Domain
Year
1983
Language
Atari BASIC
Requirements
16K RAM, Atari BASIC, joystick in port 1
A first-person view down a maze corridor drawn in purple lines on olive green, with side openings, a small footprint marker on the floor, a big-digit timer reading 3090 at the bottom left and a compass arrow at the bottom right

About the program

"This game will place you in a gigantic random maze from which there is only one route of escape." In David Bohlke's 3-D Maze Escape you see the maze as if you were standing in it: high walls, side passages and corridors fading into the distance. You have to find the way out in the shortest time. Several players can take turns, alone or as teams, to see who escapes fastest.

Typing it in

The listing below has one correction. On the original Antic disk, line 110 was corrupted in a way that put the maze off the screen and stopped the program with ERROR 141; here it reads as printed in the magazine (see "Changes from the published listing").

The special characters are in lines 20400–20413. They draw the big digits of the timer and the compass arrows from line-graphics characters, cursor moves and | bars. {CTRL-Q}, {CTRL-R}, {CTRL-E} and the like mean hold CTRL and press the letter. {DOWN} and {LEFT} are cursor moves, typed inside the quotes as ESC then CTRL-= and ESC then CTRL-+. Each of those lines must be exact, or the digits come out jumbled.

How to play

Press SELECT to set the maze width, from an easy 11 × 11 to "an almost impossible" 35 × 35, then START. You can watch the program build the maze, which takes a while for big ones, and then you're placed inside it.

  • Push the stick left or right to turn 90 degrees. Push it forward to walk to the next intersection.
  • Turn round and you'll see "tracks" on the floor where you've been.
  • The timer at the lower left runs all the time and jumps by five for every step.
  • Press the button for an overhead map, showing your path in red and your position flashing. The timer runs about ten times faster while you look. Press the button again to go back.

How it works

  • Building the maze (lines 200–390) is a "recursive backtracker" written without recursion. From a random start, it digs two pixels at a time in a random direction into unvisited space, which it checks with LOCATE. Each position is pushed onto the arrays M() and N(). At a dead end, it pops back until it finds a way on. The maze is drawn in GRAPHICS 5 as it grows.
  • Surviving CLR. Line 412 uses CLR to throw away those big arrays and free memory. Because CLR erases every variable, line 410 first POKEs the maze size and position into memory locations 96–98, and line 420 reads them back afterwards.
  • The map as a string. The maze is copied into A$, 40 characters per row: open, footprint, wall or exit. Moving is just adding −40, +1, +40 or −1 to an index.
  • The 3-D view (lines 800–900) looks up to eight squares ahead. At each depth it draws a wall or an opening on the left and the right, from perspective tables built in lines 2000–2010.

Changes from the published listing

Line As published Now Why
110 XM=INT((38-MD)/2)+241.068713:… XM=INT((38-MD)/2)+2:… The constant was corrupted on the Antic disk; restored from the printed magazine. The corrupt value put the maze off screen (ERROR 141).
465, 504, 506, 20090–20110 DIR DRN Altirra BASIC (used by many emulators) has a DIR command, so it rejected lines that use a variable named DIR. The same-length name keeps memory use identical; behaviour on Atari BASIC is unchanged.

Listing

1 REM MAZE... IN {inv}ANTIC{/inv} MAG. (APR. '83)PAGE #69.
50 GRAPHICS 18
51 POKE 710,0
52 MD=11
53 POSITION 0,0:? #6;"--------------------"
55 POSITION 3,1:PRINT #6;"3-d maze escape"
57 ? #6;"--------------------"
60 POSITION 1,3:? #6;"select MAZE WIDTH":POSITION 1,5:PRINT #6;" THEN PRESS start"
70 IF PEEK(53279)=6 THEN 100
75 IF PEEK(53279)=5 THEN MD=MD+2:IF MD>35 THEN MD=11
85 POSITION 5,8:PRINT #6;"{inv}width{/inv}=";MD
90 FOR I=1 TO 5:SOUND 0,RND(0)*100,10,2:NEXT I:GOTO 70
100 GRAPHICS 5:POKE 752,1
102 POKE 710,0
110 XM=INT((38-MD)/2)+2:YM=INT((38-MD)/2)
120 COLOR 2:PLOT XM,YM:DRAWTO XM+MD-1,YM:DRAWTO XM+MD-1,YM+MD-1:DRAWTO XM,YM+MD-1:DRAWTO XM,YM
150 PRINT
160 PRINT :PRINT "INTERSECTION","     RESET"
200 DIM M(200),N(200)
210 K=0:M=INT(RND(0)*MD/3)*2+XM+2
215 N=INT(RND(0)*MD/3)*2+YM+2
220 PLOT M,N
240 LOCATE M+2,N,X:IF X=0 THEN 250
242 LOCATE M-2,N,X:IF X=0 THEN 250
244 LOCATE M,N+2,X:IF X=0 THEN 250
246 LOCATE M,N-2,X:IF X=0 THEN 250
248 GOTO 370
250 D=INT(RND(0)*4)+251:GOTO D
251 M1=-1:N1=0:GOTO 300
252 M1=0:N1=1:GOTO 300
253 M1=1:N1=0:GOTO 300
254 M1=0:N1=-1
300 LOCATE M+M1*2,N+N1*2,X:IF X>0 THEN 250
310 PLOT M+M1,N+N1:PLOT M+M1*2,N+N1*2
320 SOUND O,M+N,10,4
330 M=M+M1*2:N=N+N1*2:K=K+1:M(K)=M:N(K)=N:POKE 656,2:POKE 657,16:PRINT K;" ";:GOTO 240
370 M=M(K):N=N(K):K=K-1:POKE 656,2:POKE 657,35:PRINT K;" ";
380 IF K=0 THEN 400
390 GOTO 240
400 COLOR 3:PLOT XM+1,YM+1:DRAWTO XM+MD-2,YM+1:DRAWTO XM+MD-2,YM+MD-2
402 COLOR 3:PLOT XM+1,YM+1:DRAWTO XM+MD-2,YM+1:DRAWTO XM+MD-2,YM+MD-2
403 DRAWTO XM+1,YM+MD-2:DRAWTO XM+1,YM+1
405 POKE 656,3:POKE 657,10:PRINT "filling  array . . .";
410 POKE 96,MD:POKE 97,XM:POKE 98,YM
412 CLR :DIM A$(1600):A$=" "
413 DIM N$(1),F$(1),W$(1),E$(1),L$(1),R$(1),U(8),D(8),R(8),L(8),P$(5)
414 N$=CHR$(0):F$=CHR$(1):W$=CHR$(2):E$=CHR$(3)
415 SOUND 0,0,0,0:GOSUB 2000
420 MD=PEEK(96):XM=PEEK(97):YM=PEEK(98)
430 FOR X=XM-1 TO XM+MD:FOR Y=YM-1 TO YM+MD
432 LOCATE X,Y,C:A$(Y*40+X,Y*40+X)=CHR$(C):COLOR C+6:PLOT X+40,Y
434 NEXT Y:SOUND 0,X*5,10,2:NEXT X
446 PT=PT+50
460 X=INT(RND(0)*6+(MD-7)/2)+XM+1
462 Y=INT(RND(0)*6+(MD-7)/2)+YM+1
464 IF A$(Y*40+X,Y*40+X)=W$ THEN 460
465 DRN=0
470 D=-40:R=1:L=-1:GOSUB 800
480 A=Y*40+X:A$(A,A)=F$
490 PT=0:POKE 752,1:POKE 77,0
500 S=STICK(0)
504 IF S=11 THEN DRN=DRN-1:GOSUB 950:GOTO 515
506 IF S=7 THEN DRN=DRN+1:GOSUB 970:GOTO 515
510 IF S=14 THEN 530
512 GOTO 517
515 GOSUB 800:PT=PT+1
517 SOUND 0,RND(0)*200,10,2:POKE 77,0
518 PT=PT+0.1
520 IF STRIG(0)=1 THEN 550
522 GOSUB 700:GOSUB 800:GOTO 500
530 A=Y*40+X:A=A+D:IF A$(A,A)=W$ THEN 500
535 IF A$(A,A)=E$ THEN GOTO 650
540 Y=INT(A/40):X=A-40*Y:GOSUB 800
545 A=Y*40+X:A$(A,A)=F$
546 PT=PT+5
550 GOSUB 20000
590 GOTO 500
650 GRAPHICS 17:? #6;"**you have escaped**"
651 ? #6;"press fire";
652 ? #6;" to go on":? #6;"********************":? #6;"or pull back on the":? #6;"stick to see path"
653 IF STICK(0)=13 THEN GOSUB 700
654 IF STRIG(0)=1 THEN SOUND 0,RND(0)*200,10,2:GOTO 653
655 RUN
700 GRAPHICS 5:POKE 710,0:POKE 752,1:PT=INT(PT)
705 IF A$(A,A)<>E$ THEN PT=PT+10*MD
720 COLOR 1:PLOT X,Y
730 FOR M=XM+1 TO XM+MD-2:FOR N=YM+1 TO YM+MD-2
732 C=ASC(A$(M+N*40,M+N*40))
734 COLOR C:PLOT M,N
736 NEXT N:SOUND 0,M*5,10,2:NEXT M
780 PRINT :PRINT "press {inv}FIRE{/inv} to return. . .";
782 PT=PT+1:IF A$(A,A)=E$ THEN PT=INT(PT/10)*10
783 POKE 656,0:POKE 657,23:PRINT " SCORE ";PT;
784 SOUND 0,RND(0)*200,10,2
786 IF STRIG(0)=0 THEN RETURN
790 IF PT/10<>INT(PT/10) THEN 782
792 IF C=1 THEN C=2:GOTO 795
794 C=1
795 COLOR C:PLOT X,Y
796 GOTO 782
800 GRAPHICS 7:POKE 752,1
801 SETCOLOR 2,13,4:SETCOLOR 4,13,4
802 SETCOLOR 1,5,10:SETCOLOR 0,13,12
805 A=Y*40+X
810 S=1:GOSUB 910
820 S=S+1:IF S=9 THEN RETURN
822 SOUND 0,S*20,4,2
825 COLOR 2:PLOT L(S),U(S):DRAWTO L(S),D(S)
826 PLOT R(S),U(S):DRAWTO R(S),D(S)
828 IF A$(A+D,A+D)=F$ THEN GOSUB 900
830 IF A$(A+L,A+L)=W$ THEN 840
834 COLOR 1:PLOT L(S),U(S):DRAWTO L(S-1)+1,U(S)
835 PLOT L(S),D(S):DRAWTO L(S-1)+1,D(S):GOTO 850
840 COLOR 2:PLOT L(S),U(S):DRAWTO L(S-1),U(S-1)
842 PLOT L(S),D(S):DRAWTO L(S-1),D(S-1)
850 IF A$(A+R,A+R)=W$ THEN 860
854 COLOR 1:PLOT R(S),U(S):DRAWTO R(S-1)-1,U(S)
855 PLOT R(S),D(S):DRAWTO R(S-1)-1,D(S):GOTO 870
860 COLOR 2:PLOT R(S),U(S):DRAWTO R(S-1),U(S-1)
862 PLOT R(S),D(S):DRAWTO R(S-1),D(S-1)
870 IF A$(A+D,A+D)=W$ THEN 873
872 A=A+D:GOTO 820
873 COLOR 2:PLOT L(S),U(S):DRAWTO R(S),U(S)
874 PLOT L(S),D(S):DRAWTO R(S),D(S)
899 RETURN
900 I=ABS(R(S)-L(S))/2
905 COLOR 1:PLOT L(S)+I,D(S):RETURN
910 COLOR 2:J=69:I=RND(0)*90+35
912 PLOT I,J:DRAWTO I,J+5:DRAWTO I-2,J+7
914 PLOT I-1,J+1:PLOT I+1,J+1:PLOT I+1,J+6:PLOT I+2,J+7
916 PLOT I-3,J+3:DRAWTO I-2,J+4:DRAWTO I+3,J+5:RETURN
950 IF D=-40 THEN D=-1:R=-40:L=40:RETURN
952 IF D=-1 THEN D=40:R=-1:L=1:RETURN
954 IF D=40 THEN D=1:R=40:L=-40:RETURN
956 IF D=1 THEN D=-40:R=1:L=-1:RETURN
958 PRINT :PRINT "ERROR":END
970 IF D=-40 THEN D=40:GOTO 954
972 IF D=1 THEN D=-1:GOTO 952
974 IF D=40 THEN D=-40:GOTO 950
976 IF D=-1 THEN D=1:GOTO 956
978 GOTO 958
2000 U(0)=-6:FOR I=1 TO 8:U(I)=U(I-1)+10-I:NEXT I
2010 D(0)=84:FOR I=1 TO 8:D(I)=D(I-1)-(10-I):NEXT I
2020 L(0)=-12:FOR I=1 TO 8:L(I)=L(I-1)+(10-I)*2-1:NEXT I
2030 R(0)=151:FOR I=1 TO 8:R(I)=R(I-1)-(9-I)*2-1:NEXT I
2035 FOR I=1 TO 8:L(I)=L(I)+14:R(I)=R(I)+14:NEXT I
2040 RETURN
20000 P$=STR$(INT(PT))
20040 FOR I=1 TO LEN(P$)
20050 POKE 656,1:POKE 657,I*3
20060 GOSUB VAL(P$(I,I))+20400
20070 NEXT I
20080 POKE 656,1:POKE 657,34
20090 IF DRN=-1 THEN DRN=3
20100 IF DRN=4 THEN DRN=0
20110 GOSUB DRN+20410:RETURN
20400 ? "{CTRL-Q}{CTRL-R}{CTRL-E}{DOWN}{LEFT}{LEFT}{LEFT}| |{DOWN}{LEFT}{LEFT}{LEFT}{CTRL-Z}{CTRL-R}{CTRL-C}                ";:RETURN
20401 ? " {CTRL-E} {DOWN}{LEFT}{LEFT}{LEFT} | {DOWN}{LEFT}{LEFT}{LEFT} {CTRL-X} ";:RETURN
20402 ? "{CTRL-Q}{CTRL-R}{CTRL-E}{DOWN}{LEFT}{LEFT}{LEFT}{CTRL-Q}{CTRL-R}{CTRL-C}{DOWN}{LEFT}{LEFT}{LEFT}{CTRL-Z}{CTRL-R}{CTRL-C}";:RETURN
20403 ? "{CTRL-Q}{CTRL-R}{CTRL-E}{DOWN}{LEFT}{LEFT}{LEFT} {CTRL-R}{CTRL-D}{DOWN}{LEFT}{LEFT}{LEFT}{CTRL-Z}{CTRL-R}{CTRL-C}";:RETURN
20404 ? "{CTRL-W} {DOWN}{LEFT}{LEFT}{LEFT}{CTRL-Z}{CTRL-R}{CTRL-S}{DOWN}{LEFT}{LEFT}{LEFT}  {CTRL-X} ";:RETURN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TRL-R}{DOWN}{LEFT}{LEFT}{LEFT}{CTRL-Z}{CTRL-R}{CTRL-C}";:RETURN

Download

The original program from the Antic disk, to LOAD or ENTER instead of typing it: MAZE3D.BAS.

Credits