Move a ball
Change a position repeatedly and make one character travel across the screen.
In Bright Spark, the program waits while the player chooses a response. In Volley, the ball keeps travelling while you decide where to put the paddle. We’ll begin with the smallest part of that change: one character moving without your help.
Use a 48K ZX Spectrum or an emulator set to that model. Start a new program;
we are not editing Bright Spark. Save anything you want to keep before using NEW.
The early versions use plain characters so we can see the movement rules. Later
we’ll give the court bold colours and improve the way we redraw it.
A position that changes
Enter this complete program, then RUN it:
10 BORDER 0: PAPER 0: INK 7: CLS
20 LET x=15: LET y=10: LET dx=1
30 PRINT AT 0,1;"VOLLEY"
100 PRINT AT y,x;"o"
110 PAUSE 2
120 PRINT AT y,x;" "
200 LET x=x+dx
210 IF x=30 THEN STOP
300 GO TO 100
BORDER 0, PAPER 0 and INK 7 choose a black border, black background and white
text. CLS clears the display using that background. A colon separates statements
on the same numbered line; BASIC carries them out from left to right.
LET stores a value. Here x is the ball’s column, y its row and dx the amount
to add to the column on each trip through the loop. PRINT AT takes row first,
column second, which is why the code says y,x. Rows increase downwards and
columns to the right. The quoted lowercase o is our ball.
The upper printing area has rows 0–21 and columns 0–31. We leave room around our movement area rather than sending the character all the way to an edge.
Draw, wait, erase, move
Line 100 draws at the current position. PAUSE 2 requests a short wait. Line 120
prints a space at the same position, removing the old ball. Line 200 then adds
dx to x: with dx=1, column 15 becomes 16. GO TO 100 sends execution back
to draw again. Changing x alone does not move a character already on screen;
the next PRINT makes the new position visible.
There is no request for player input in this loop. Once started, it continues
until the condition in line 210 is true. IF x=30 THEN STOP means stop when the
column reaches 30. It stops before drawing there, so the last ball drawn is
at column 29. That ball is erased before the intentional 9 STOP statement
report appears.
After drawing at column 15, where will the next three drawings be?
Show the explanation
Columns 16, 17 and 18, all on row 10. Each update adds one to x; nothing changes
y. The line numbers identify instructions, not screen positions.
Run it again. It starts at column 15 because line 20 assigns the starting values
each time. If you see a trail, check the space between the quotes in line 120
and that it prints at the old position before x changes. If it never stops,
compare the equality test and the one-cell step with the listing.
The ball may visibly blink. Keep this working version: we’ll return to the time
between erasing and redrawing once the game has rules worth preserving. PAUSE
can be shortened by a keypress, so it is not a promise of a fixed update rate.
Sources
Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming, second edition (Sinclair Research, 1983), chapters 2–3 (assignment, GO TO and conditions), chapter 15 (PRINT AT), and chapter 18 (PAUSE and movement).