Let the person walk across the empty lane. For this first inspection, one press makes one step, and holding the key does not repeat it.
Replace lines 1090.
Add lines 100, 200, 210, 220, 230, 250, 295, 296, 297, 298, 300, 310, 340, 341, 470, 480, 1110, 1120, 3100, 3110, 3120, 9000.
Delete lines 190. Enter each deleted line number alone.
100 LET steps=0
200 LET k$=INKEY$
210 IF k$="" THEN GO TO 200
220 IF k$="q" OR k$="Q" THEN GO TO 9000
230 IF k$="r" OR k$="R" THEN GO TO 100
250 LET dx=0: LET dy=0
295 IF k$="i" OR k$="I" THEN LET dy=-1
296 IF k$="k" OR k$="K" THEN LET dy=1
297 IF k$="j" OR k$="J" THEN LET dx=-1
298 IF k$="l" OR k$="L" THEN LET dx=1
300 LET nx=x+dx: LET ny=y+dy
310 IF nx<0 OR nx>14 OR ny<0 OR ny>2 THEN LET nx=x: LET ny=y
340 IF nx=x AND ny=y THEN GO TO 470
341 GO SUB 3100: LET x=nx: LET y=ny: GO SUB 3000: GO TO 470
470 IF INKEY$<>"" THEN GO TO 470
480 GO TO 200
1090 PRINT AT 20,2; PAPER 0; INK 7;"I up J left K down L right"
1110 PRINT AT 21,2; INK 7;"R retry Q quit";
1120 RETURN
3100 IF y=1 THEN PRINT AT 2+2*y,1+2*x; PAPER 0;" ";AT 3+2*y,1+2*x;" ": RETURN
3110 IF y=0 AND x=7 THEN PRINT AT 2,15; PAPER 4;" ";AT 3,15;" ": RETURN
3120 PRINT AT 2+2*y,1+2*x; PAPER 1; INK 5;g$;AT 3+2*y,1+2*x;g$: RETURN
9000 PAPER 0: INK 7: PRINT AT 21,0;"Finished. RUN to try again. ";: STOPRUN the changed program.
Complete source at this checkpoint
10 GO SUB 7000
100 LET steps=0
110 LET x=7: LET y=2
180 GO SUB 1000: GO SUB 3000
200 LET k$=INKEY$
210 IF k$="" THEN GO TO 200
220 IF k$="q" OR k$="Q" THEN GO TO 9000
230 IF k$="r" OR k$="R" THEN GO TO 100
250 LET dx=0: LET dy=0
295 IF k$="i" OR k$="I" THEN LET dy=-1
296 IF k$="k" OR k$="K" THEN LET dy=1
297 IF k$="j" OR k$="J" THEN LET dx=-1
298 IF k$="l" OR k$="L" THEN LET dx=1
300 LET nx=x+dx: LET ny=y+dy
310 IF nx<0 OR nx>14 OR ny<0 OR ny>2 THEN LET nx=x: LET ny=y
340 IF nx=x AND ny=y THEN GO TO 470
341 GO SUB 3100: LET x=nx: LET y=ny: GO SUB 3000: GO TO 470
470 IF INKEY$<>"" THEN GO TO 470
480 GO TO 200
1000 BORDER 0: PAPER 0: INK 7: CLS
1010 PRINT AT 0,1; INK 5;"QUICKSTEP";AT 0,21; INK 4;"EXIT ABOVE"
1030 FOR j=0 TO 2 STEP 2
1040 PRINT AT 2+2*j,1; PAPER 1; INK 5;s$;AT 3+2*j,1;s$
1060 NEXT j
1070 PRINT AT 2,15; PAPER 4; INK 7;" ";AT 3,15;" "
1090 PRINT AT 20,2; PAPER 0; INK 7;"I up J left K down L right"
1110 PRINT AT 21,2; INK 7;"R retry Q quit";
1120 RETURN
3000 LET shade=0: IF y<>1 THEN LET shade=1
3010 IF y=0 AND x=7 THEN LET shade=4
3020 PRINT AT 2+2*y,1+2*x; PAPER shade; INK 7;h$;AT 3+2*y,1+2*x;f$
3030 RETURN
3100 IF y=1 THEN PRINT AT 2+2*y,1+2*x; PAPER 0;" ";AT 3+2*y,1+2*x;" ": RETURN
3110 IF y=0 AND x=7 THEN PRINT AT 2,15; PAPER 4;" ";AT 3,15;" ": RETURN
3120 PRINT AT 2+2*y,1+2*x; PAPER 1; INK 5;g$;AT 3+2*y,1+2*x;g$: RETURN
7000 RESTORE 7280: FOR j=64 TO 103: READ n: POKE USR "a"+j,n: NEXT j
7010 LET h$=CHR$ 152 +CHR$ 153: LET f$=CHR$ 154 +CHR$ 155
7020 LET g$=CHR$ 156 +CHR$ 156: LET s$="": FOR j=1 TO 15: LET s$=s$+g$: NEXT j: RETURN
7280 DATA 0,7,15,13,15,7,3,31
7290 DATA 0,224,240,176,240,224,192,248
7300 DATA 63,55,7,7,6,6,14,0
7310 DATA 252,236,224,224,96,96,112,0
7320 DATA 0,0,0,0,0,16,0,0
9000 PAPER 0: INK 7: PRINT AT 21,0;"Finished. RUN to try again. ";: STOPUse I up, J left, K down and L right. Release between moves. R restores the starting board; Q stops the program. Reaching the exit does not win yet: we need to be able to walk away from it and inspect the drawing.
Ask for a key
INKEY$ supplies the current key as a string, or an empty string when no key is detected. Line 210 keeps asking while that string is empty. Lines 295–298 turn a recognised direction into a signed offset: left sets dx to −1, down sets dy to 1. All other movement begins with dx=0 and dy=0.
IF executes the rest of its line only when the condition is true; otherwise execution continues at the next numbered line. OR allows either of two conditions to match. The uppercase alternatives let either case work. At the end of a move, line 470 waits while a key remains held. Only after release does line 480 return to the next command. Without that gate, the same held key could be read again immediately.
R and Q are handled before the movement offsets. R returns to initialisation; Q prints a finishing message and stops. Enter RUN at the BASIC prompt to begin again.
Propose before accepting
The stored position is x/y. The proposed position is nx/ny. Line 300 adds the offsets without yet changing the player.
The board permits x=0..14 and y=0..2. If any of the four bounds fails, line 310 restores nx/ny to x/y. Line 340 then recognises that nothing changed and skips drawing. Trying to leave the board therefore keeps the player in its last valid cell.
The player is at (0,2). J proposes (−1,2). Which values should still be stored after the bounds check?
Show the explanation
x/y remain (0,2), and nx/ny are restored to (0,2). The invalid proposal must not become the stored position, even briefly: the drawing routine expects a cell on the board.
Put back what was underneath
An accepted move calls 3100 while x/y still describe the old cell. On the empty lane it prints two blank rows. On a dotted strip it restores g$. At the exit it restores the two green rows instead.
Only then does line 341 assign nx/ny to x/y and draw the person. The order is erase, accept, draw. If you change x/y first, the erase routine will clear the destination and leave the old person behind.
This is background restoration, not a collision test. The colours make the board readable; the coordinate comparisons decide whether a move is allowed.
Walk to every edge and press outwards once more. Then walk onto the exit, move sideways and return. The exit should remain marked and the person should leave no trail. If the exit turns into ordinary dotted ground, check line 3110 before changing the drawing routine. If a held direction repeats, check the release gate at 470.
Sources
Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming, second edition (Sinclair Research, 1983), [chapter 13, chapter 18. IF and conditions select the movement path; INKEY$ supplies keyboard input. Candidate positions and background restoration are rules of this program.
Run it here
This unit's program, built for you.
- Program
- quickstep.tap
- Machine
- ZX Spectrum 48K (PAL)