Chapter 9 Direct Routines
Space Invaders, one technique is to check only for a bomb-ship collision
when the bomb is near the bottom of the screen. The only thing the
bomb could hit on the line where the ship operates is the ship itself, and
so all the program has to do is check for a collision when the bomb
crosses this line. For more involved situations, the easiest method might
prove to be just looking at the PEEK codes and comparing them with
those of the ship and the other items.
This then gives the general idea of moving the bombs, but one or two
finer points arise out of it. Firstly you must scan the screen in the
opposite direction to that of bomb movement (this idea is met in
scrolling as well) as otherwise you will pick up a bomb and move it on,
only to pick it up again a fraction of an instant later (and move it on
again). Of course this results in the bombs moving straight to the base of
the screen in one scan. Secondly, don’t forget to reset the collision flag.
How this is done is important. You may want the bombs in the BASIC
program to move three times as fast as everything else. This can be
achieved by using:
SYS 826 : SYS 826 : SYS 826
(826 is the assumed address of the routine.) If this is the case, then it’s
no use the machine code routine resetting the flag: the flag might be lost
if a collision occurred in the first one or two passes. In this instance it’s
the caller that must maintain the status of the flag, but bear in mind this
is not always the case.
We are now in a position to set down the various stages involved in
the bomb-updating process:
1) Reset the collision flag (may be omitted).
2) Scan screen in opposite sense to bomb motion.
3) If bomb has hit something other than the player’s property, then
apply rules of the game to the situation.
4) If the bomb has hit the player’s ship, then set the collision flag.
5) Repeat (2) onwards until the screen has been scanned.
If the bomb does hit something then the programmer might want to
trigger an explosion by tripping a gate in the SID.
To alter the direction of the bombs all you have to do is to alter the
bomb vector, but bear in mind that if you make the bombs move into
progressively lower memory locations then you will have to reverse the
direction of the scan. To liven things up a bit you might like to try a
‘spiralling’ bomb routine where the bombs change shape as they fall.
The best way to do this is to alter the UDG definition from one shape to
another, every time the routine is called. Using this method I have
79