Tuesday, April 15, 2025

Mystify

Let's start off with something simple. Here's a rather spartan clone of the old screen-saver called "Mystify."

We'll start with the CGA version:
10 REM Mystify - CGA version
11 RANDOMIZE TIMER
12 KEY OFF
15 SCREEN 1: CLS
20 DEFINT A-Z
30 MAXLINES = 11
40 DIM Lines(MAXLINES, 4)
50 startwidth = 10 + INT(RND * 40)
60 x1 = INT(RND * (320 - startwidth))
70 y1 = INT(RND * (200 - startwidth))
80 y2 = y1 + startwidth
90 x2 = x1 + startwidth
100 steps = 10
110 SWAP y1, y2
120 x1inc = 2 + INT(RND * steps)
130 y1inc = 2 + INT(RND * steps)
140 x2inc = 2 + INT(RND * steps)
150 y2inc = 2 + INT(RND * steps)
190 c = 1
300 akey$ = "a"
310 REM Make a new line
320 FOR l = (MAXLINES - 1) TO 1 STEP -1
330 FOR a = 0 TO 4
340 Lines(l + 1, a) = Lines(l, a)
350 NEXT a
360 NEXT l
370 Lines(1, 0) = x1: Lines(1, 1) = y1
380 Lines(1, 2) = x2: Lines(1, 3) = y2
390 Lines(1, 4) = c
400 LINE (Lines(MAXLINES, 0), Lines(MAXLINES, 1))-(Lines(MAXLINES, 2), Lines(MAXLINES, 3)), 0
410 FOR l = 1 TO MAXLINES - 1
420 LINE (Lines(l, 0), Lines(l, 1))-(Lines(l, 2), Lines(l, 3)), Lines(l, 4)
430 NEXT l
440 REM SOUND 0, 1
450 c = (c + 1) MOD 3 + 1 ' CGA color range ensured by MOD operator
460 x1 = x1 + x1inc
470 y1 = y1 + y1inc
480 x2 = x2 + x2inc
490 y2 = y2 + y2inc
500 IF x1 < 0 THEN x1inc = -x1inc: x1 = 0
510 IF x1 > 319 THEN x1inc = -x1inc: x1 = 319
520 IF y1 < 0 THEN y1inc = -y1inc: y1 = 0
530 IF y1 > 199 THEN y1inc = -y1inc: y1 = 199
540 IF x2 < 0 THEN x2inc = -x2inc: x2 = 0
550 IF x2 > 319 THEN x2inc = -x2inc: x2 = 319
560 IF y2 < 0 THEN y2inc = -y2inc: y2 = 0
570 IF y2 > 199 THEN y2inc = -y2inc: y2 = 199
580 akey$ = INKEY$
590 IF akey$ <> CHR$(27) THEN 300
600 SCREEN 0: WIDTH 80
610 CLS
620 PRINT "Good-bye!"
630 END
And now for a the EGA version:
10 REM Mystify - EGA version
11 RANDOMIZE TIMER
12 KEY OFF
15 SCREEN 7, , 1, 0: CLS
20 DEFINT A-Z
30 MAXLINES = 16
40 DIM Lines(MAXLINES, 4)
50 startwidth = 10 + INT(RND * 40)
60 x1 = INT(RND * (319 - startwidth))
70 y1 = INT(RND * (199 - startwidth))
80 y2 = y1 + startwidth
90 x2 = x1 + startwidth
100 steps = 5
110 SWAP y1, y2
120 x1inc = 2 + INT(RND * steps)
130 y1inc = 2 + INT(RND * steps)
140 x2inc = 2 + INT(RND * steps)
150 y2inc = 2 + INT(RND * steps)
170 c1 = 1: c = c1
180 cinc = 1
190 turns = 0
300 akey$ = "a"
310 REM Make a new line
320 FOR l = (MAXLINES - 1) TO 1 STEP -1
330 FOR a = 0 TO 4: Lines(l + 1, a) = Lines(l, a): NEXT a
340 NEXT l
350 Lines(1, 0) = x1: Lines(1, 1) = y1
360 Lines(1, 2) = x2: Lines(1, 3) = y2
370 Lines(1, 4) = c
400 PCOPY 1, 0
410 CLS 1
420 FOR l = 1 TO MAXLINES
430 LINE (Lines(l, 0), Lines(l, 1))-(Lines(l, 2), Lines(l, 3)), (Lines(l, 4) + l) MOD 16
440 NEXT l
450 REM SOUND 0, 1
460 turns = turns + 1
470 chgcol = (turns MOD 2) = 0
480 IF chgcol THEN c = c + cinc: IF (c = 15 OR c = c1) THEN cinc = -cinc
490 x1 = x1 + x1inc: y1 = y1 + y1inc: x2 = x2 + x2inc: y2 = y2 + y2inc
500 IF x1 < 0 THEN x1inc = -x1inc: x1 = 0
510 IF x1 > 319 THEN x1inc = -x1inc: x1 = 319
520 IF y1 < 0 THEN y1inc = -y1inc: y1 = 0
530 IF y1 > 199 THEN y1inc = -y1inc: y1 = 199
540 IF x2 < 0 THEN x2inc = -x2inc: x2 = 0
550 IF x2 > 319 THEN x2inc = -x2inc: x2 = 319
560 IF y2 < 0 THEN y2inc = -y2inc: y2 = 0
570 IF y2 > 199 THEN y2inc = -y2inc: y2 = 199
580 akey$ = INKEY$
590 IF akey$ <> CHR$(27) THEN 300
600 SCREEN 0: WIDTH 80
610 CLS
620 PRINT "Good-bye!"
630 END
And there you have it. Pretty horrible, ey?

No comments:

Post a Comment

Maze generator in GW-BASIC

 A while back I was looking at maze making algorithms written in Basic. I was not very happy with any of the ones I could find at the time, ...