A Stationary Guard
Place a guard on the map and detect when the player walks into them.
The building has walls. Now it has a guard. A red G stands in the corridor. Walk into the guard and you’re detected — alarm sounds, border flashes red.
The Program
10 BORDER 0: PAPER 0: INK 7: CLS
20 DIM m$(8, 16)
30 FOR i = 1 TO 8
40 READ m$(i)
50 NEXT i
60 REM draw map
70 FOR r = 1 TO 8
80 FOR c = 1 TO 16
90 IF m$(r)(c TO c) = "#" THEN PRINT AT r + 2, c + 2; INK 1; CHR$ 143
100 NEXT c
110 NEXT r
120 LET r = 6: LET c = 2
130 REM guard position
140 LET g = 3: LET h = 10
150 PRINT AT g + 2, h + 2; INK 2; "G"
160 REM game loop
170 PRINT AT r + 2, c + 2; INK 7; BRIGHT 1; "@"
180 LET k$ = INKEY$
190 IF k$ = "" THEN GO TO 180
200 LET u = r: LET z = c
210 IF k$ = "q" THEN LET u = r - 1
220 IF k$ = "a" THEN LET u = r + 1
230 IF k$ = "o" THEN LET z = c - 1
240 IF k$ = "p" THEN LET z = c + 1
250 IF u < 1 OR u > 8 OR z < 1 OR z > 16 THEN GO TO 170
260 IF m$(u)(z TO z) = "#" THEN GO TO 170
270 PRINT AT r + 2, c + 2; " "
280 LET r = u: LET c = z
290 REM check guard contact
300 IF r = g AND c = h THEN GO TO 400
310 GO TO 170
400 REM detected!
410 BEEP 0.1, 20: BEEP 0.1, 15: BEEP 0.2, 20
420 BORDER 2: PAUSE 10: BORDER 0
430 PRINT AT 12, 6; INK 2; BRIGHT 1; "DETECTED!"
440 STOP
500 DATA "################"
510 DATA "# #"
520 DATA "# ## #### # #"
530 DATA "# # # #"
540 DATA "# #### # #"
550 DATA "# # # #"
560 DATA "# ## # #"
570 DATA "################"
How It Works
Line 70 sets the guard’s position. g is the row, h is the column. The guard stands at row 3, column 10 — in the middle of the map.
Line 100 draws the guard as a red G with INK 2.
Line 200 checks for contact. After the player moves, IF r = g AND c = h compares the player’s position with the guard’s. If they match, the player walked right into the guard.
Lines 300-330 handle detection. BEEP 0.1, 20 then BEEP 0.1, 15 plays a descending two-tone alarm. BORDER 2 flashes the border red for a moment, then resets to black. “DETECTED!” appears on screen and the program stops.
Same-Cell Collision
This is the simplest form of enemy collision: two characters occupy the same grid cell. Compare positions. If both row and column match, they’ve collided.
It’s the same check used in Hot and Cold, Treasure Hunt, and every grid game. The difference is the consequence — in Night Patrol, detection means failure.
The Guard as Data
The guard’s position comes from variables, not hardcoded coordinates. Later, guard positions will come from DATA statements alongside the map. This means different floors can have guards in different positions, all loaded by the same code.
Try This
Move the guard. Change g and h to place the guard in a different corridor. Some positions are more dangerous than others — a guard at a chokepoint is harder to avoid than one in an open room.
Visual alarm. Add more BORDER flashes: BORDER 2: PAUSE 5: BORDER 0: PAUSE 5: BORDER 2: PAUSE 5: BORDER 0. The repeated flash feels more urgent.