Although we haven’t used the Sinclair/Timex to reproduce graphics from the Star Trek movies, we made some graphics from the TV series — the Tholean web. The main procedure demonstrates a good way to use BASIC (without machine code) to bounce, or ricochet, objects from side walls. This method is useful in writing many kinds of games — for example billiards.
Here’s the program:
5 LET P$="■" (the graphics space character)
10 LET X=0
20 LET Y=0
30 LET DX=1
40 LET DY=1
50 LET X1=21
60 LET Y1=31
70 LET X$="X >= 0 AND X <= X1" (>=, AND, and <= are tokens)
80 LET Y$="Y >= 0 AND Y <= Y1" (ditto)
90 LET Z$=X$+"AND"+Y$ (AND is a token)
99 REM MAIN PROCEDURE
100 LET X=X+DX
110 LET Y=Y+DY
120 IF VAL Z$ THEN GOTO 200
130 LET DX=DX*(2*VAL X$-1)
140 LET DY=DY*(2*VAL Y$-1)
150 LET X=X*VAL X$+X1*(X >= 0)* NOT VAL X$
160 LET Y=Y*VAL Y$+Y1*(Y >= 0)* NOT VAL Y$
170 REM OUTPUT FOLLOWS
200 PRINT AT X,Y; P$;
250 GOTO 100
Run the program in SLOW mode. Try changing the values in lines 5 through 60.
For fancy, three-dimensional looking images, change lines 120 and 200 to:
120 IF VAL Z$ THEN GOTO 180
200 PRINT AT X+I,Y; P$;
and add:
180 LET I=LEN P$
190 LET I=I-1
220 IF I > 0 THEN GOTO 190
Use various length graphics strings for P$. The string consisting of the graphics on 7, G, S, T, and 8 does nicely.
Try adding the following lines:
115 LET DX=DX+1.6
135 LET DX=DX+3.2
What happens? Hint: Think of line 115 as adding gravitational deceleration, and line 135 as adding inelastic bounces.
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.