Skip to content
Game 10 Unit 13 of 16 1 hr learning time

Sightline Polish

Bring sightlines back into the multi-floor game and clean up erasure around objectives.

81% of Night Patrol

The floors work, but the guard walks blindly — no sightline. Time to bring sightlines back and handle a new problem: what happens when the sightline sweeps over the objective or exit?

The Program

10 BORDER 0: PAPER 0: INK 7: CLS
20 DIM m$(8, 16)
30 LET v = 3: LET e = 0: LET l = 1
40 RESTORE 900
50 REM load floor
60 FOR i = 1 TO 8
70 READ m$(i)
80 NEXT i
90 READ r, c, g, h, d$, o, p, w, x
100 LET q = 1: LET t = 0: LET s = 20 - l * 3: LET f$ = d$(1 TO 1)
110 LET j = 0
120 CLS
130 GO SUB 800
135 PRINT AT o + 2, p + 2; INK 6; "*"
136 PRINT AT w + 2, x + 2; INK 1; "X"
140 GO SUB 870
150 REM game loop
155 GO SUB 700
160 PRINT AT r + 2, c + 2; INK 7; BRIGHT 1; "@"
170 PRINT AT g + 2, h + 2; INK 2; "G"
180 LET t = t + 1
190 LET k$ = INKEY$
200 IF k$ = "" THEN GO TO 240
210 LET u = r: LET i = c
212 IF k$ = "q" THEN LET u = r - 1
214 IF k$ = "a" THEN LET u = r + 1
216 IF k$ = "o" THEN LET i = c - 1
218 IF k$ = "p" THEN LET i = c + 1
220 IF u < 1 OR u > 8 OR i < 1 OR i > 16 THEN GO TO 240
222 IF m$(u)(i TO i) = "#" THEN GO TO 240
224 PRINT AT r + 2, c + 2; " "
226 LET r = u: LET c = i
228 IF r = o AND c = p AND j = 0 THEN LET j = 1: BEEP 0.1, 20: PRINT AT w + 2, x + 2; INK 4; "X": GO SUB 870
230 IF r = w AND c = x AND j = 1 THEN GO TO 550
240 IF t < s THEN GO TO 320
250 LET t = 0
255 GO SUB 760
260 PRINT AT g + 2, h + 2; " "
270 LET f$ = d$(q TO q)
280 IF f$ = "N" THEN LET g = g - 1
290 IF f$ = "S" THEN LET g = g + 1
300 IF f$ = "W" THEN LET h = h - 1
310 IF f$ = "E" THEN LET h = h + 1
315 LET q = q + 1: IF q > LEN d$ THEN LET q = 1
320 IF r = g AND c = h THEN GO TO 400
330 GO TO 150
400 REM detected
410 LET v = v - 1
420 BEEP 0.1, 20: BEEP 0.1, 15
430 BORDER 2: PAUSE 10: BORDER 0
440 IF v = 0 THEN GO TO 500
450 GO SUB 760
460 PRINT AT g + 2, h + 2; " "
470 PRINT AT r + 2, c + 2; " "
480 RESTORE: FOR i = 1 TO (l - 1) * 9 + 8: READ a$: NEXT i: READ r, c, g, h, d$, o, p, w, x
490 LET q = 1: LET f$ = d$(1 TO 1): LET t = 0
495 GO SUB 870: GO TO 150
500 CLS
510 PRINT AT 8, 9; INK 2; "GAME OVER"
520 PRINT AT 10, 8; "Score: "; e
525 PRINT AT 11, 8; "Floor: "; l
530 BEEP 0.15, 0: BEEP 0.15, -3: BEEP 0.2, -7
540 STOP
550 REM floor complete
560 LET e = e + 10 * l
565 GO SUB 760
570 BEEP 0.15, 12: BEEP 0.15, 16: BEEP 0.3, 19
580 PRINT AT 12, 5; INK 4; "FLOOR "; l; " COMPLETE!"
590 PAUSE 50
600 LET l = l + 1
610 IF l > 3 THEN GO TO 650
620 GO TO 60
650 REM victory
660 CLS
670 PRINT AT 8, 8; INK 4; "YOU ESCAPED!"
680 PRINT AT 10, 8; "Score: "; e
690 BEEP 0.15, 12: BEEP 0.15, 16: BEEP 0.15, 19: BEEP 0.3, 24
695 STOP
700 REM === draw sightline ===
710 LET a = g: LET b = h
720 IF f$ = "N" THEN LET a = a - 1
722 IF f$ = "S" THEN LET a = a + 1
724 IF f$ = "W" THEN LET b = b - 1
726 IF f$ = "E" THEN LET b = b + 1
728 IF a < 1 OR a > 8 OR b < 1 OR b > 16 THEN RETURN
730 IF m$(a)(b TO b) = "#" THEN RETURN
732 IF a = r AND b = c THEN GO TO 400
734 PRINT AT a + 2, b + 2; INK 6; "."
736 GO TO 720
760 REM === clear sightline ===
770 LET a = g: LET b = h
772 IF f$ = "N" THEN LET a = a - 1
774 IF f$ = "S" THEN LET a = a + 1
776 IF f$ = "W" THEN LET b = b - 1
778 IF f$ = "E" THEN LET b = b + 1
780 IF a < 1 OR a > 8 OR b < 1 OR b > 16 THEN RETURN
782 IF m$(a)(b TO b) = "#" THEN RETURN
784 IF a = o AND b = p AND j = 0 THEN PRINT AT a + 2, b + 2; INK 6; "*": GO TO 772
786 IF a = w AND b = x THEN PRINT AT a + 2, b + 2; INK 4; "X": GO TO 772
788 PRINT AT a + 2, b + 2; " "
790 GO TO 772
800 REM === draw map ===
810 FOR y = 1 TO 8
820 FOR x = 1 TO 16
830 IF m$(y)(x TO x) = "#" THEN PRINT AT y + 2, x + 2; INK 1; CHR$ 143
840 NEXT x
850 NEXT y
860 RETURN
870 REM === draw HUD ===
880 PRINT AT 0, 0; INK 7; "Lives:"; v; " Score:"; e; " Floor:"; l; "  "
885 IF j = 0 THEN PRINT AT 1, 0; INK 6; "Find * then reach X "
886 IF j = 1 THEN PRINT AT 1, 0; INK 4; "Go to X exit!       "
890 RETURN
900 REM floor 1
910 DATA "################"
920 DATA "#              #"
930 DATA "#  ## ####  #  #"
940 DATA "#     #     #  #"
950 DATA "#  ####  #     #"
960 DATA "#        #  #  #"
970 DATA "#   ##      #  #"
980 DATA "################"
990 DATA 6,2,3,10,"WWWWWWEEEEEE",2,14,6,15
1000 REM floor 2
1010 DATA "################"
1020 DATA "#   #     #    #"
1030 DATA "#   #  ## # #  #"
1040 DATA "#   #     #    #"
1050 DATA "### #####  #   #"
1060 DATA "#          #   #"
1070 DATA "#   # #     #  #"
1080 DATA "################"
1090 DATA 6,2,3,5,"SSSSNNNN",2,14,6,15
1100 REM floor 3
1110 DATA "################"
1120 DATA "#       #      #"
1130 DATA "# ####  # ###  #"
1140 DATA "#       #      #"
1150 DATA "# ##### # ###  #"
1160 DATA "#              #"
1170 DATA "#  # #   # #   #"
1180 DATA "################"
1190 DATA 6,2,2,3,"EEEEEEEWWWWWWW",2,14,6,15

