Skip to content
Game 7 Unit 3 of 6 1 hr learning time

Walls That Stop You

An open screen lets the rover wander off the edge. Draw a maze of walls, then before each move, PEEK the cell the rover is about to enter — if it's a wall, cancel the step. The world pushes back, and a border wall keeps the rover in bounds for free.

50% of Rover

A rover that can drive off the screen — POKEing into memory it shouldn't — isn't in a world yet. Give it one: walls it can't pass, including a border that pens it in. The trick is to look before you leap — check what's in the next cell before moving there.

10 POKE 53281,0:PRINT CHR$(147)
20 GOSUB 500
30 R=4:C=5
40 POKE 1024+R*40+C,160:POKE 55296+R*40+C,7
50 J=PEEK(56320)
60 NR=R:NC=C
70 IF (J AND 1)=0 THEN NR=R-1
80 IF (J AND 2)=0 THEN NR=R+1
90 IF (J AND 4)=0 THEN NC=C-1
100 IF (J AND 8)=0 THEN NC=C+1
110 IF NR=R AND NC=C THEN 50
120 IF PEEK(1024+NR*40+NC)=160 THEN 50
130 POKE 1024+R*40+C,32
140 R=NR:C=NC
150 POKE 1024+R*40+C,160:POKE 55296+R*40+C,7
160 GOTO 50
500 FOR C=1 TO 38
510 POKE 1024+40+C,160:POKE 55296+40+C,1
520 POKE 1024+23*40+C,160:POKE 55296+23*40+C,1
530 NEXT C
540 FOR R=1 TO 23
550 POKE 1024+R*40+1,160:POKE 55296+R*40+1,1
560 POKE 1024+R*40+38,160:POKE 55296+R*40+38,1
570 NEXT R
580 FOR R=3 TO 12:POKE 1024+R*40+19,160:POKE 55296+R*40+19,1:NEXT R
590 FOR C=8 TO 30:POKE 1024+16*40+C,160:POKE 55296+16*40+C,1:NEXT C
600 RETURN
A C64 maze: a white border and inner walls on black, the yellow rover pressed against an inner wall.
The world pushes back: the rover drove right and stopped dead against the wall, unable to pass. The border does the same job at the screen's edge — no special edge code needed.

Two parts make this work. The maze is the routine at line 500: it POKEs a border of solid blocks around the playfield and a couple of inner walls into screen and colour RAM, all before the loop starts. The collision is the new line 120: IF PEEK(1024 + NR*40 + NC) = 160 THEN 60. Before committing a move, it reads back the screen code at the cell the rover is about to enter. If that cell holds a wall (character 160), the move is cancelled — GOTO 60 skips straight back to reading the stick, and the rover stays put.

This is look-ahead collision, and it's the core of the embedded idea: the world pushes back. Notice the border does double duty — because it's a wall, the same check that stops the rover at inner walls also stops it at the screen's edge, so there's no separate "am I off the screen?" code to write. Read the cell ahead, branch on what's there: that one pattern is how collision works on a memory-mapped screen.

Try this

  • Design your own maze. Lines 580–590 draw the inner walls. Add more FOR loops to POKE your own corridors and dead ends — the playfield is yours to shape.
  • Hear the bump. Add a short SID tone on the blocked branch (line 120) so hitting a wall sounds solid, not just unresponsive — the audio half of collision.

What's next

The rover roams a maze, but there's nothing to do in it. In Unit 4 pickups appear — and the same look-ahead PEEK that spots a wall now spots a prize and scores it.