Targets
A crate on a target is a fifth cell state with its own colour and behaviour — and the puzzle is won when no bare target is left.
Pushing works; now it needs a point. Targets are the goal cells, and a crate pushed onto one becomes a new combined state — which means the grid must track crate-on-target separately, and the player must remember what they are standing on. When no bare target remains, the puzzle is solved.
90 RESTORE 900
100 READ w, h
120 LET sr = INT ((22 - h) / 2) + 1
130 LET sc = INT ((32 - w) / 2)
140 LET ps = 0
150 DIM g(h, w)
160 CLS
170 PRINT AT 0, 10; "*** CRATES ***"
200 FOR r = 1 TO h
210 READ r$
220 FOR c = 1 TO w
230 LET q$ = r$(c TO c)
240 IF q$ = "W" THEN LET g(r,c) = 1: PRINT AT sr+r-1, sc+c-1; PAPER 1; INK 0; " "
250 IF q$ = " " THEN PRINT AT sr+r-1, sc+c-1; PAPER 7; INK 0; " "
260 IF q$ = "." THEN LET g(r,c) = 2: PRINT AT sr+r-1, sc+c-1; PAPER 2; INK 0; " "
270 IF q$ = "C" THEN LET g(r,c) = 3: PRINT AT sr+r-1, sc+c-1; PAPER 6; INK 0; " "
280 IF q$ = "P" THEN LET pr = r: LET pc = c: PRINT AT sr+r-1, sc+c-1; PAPER 7; INK 4; "P"
290 NEXT c
300 NEXT r
320 IF INKEY$ <> "" THEN GO TO 320
330 LET k$ = INKEY$: IF k$ = "" THEN GO TO 330
350 LET dy = 0: LET dx = 0
360 IF k$ = "i" OR k$ = "I" THEN LET dy = -1
370 IF k$ = "k" OR k$ = "K" THEN LET dy = 1
380 IF k$ = "j" OR k$ = "J" THEN LET dx = -1
390 IF k$ = "l" OR k$ = "L" THEN LET dx = 1
400 IF dy = 0 AND dx = 0 THEN GO TO 320
410 LET nr = pr + dy: LET nc = pc + dx
420 LET v = g(nr, nc)
430 IF v = 1 THEN GO TO 320
440 IF v = 3 OR v = 4 THEN GO TO 510
450 IF v <> 0 AND v <> 2 THEN GO TO 320
460 PRINT AT sr+pr-1, sc+pc-1; PAPER (7-ps*5); INK 0; " "
470 LET ps = 0: IF v = 2 THEN LET ps = 1
480 LET pr = nr: LET pc = nc
490 PRINT AT sr+pr-1, sc+pc-1; PAPER (7-ps*5); INK 4; "P"
500 GO TO 320
510 REM --- Push crate ---
520 LET br = nr + dy: LET bc = nc + dx
530 LET bv = g(br, bc)
540 IF bv <> 0 AND bv <> 2 THEN GO TO 320
550 IF bv = 0 THEN LET g(br,bc) = 3: PRINT AT sr+br-1, sc+bc-1; PAPER 6; INK 0; " "
560 IF bv = 2 THEN LET g(br,bc) = 4: PRINT AT sr+br-1, sc+bc-1; PAPER 4; INK 0; " "
570 PRINT AT sr+pr-1, sc+pc-1; PAPER (7-ps*5); INK 0; " "
580 LET ps = 0: IF v = 4 THEN LET ps = 1
590 IF v = 3 THEN LET g(nr,nc) = 0
600 IF v = 4 THEN LET g(nr,nc) = 2
610 LET pr = nr: LET pc = nc
620 PRINT AT sr+pr-1, sc+pc-1; PAPER (7-ps*5); INK 4; "P"
650 REM --- All targets covered? ---
660 LET win = 1
670 FOR r = 1 TO h
680 FOR c = 1 TO w
690 IF g(r, c) = 2 THEN LET win = 0
700 NEXT c
710 NEXT r
720 IF win = 0 THEN GO TO 320
730 PRINT AT 20, 4; "Level complete!"
740 PAUSE 0: STOP
900 DATA 5,5
901 DATA "WWWWW"
902 DATA "W . W"
903 DATA "W C W"
904 DATA "W P W"
905 DATA "WWWWW"
Five states in one grid
The array now holds 0 floor, 1 wall, 2 target, 3 crate and 4 crate-on-target. State 4 is
the interesting one: a crate on a target is not "a crate and a target together" but a single value with
its own green PAPER and its own behaviour. The push routine grows to match — lines 550–560 land a
crate as 3 on floor or 4 on a target, and lines 590–600 leave behind 0 or 2 depending on what
it sat on. Encoding the combination as one number keeps the array the single source of truth, the same
multi-meaning-per-cell idea you used in Sonar, taken one step further.
Remembering the floor underneath
The player can now stand on a target, so line 140 adds ps — what the player is standing on, 0 or
1. When the player moves off, the cell must be repainted the right colour, and PAPER (7 - ps*5)
does it without an IF: ps = 0 gives PAPER 7 (white floor), ps = 1 gives PAPER 2 (red target).
One expression, two colours, used everywhere the player is drawn or erased.
Knowing when it is solved
Winning is a sweep of the grid (lines 660–720): assume win = 1, then scan every cell, and any bare
target still showing (g(r,c) = 2) sets win = 0. If none remain, every target has a crate on it and
the level is complete. It is the same whole-grid scan Sonar used to find targets and The Caverns used
to reveal the cave — here it asks one question of the finished board: is anything left uncovered?
The puzzle is complete. The last unit turns one room into a game of three.