The paddle can move, but the ball passes it without noticing. We will now check whether their horizontal spans overlap as the ball crosses the paddle’s catching plane.
Only four lines change or are added.
Replace lines 300, 390.
Add lines 400, 410.
300 IF k$=" " THEN LET served=1: PRINT AT 1,2;"Keep the ball in play. ": GO TO 350
390 IF ny>=32 THEN GO TO 490
400 IF nx+1 <8 *p OR nx>8 *p+31 THEN LET e$="Missed! R for another go.": GO TO 4000
410 LET ny=64 -ny: LET dy=4RUN the changed program.
Complete source at this checkpoint
10 GO SUB 7000
100 LET p=14: LET x=127: LET y=40
110 LET dx=4: LET dy=4: LET served=0: LET steps=0
130 GO SUB 1000: GO SUB 3000
200 LET k$=INKEY$
210 IF k$="q" OR k$="Q" THEN GO TO 9000
220 IF k$="r" OR k$="R" THEN GO TO 100
230 LET oldp=p
240 IF k$="o" OR k$="O" THEN LET p=p-1
250 IF k$="p" OR k$="P" THEN LET p=p+1
260 IF p<2 THEN LET p=2
270 IF p>26 THEN LET p=26
280 IF p<>oldp THEN PRINT AT 18,oldp;" ";AT 18,p; INK 7;p$
290 IF served=1 THEN GO TO 350
300 IF k$=" " THEN LET served=1: PRINT AT 1,2;"Keep the ball in play. ": GO TO 350
310 IF p=oldp THEN GO TO 200
320 GO SUB 3000: LET x=8 *p+15: GO SUB 3000: GO TO 200
350 LET nx=x+dx: LET ny=y+dy
360 IF nx<16 THEN LET nx=32 -nx: LET dx=ABS dx
370 IF nx>238 THEN LET nx=476 -nx: LET dx=-ABS dx
380 IF ny>149 THEN LET ny=298 -ny: LET dy=-ABS dy
390 IF ny>=32 THEN GO TO 490
400 IF nx+1 <8 *p OR nx>8 *p+31 THEN LET e$="Missed! R for another go.": GO TO 4000
410 LET ny=64 -ny: LET dy=4
490 GO SUB 3000
500 LET x=nx: LET y=ny: LET steps=steps+1
510 GO SUB 3000: GO TO 200
1000 BORDER 0: PAPER 0: INK 7: CLS
1010 PRINT AT 0,2; INK 5;"BRICK BASH"
1020 PRINT AT 1,2;"SPACE serves. O/P move."
1030 PLOT INK 1;15,16: DRAW INK 1;0,136: DRAW INK 1;225,0: DRAW INK 1;0,-136
1080 PRINT AT 18,p; INK 7;p$
1090 PRINT AT 21,2; INK 5;"O/P move R retry Q quit";
1100 RETURN
3000 PLOT INK 7; OVER 1;x,y: DRAW INK 7; OVER 1;1,0: DRAW INK 7; OVER 1;0,1: DRAW INK 7; OVER 1;-1,0: RETURN
4000 PRINT AT 1,0;" ";AT 1,2; INK 6;e$
4010 PRINT AT 21,2; INK 7;"R plays again Q quits ";
4020 IF INKEY$<>"" THEN GO TO 4020
4030 LET k$=INKEY$
4040 IF k$="q" OR k$="Q" THEN GO TO 9000
4050 IF k$="r" OR k$="R" THEN GO TO 100
4060 GO TO 4030
7000 RESTORE 7230: FOR j=24 TO 47: READ v: POKE USR "a"+j,v: NEXT j
7020 LET p$=CHR$ 147 +CHR$ 148 +CHR$ 148 +CHR$ 149: RETURN
7230 DATA 63,127,127,63,0,0,0,0
7240 DATA 255,255,255,255,0,0,0,0
7250 DATA 252,254,254,252,0,0,0,0
9000 PAPER 0: INK 7: PRINT AT 21,0;"Finished. RUN to try again. ";: STOPCatching a two-pixel ball
A candidate ball spans nx to nx+1. The paddle spans 8p to 8p+31. They are separated if the ball’s rightmost pixel is left of the paddle, or the ball’s leftmost pixel is right of it.
Those are the two failure tests in line 400. OR means either separation is enough for a miss. Equality is a catch: one shared pixel counts.
With the paddle at p=14, its span is 112–143:
| Candidate ball x | Ball span | Result |
|---|---|---|
| 110 | 110–111 | Miss: no shared pixel |
| 111 | 111–112 | Catch at the left edge |
| 143 | 143–144 | Catch at the right edge |
| 144 | 144–145 | Miss: no shared pixel |
These are coordinate examples. The moving program reaches only some integer positions with its four-pixel steps, but the overlap rule is defined for all of them.
Turn down into up
Line 390 skips the paddle test while ny is at least 32. Once ny is below 32, a catch reflects that candidate around y=32: ny=64-ny. For example, ny=28 becomes 36. Then dy becomes 4, sending the ball upwards.
We are using a catching plane just above the artwork, not asking which coloured pixels are underneath the ball. This keeps the rule independent of the rounded corners and the character-cell colour attributes.
Horizontal direction is unchanged for now. If the ball arrived moving right, it leaves moving right. Later we will use the contact position to aim.
A miss leaves a valid picture
A failed overlap sets the result message and jumps away before erasing or committing the proposed ball. x and y still describe the last safe position. Retry returns to the same initialisation used at the start: centred paddle, waiting ball and upward-right direction.
Would checking only nx against the paddle miss a legal catch at its left edge?
Show the explanation
Yes. At nx=111, the ball’s left pixel is outside a paddle beginning at 112, but its right pixel is 112. The ball overlaps by one pixel, so nx+1 must take part in the test.
RUN and keep the ball in play for several returns. Then deliberately move away and miss. Hold a direction while the result appears, release it, and press R. Check that SPACE is needed to serve again; Q should leave from both ready and result screens.
If a catch passes through, inspect both span comparisons and the jump in line 390. If the ball travels downwards after a catch, check the positive dy in line 410. Changing a paddle’s colour should not change any of these decisions.
Sources
Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming, second edition (Sinclair Research, 1983), chapters 3 and 17–18. The court dimensions, collision rules and artwork are choices made for this game.
Run it here
This unit's program, built for you.
- Program
- brick-bash.tap
- Machine
- ZX Spectrum 48K (PAL)