How It Works

Lines 700-736 draw the sightline, same as unit 8. Step from the guard in its facing direction, drawing yellow dots until hitting a wall, the edge, or the player.

Lines 760-790 clear the sightline — but with new logic. The original clear routine printed spaces everywhere. That erased the objective and exit if the sightline passed over them.

Lines 784-786 fix this. Before printing a space, check: is this cell the objective? Is it the exit? If so, redraw the objective or exit instead of blanking it. IF a = o AND b = p AND j = 0 redraws the uncollected objective. IF a = w AND b = x redraws the exit.

Line 155 draws the sightline at the top of the game loop, before the player and guard are drawn. This layering means the player and guard always appear on top of sightline dots.

Line 255 clears the sightline before the guard moves and changes direction.

Line 565 clears the sightline before showing the floor-complete message, preventing stale dots from lingering.

Preserving Game Objects

When you erase something from the screen, you might accidentally erase something else that occupies the same cell. The sightline clear routine needs to know about every game object that might be on the map.

This is a common problem in character-cell games. The screen doesn’t track layers — printing a space removes whatever was there. The code must restore the correct character manually.

Clean Transitions

The sightline is cleared before floor completion (line 565) and before detection reset (line 405 in the next unit). Each state transition needs to clean up the previous state’s visual elements.

Try This

Coloured sightlines. Change the sightline colour from yellow (INK 6) to red (INK 2). Does it make the danger feel more immediate?

Watch the sweep. Move the player near the guard’s path and watch the sightline sweep past. The dots appear, the guard turns, the old dots vanish, new dots appear in the new direction. The cleanup is invisible when it works properly.