The Intruder
Place a player on the map and move with QAOP controls.
The building is drawn. Now someone needs to be inside it. The player appears as a bright @ symbol and moves one cell per keypress with QAOP controls.
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 game loop
140 PRINT AT r + 2, c + 2; INK 7; BRIGHT 1; "@"
150 LET k$ = INKEY$
160 IF k$ = "" THEN GO TO 150
170 PRINT AT r + 2, c + 2; " "
180 IF k$ = "q" AND r > 1 THEN LET r = r - 1
190 IF k$ = "a" AND r < 8 THEN LET r = r + 1
200 IF k$ = "o" AND c > 1 THEN LET c = c - 1
210 IF k$ = "p" AND c < 16 THEN LET c = c + 1
220 GO TO 140
500 DATA "################"
510 DATA "# #"
520 DATA "# ## #### # #"
530 DATA "# # # #"
540 DATA "# #### # #"
550 DATA "# # # #"
560 DATA "# ## # #"
570 DATA "################"
How It Works
Line 60 sets the player’s starting position. r is the row, c is the column. The player starts at row 6, column 2 — the bottom-left corridor.
Line 100 prints the player. INK 7; BRIGHT 1 makes a bright white @ that stands out against the dark floor. The + 2 offset matches the map’s offset.
Lines 130-170 read input. INKEY$ returns whatever key is held. If nothing is pressed, it returns an empty string and the loop continues. u and z hold the proposed new position — the player hasn’t moved yet.
Lines 140-170 calculate the new position based on which key was pressed. Q moves up (row - 1), A moves down (row + 1), O moves left (column - 1), P moves right (column + 1).
Lines 180-190 erase the old position (print a space) and update r and c to the new position. The next time through the loop, the player draws at the new spot.
Erase and Redraw
This is the same pattern from every previous game: print a space where the player was, update the position, let the loop draw the player at the new spot. The player appears to slide across the screen, one cell at a time.
Try This
Different character. Replace @ with O or CHR$ 2 (a smiley face). Which feels right for a stealth game?
Starting position. Change r and c to place the player in different parts of the map. Notice you can walk through walls — that’s the next unit.