Move the paddle
Read controls while the ball keeps moving and keep a three-cell paddle inside the court.
The ball already moves without us. Now give the player a paddle they can move at the same time. Continue from Use the whole court after stopping the demonstration.
Add lines 25, 90, 105, 106, 125, 126, 130, 500, 510. Delete line 60.
25 LET p=9
90 GO SUB 500
105 LET k$=INKEY$
106 IF k$="q" THEN STOP
125 IF k$="a" THEN IF p>3 THEN PRINT AT p+2,2;" ": LET p=p-1
126 IF k$="z" THEN IF p<17 THEN PRINT AT p,2;" ": LET p=p+1
130 GO SUB 500
500 FOR r=p TO p+2: PRINT AT r,2;"I": NEXT r
510 RETURN
Keep every line not named in those editing instructions. Enter the whole set before running: the drawing routine belongs to this checkpoint too.
One position for a three-cell paddle
p is the paddle’s top row. With p=9, its three cells occupy rows 9, 10 and
11 in column 2. We can derive the bottom row as p+2; we do not need to store
three separate positions.
The routine at 500 draws those cells. GO SUB 500 runs it and remembers where to
come back. RETURN resumes just after the call. Line 90 draws the initial
paddle; line 130 redraws it during the moving loop. The ordinary loop jumps back
at line 300, so it does not fall into the routine by accident.
The left wall is removed, but the ball still returns automatically at column 3. This checkpoint demonstrates simultaneous movement and controls. The paddle will decide returns in the next lesson.
Ask without waiting
INKEY$ checks the keyboard without waiting for an answer. It gives a one-character
string for a recognised key, or an empty string, "", when there is none. We keep
that reading in k$ for this update. The dollar sign identifies a string variable.
If it is "a", move up when there is room; if it is "z", move down. Otherwise
those movement statements do nothing and the ball still advances. Hold A or Z
for continued movement. A brief tap between checks can be missed: this is polling,
not a queue of every keypress.
In line 125, the second IF is another condition that must be true. If either
condition fails, BASIC skips the remainder of that line. The colons after the
conditions do not start an unconditional part: the erase and assignment belong
to the successful branch.
Keep the whole paddle inside
At the top, p must not go below 3. At the bottom it must not exceed 17, because
rows 17, 18 and 19 already fill the final three available cells.
Why would allowing p to reach 19 be wrong?
Show the explanation
Only the top cell would be inside the court. The other cells would occupy rows 20 and 21, covering the lower wall and the message area. The limit must account for the object’s length, not just its stored coordinate.
Moving up first clears the old bottom cell at p+2, then subtracts one from p.
Moving down clears the old top cell, then adds one. The drawing routine fills
the paddle at its new position. For now it also redraws when we have not moved;
we’ll examine that extra work later.
Run it. Hold A until the paddle stops at the top, then Z until it stops at the
bottom. Release the keys: the paddle stays where it is while the ball continues.
Press Q to stop this version. If a paddle trail remains, check which old endpoint
is erased before changing p.
Complete program to keep
10 BORDER 0: PAPER 0: INK 7: CLS
20 LET x=15: LET y=10: LET dx=1: LET dy=1
25 LET p=9
30 PRINT AT 0,1;"VOLLEY"
40 FOR c=2 TO 30: PRINT AT 2,c;"-";AT 20,c;"-": NEXT c
50 FOR r=3 TO 19: PRINT AT r,30;"I": NEXT r
90 GO SUB 500
100 PRINT AT y,x;"o"
105 LET k$=INKEY$
106 IF k$="q" THEN STOP
110 PAUSE 2
120 PRINT AT y,x;" "
125 IF k$="a" THEN IF p>3 THEN PRINT AT p+2,2;" ": LET p=p-1
126 IF k$="z" THEN IF p<17 THEN PRINT AT p,2;" ": LET p=p+1
130 GO SUB 500
200 LET x=x+dx
210 IF x=29 THEN LET dx=-1
220 IF x=3 THEN LET dx=1
230 LET y=y+dy
240 IF y=19 THEN LET dy=-1
250 IF y=3 THEN LET dy=1
300 GO TO 100
500 FOR r=p TO p+2: PRINT AT r,2;"I": NEXT r
510 RETURN
Sources
Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming, second edition (Sinclair Research, 1983), chapter 5 (subroutines), chapter 8 (strings), and chapter 18 (INKEY$).