ZX Computings - OpenLibra
ZX Computings - OpenLibra
ZX Computings - OpenLibra
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Moving graphics<br />
Getting into<br />
the Movies<br />
What do you do when you want<br />
aliens and asteriods to burn<br />
around your TV screen? The<br />
PRINT AT on the <strong>ZX</strong>81 gives you<br />
one solution.<br />
You make an object move — or<br />
appear to move — on the TV<br />
screen by printing it in one position,<br />
holding the display for a<br />
moment, then unprinting the<br />
old position just as you reprint<br />
in a new position.<br />
The PRINT AT function on<br />
the <strong>ZX</strong>81, although it is slow,<br />
makes it easy to position an object<br />
just where you want it. For<br />
our first simple program, enter<br />
PROGRAM ONE and press RUN<br />
to see it in action. What you'll<br />
see, all being well, is a black<br />
square move down the screen<br />
diagonally. Note that you can<br />
'chain' PRINT AT commands as<br />
in line 30.<br />
This program shows the<br />
simplest kind of moving<br />
graphics programming, and<br />
although far from satisfactory<br />
in terms of the result displayed<br />
on the screen, at least it should<br />
give you a clear idea of how to<br />
produce one kind of effect. Its<br />
main disadvantage is that the<br />
screen is blank while the computer<br />
is working out the new<br />
PRINT AT position for the black<br />
blob. As you can see from running<br />
this program, the RND function<br />
— when running the computer<br />
in SLOW — is particularly<br />
slow. As you begin to elaborate<br />
the program you're working on,<br />
and you want the computer to<br />
do more and more, you'll find<br />
this blank between subsequent<br />
PRINT ATs of the blob becomes<br />
intolerable. Try, for example,<br />
adding 35 LET Z = X' "Y and<br />
see how slow the program<br />
becomes. This can be overcome<br />
to some extent by assigning<br />
two other variables to the<br />
PRINT AT position which hold it<br />
for unprinting while the computer<br />
is working out new positions.<br />
Change the program so it<br />
reads as the listing for program<br />
two. Run this, and you'll see<br />
how much more satisfactory it<br />
is. If you want it to run forever,<br />
add 57 IF X greater than 19<br />
THEN RUN.<br />
Now moving a blob down<br />
the screen in an irregular slide is<br />
not of much use to anyone.<br />
Enter and run program number<br />
three, which makes a ball<br />
bounce around the screen.<br />
Although this does not use a second<br />
set of variables to unprint,<br />
it is fairly satisfactory. You'll<br />
see that lines 70 and 80 check<br />
each time through the program<br />
to ensure that the ball has not<br />
'hit the sides', and if it has done<br />
so, ensures that the variables<br />
which determine the next position<br />
of the ball (C and D) are<br />
changed.<br />
Program four does use new<br />
variables (E and F) to hold the<br />
5 REM *MOUING GRAPHICS 5 REM *HOMING GRAPHIC<br />
PROGRAM ONE* PROGRAM TWO*<br />
1® LET X = © 1 0 LET X=0<br />
L.ET Y=0 20 LET Y=0<br />
3 0 PRINT AT X..Y; ' AT X , Y ;<br />
*• *<br />
25 LET A =X<br />
LET XsXfRND 27 L ET B =Y<br />
5 0 LET Y=YfRND 3 0 PRINT AT X/Y;"B"<br />
50 GOTO 30 4 0 LET X-X +RHD<br />
5 0 LET Y=Y+RND<br />
5 5 PRINT AT A,, 8; " "<br />
60 GOTO 25<br />
• Program one • Program two<br />
20 LET A=UFiL "10*RND + 5<br />
30 L E T B='vhL " A ^ R N D + S "<br />
10 REM *BOUNCING BRLL -• • 1 * 40 LET' - A<br />
LEI A = 10*RNL>+5 45 LPT G-C +C<br />
3 0 LET 6-P*RND+5 50 LFT D =C<br />
4.0 L t£T C = 1 55 L^T E=R<br />
5 3 LET D=1 56 L. fiT F s=B<br />
5 0 PRINT f*T P . B; 0<br />
60 PRINT RT R,B,"0'<br />
7 0 Ir A 19 THEN LET C = - 70 IF R 19 THEN<br />
3 0 IF 829 THEN LET D=- 60 IF B < G OR B>29 THEN<br />
3 5 P R I N T RT A.. B.: " "<br />
90 LET A = A 4-C<br />
9 0 LET R=R*C 100 LET B=B+D<br />
1 0 0 LET S = B + D 105 PRINT AT E F; ". "<br />
1 10 GOTO 50 110 GOTO UAL "SS"<br />
Program three Program four<br />
o<br />
old position while the new one<br />
is being worked out, and these<br />
are used not as an 'unprint' but<br />
rather to print a trailing series of<br />
full stops, as you can see in<br />
diagram one. Run these programs<br />
a few times, and examine<br />
the listings, and you're<br />
sure to be able to work out<br />
ways to make them more effective.<br />
A second way of approaching<br />
the moving graphics problem<br />
is to use SCROLL to move<br />
the screen up a line, before<br />
reprinting what you need on the<br />
line it has just left. Enter and run<br />
program five, HAILSTORM,<br />
and you'll see how it works in<br />
practice. In this program, you<br />
are the black block, PRINT ATted<br />
in line 30. You control the<br />
position of the blob by using IN-<br />
KEY$, pressing on keys "8" (to<br />
move the blob right) and "5"<br />
(to move it left). The whole of<br />
line 80 ensures that the blob<br />
will not move off the screen,<br />
and saves valuable memory by<br />
placing the interpretation of<br />
both INKEY $ and checking the<br />
screen limits on either side,<br />
within one line. Line 990 prints<br />
LET<br />
LET D^-<br />
<strong>ZX</strong> COMPUTING SUMMER 1382 109