MOVEAREA
by Stephen Fowler
from Sinclair Answers #1 (1984)

MOVING PICTURES

We provide hints and routines to animate your groovy graphics
creations.


Whether you see a missile glide through the air or an animal trot
across the screen, smooth animation is one of the main features that
makes a program look professional. Moving a figure one character
position at a time is sometimes acceptable but tends to look jarred,
(especially in comparison with a figure moving one pixel at a time).

On the Spectrum the screen is made up of 32 by 24 character squares,
each square being 8 by 8 pixels in size, and this article explains how
to move any drawing of this size or more smoothly round the screen. By
typing in the program supplied in Figs.1 and 2, you can achieve smooth
movement of your drawings from a Basic program, without having to
write a single line of machine-code. As letters are simply small
drawings, text can be moved using exactly the same procedure

To create the drawings in the first place a commercial graphics
development package could be used, or your own Basic program - or
better still, the graphics design program listed in the May 1984 issue
of Computer Answers. Having finished the artworks, the procedure to
introduce animation into the program is as follows (note that numbers
given are for the 48K Spectrum, the 16K values follow in brackets):

* Type in the Movearea program - in Fig.1 - and RUN it. When asked to
  start the tape recorder and press any key, do so and this will save
  a machine-code program called Movearea on the tape.

* Now write your own Basic program. The first line should be CLEAR
  50000 (CLEAR 29000). This command resets RAMTOP allowing memory
  space for the machine-code routines and also for some drawings.
  Memory addresses 50001 to 64511 (29001 to 31743) can be used to
  store pictures. The program Store, also listed in the May issue of
  Computer Answers, will help you do this.

* After the CLEAR command, the next statement should be LOAD "" CODE,
  which loads in the Movearea program. The example program Demo in
  Fig.2 should help clarify the procedure.

* As a convention, your Basic program should start at line 200, so
  include the statement GO TO 200.

* The subroutine in lines 4 to 11 of the Demo program feeds parameters
  to the Movearea program, to set the picture's size, co-ordinates,
  and speed of movement. Type in these lines exactly as they are in
  the Demo program, as the actual values are set later on in your
  Basic program.

* The next thing to do is to work out the sequence of movements you
  wish the drawing to go through. This is added to the program in the
  form of a list of decimal numbers. Use the table in Fig.3 to work
  out what these numbers should be. For example, if the drawing should
  move 5 pixels up, the number to enter is 5x4 + 2 = 22. These numbers
  are POKEd into successive locations in memory, starting at location
  64512 (31744), and terminating in a zero. The movement sequence
  should not go beyond the address 64599 (31885). Note that none of
  the numbers poked should be greater than 255, as this is the maximum
  a byte can hold.

* The movement sequence subroutine in your Basic program should be
  terminated by a RETURN.

* Your program starts from line 200, and when a drawing is to be
  moved, the following lines of Basic should be included:

LET LENGTH=L
LET HEIGHT=H
LET DELAY=D
LET X=x
LET Y=y
GO SUB 25 : REM set up movement sequence
GO SUB 4  : REM move the drawing

Note that L and H are the length and height of the drawing in
character sequences; x and y are the co-ordinates of the top left hand
corner; x can be anything from 0 to 31, and y can be from 0 to 23 (0,0
is the top left hand corner of the screen); D is any number between 1
and 255, which determines the speed of movement. If D is set to 1 then
the movement is fast, if it is 50 then it is quite slow, 255 gives
very slow movement.

And that's just about it! Remember to save your program to tape before
typing RUN just to be on the safe side. The computer will crash if you
try to move a drawing down off the bottom of the screen, but if you
move one off one side of the screen, it will reappear at the other
side. The computer should not crash if a drawing is moved off the top
of the screen, but the drawing will not reappear at the bottom. So, in
general, be very careful about moving any picture off the screen.

When running your program for the second (or subsequent) time, type
RUN 2 rather than RUN. This will avoid having to wait for the Movearea
program to load, as it should still be there (unless your program
inadvertently trampled all over it).

This is all you need to get going simple smooth movement, but there
are a few limitations of the system that should be pointed out: first,
it is only possible to move one drawing at once; and second a moving
drawing will delete whatever is underneath it, so drawings cannot be
moved over the top of one another. Very occasionally a drawing may
split when changing direction. To correct this try altering the
movement sequence slightly, or move a larger area of the screen.

The next stage is to add colour. To start off with it is probably best
simply to stick with black INK on white PAPER. Colours have to be set
for one character position (fore and background colour), it is not
possible to set the colour of one individual pixel. This makes full
colour animation difficult, with some of the strange changes in colour
that you see when playing some commercial games programs. The June '84
issue of Computer Answers explains the programs more fully.

In addition to GR3 and Store from the May issue, Movearea is also
compatible with the 48K version of the Missile machine-code program
from the June issue and the Spacesnds program also listed in this
issue on page 48. To make the 16K versions compatible, alter the 16K
version of Missile by subtracting 240 from every number over 32198 in
the program Mslmkr.

To achieve smooth animation, rather than just smooth movement, the
drawing can be altered using the GR3 program listed in our May issue.
To move, for example, a walking figure across the screen with the y
co-ordinate fixed and the x co-ordinate varying, the following loop
should be implemented:

Initialise X and Y co-ordinates;

Loop: { Draw a figure with legs apart at position X,Y;
      { Move a block of the screen (starting at X)
      { right by one character square;
      { LET X=X+1
        Goto Loop

These utilities should take a lot of the drudgery out of programming
your own games, so you can concentrate on the creative element. The
important aspect of them is that you can take advantage of the speed
of machine-code, without having to write a single line of it.


Fig.3
Move Number Table

If S = number of squares that are to be moved, then POKE the following values:

Direction   Number
---------   ------
Left        S x 32
Right       S x 32 + 1
Up          S x 32 + 2
Down        S x 32 + 3

If P = number of pixels that are to be moved, then POKE the following values:

Direction   Number
---------   ------
Left        P x 4
Right       P x 4 + 1
Up          P x 4 + 2
Down        P x 4 + 3

Example: If the drawing is to be moved three character squares up by
two pixels left, then the two numbers that would need to be POKEd are
98 and 8.


--
Another Fine Product transcribed by:
Jim Grimwood (jimg@globalnet.co.uk), Weardale, England
--
