SPACE EGGS
Christopher Leigh presents a new version of a favourite shoot-'em-up using
sprites in glorious colour.
HERE'S A colourful asteroids-style game for the Amstrad CPC-464. While using
Mode 1 it manages to give a whole range of colours and provides Mode 0 size
text printing on the screen using a Rom indirection. Get yourself a high score
by shooting the eggs and aliens but watch the bonus. Quick shots will score
well but be slow and the bonus will turn against you!
The game features 44 sprites of different sizes with up to 25 on the screen
at any one time. These are controlled by a machine-code routine that can easily
be adapted for your own purposes. In fact, most of the action is controlled by
machine-code making the main Basic game loop very short and speedy.
The main program appears in listing 1 and may be typed in directly. It should
be saved - with Goto 20000 - before running as any mistakes in the data may
cause the system to crash. The machine-code is in five routines, three of which
are listed so that you can used them in your own programs. The first one -
listing 2 - is for wide printing mimicking mode 0 printing.
In fact, it will work in any mode with suitable changes to the final few
bytes to reset the cursor position. It works by altering the high byte of the
Rom indirection at &BDD5 using Poke so that instead of pointing to the Rom
routine at &134A, it points to our routine at &A34A.
We can then use the usual Print command including the Print Using format.
The colour of the printing is given by the pen mask - changing this can give
striped writing or mixed colours. Note that the indirection supplies the screen
position as a physical position - top left = 0, 0 - whilst the cursor must be
reset to the logical position - top left = 1, 1 - hence the extra increment
instructions.
The second and third routines control the sprites and are called using
Resident System Extension (RSX) commands. Move and Erase must be preceded by
the elongated colon - shift @ - and 1Erase must be followed by a comma and its
parameter which is the address of the first byte of the move data for the
sprite.
The screen is 80 bytes wide and the sprite routines divide it into 50 half
lines high, so that each sprite unit is a quarter of a Mode 1 character. These
routines can cope with sprites of any size and - with slight alterations - of
any shape. All our sprites will be set in a square sprite shape definition, but
since zero bytes are not written to the screen - making the sprite transparent
- the sprite can be any shape within that framework.
As written the procedure allows full wrap-around, adjusting for sprites being
partly off a screen edge. Again fairly simple alterations will allow sprites to
bounce.
1Erase simply erases a sprite and turns it off. 1Move works by calculating
the old sprite position and then writing it with an ink mask of zero to rub it
out, then calculating the new position and writing with the ink mask given in
the move data.
This ink mask can be set to produce pure colours or colour mixtures for a
whole sprite. The new position is calculated by adding the speed components to
the old position and then ensuring it is on the screen. The move data also
includes the address of the shape data for a particular sprite and a collision
byte. This collision byte is the last non zero byte read off the screen when
writing the sprite. This allows us to know if it is on top of anything and also
what it is n top of.
The move data consists of nine bytes formatted thus: on/off flag, right
position, down position, right speed, down speed, ink mask, shape address low,
shape address high, collision byte. 1Move will, in fact, move every sprite,
whose on/off flag is one, in the block of move data and the routine is stopped
by a value of two. The shape data address can be altered to change the shape of
a sprite during the game as is done to rotate your space ship.
The first byte of the shape data is the size of the sprite in quarters. The
rest of the shape data comprises bytes made up in the same way as characters
are plotted on the screen in Mode 1.
As already suggested, 1Move only needs to be called once a game cycle to move
everything. Printing of score and bonus is done once a second by calling the
routine at line 200. All that remains is to read the keys, produce sound
effects, check for collisions and keep the bullets firing.
For the sake of speed the last two requirements are covered by two routines
tailored for this game. Collision checking is done by reading the collision
flags of each sprite and by checking for identical positioning. The latter is
only needed for a stationary sprite.
Eight bullets are allowed on screen at any time so as each is fired the one
eight back must be erased. Key checking is left in Basic so that you can easily
change the program to suit your fingers, and the speed can be changed using p%
in 1070 and 4010.
Note that your subspace thrusters always work in the direction you are
pointing so that once moving you need to turn round in order to slow down.
Remember your hyper space dive is kaput so using it could well land you in the
middle of one of those eggs or in the firing line of your own bullets. The
faster you shoot the aliens the larger the bonus - if you take too long your
bonus will become negative having a disastrous effect on your score!
Should you wish to start firing immediately without typing in the lengthy
data, you should send £3 for a tape to C.J. Leigh, 12 The Bassetts, Cashes
Green, Stroud, Glos GL5 4SJ. Ask for Space Eggs and don't forget your name and
address.