maze/maze.baz
Bill Chatfield 130b5f2a32 Created disk
2021-02-15 01:57:20 -05:00

97 lines
2.1 KiB
Plaintext

rem
REM cxxxxxx|/////////////////////////>
REM
REM MAZE - DRAWS A MAZE-LIKE PATTERN
REM AUTHOR - BILL CHATFIELD
REM
REM cxxxxxx|/////////////////////////>
rem
REM //////////////
REM Init
REM //////////////
let d$ = chr$(4)
let ret$ = chr$(13)
let esc$ = chr$(27)
LET SW = 140 : SH = 192: REM SCREEN WIDTH AND HEIGHT
LET KBD = -16384: REM Addr of byte that is neg if key pressed
LET RL = 78 : RH = 79: REM RNDL AND RNDH
LET SEED = PEEK (RL) + PEEK (RH) * 256: REM GET RND SEED
LET NA = RND ( - SEED): REM SEED RANDOM NUM GENERATOR
HOME
print d$;"-dhgr" : rem Load Double Hi-res driver
& HGR2 : REM FULL SCREEN DOUBLE HIGH RES
& MODE(2) : REM 16-color mode
REM //////////////////////////
REM Draw Screen
REM //////////////////////////
£drawScreen
let BG = 0: rem Black
let fg = int(rnd(1) * 15) + 1: rem Gives 1 to 15
& BCOLOR=BG
& CLEAR : REM Draw background
& HCOLOR=FG
let s = int(rnd(1) * 5) + 4: REM Gives 4 to 8
let W = s
let H = s
PRINT "W=";W;" H=";H;" FG=";FG;" BG=";BG
REM ///////////////////////////
REM Draw Segment
REM ///////////////////////////
£drawSegments
let mx = (int(sw / w) - 1) * w
let my = (int(sh / h) - 1) * h
for y1 = 0 to my step h
let y2 = y1 + h - 1
for x1 = 0 to mx step w
if peek(kbd) > 127 then gosub @checkKeypress
let x2 = x1 + w - 1
let T = INT(RND(1) * 2): REM Segment type
gosub @drawSegment
next x1
if x1 >= sw then @skipShortSegment
let x2 = sw - 1
let dy = int((x2 - x1 + 1) * h / w) - 1
let t = int(rnd(1) * 2): REM Segment type
let yb = y1: rem Backup y1
if t = 0 then y1 = y2 - dy
if t = 1 then y2 = y1 + dy
gosub @drawSegment
let y1 = yb: rem Restore y1
£skipShortSegment
next y1
GOTO @drawScreen
£drawSegment
IF T = 0 THEN & HPLOT X1,Y2 TO X2,Y1
IF T = 1 THEN & HPLOT X1,Y1 TO X2,Y2
return
REM //////////////////////////
REM KEY HANDLER
REM //////////////////////////
£checkKeypress
get KEY$
if key$ = " " then pop : goto @drawScreen
if key$ = esc$ then pop : goto @exit
if key$ = ret$ then pop : goto @drawScreen
return
rem ////////////////
rem Exit
rem ////////////////
£exit
& TEXT
print "Maze terminated."
print "Run -FP before running Maze again to clear memory";
END