Hardware Reference
In-Depth Information
checks whether those coordinates are contained in the exclusion list. hat is quite a lot of func-
tionality in a single statement and would be quite hard to code in another language. Finally, the
power pills are simply contained in another list, and they have a large square in a diferent colour
drawn around them. In fact, this did not look good when I drew a box around the existing pixel,
so the code draws the large solid square irst and then the small yellow pill square on top of that.
The Game Action
Now let's look at the action part of the program, which will move the sprite in a speciic direc-
tion unless it is blocked by a wall. his is not quite as simple as it might sound. he position of
a sprite, Pie Man or ghost, is the point where you will plot it on the screen, which is in fact the
top-left corner of the sprite and, depending on what direction the sprite is moving, will depend
on where you have to check to see if it can move. Figure 6-7 shows this for Pie Man moving
both left and right. Note that the distance away from the plot position depends on the direc-
tion. When Pie Man is moving to the left the place to test is only the move increment away
from the plotted position, whereas when he is moving to the right the length of the image
needs to be added to the walk increment and then subtracted from the plot position. hat is
only for the X coordinate; the Y coordinate needs to be scanned over the height of the image to
see if a part of a wall is blocking the progress. Note the pixels to test are not contiguous, but
every four pixels - that is, half the maximum walk increment. his reduces the number of pix-
els that need testing and thus speeds up the process. A similar process must be gone through
when checking up and down movement. he functions in Listing 6-3 do this.
Figure 6-7:
Detecting a wall.
Search WWH ::




Custom Search