Masks & Graphical Adventure Games
By Joshua Cantrell
last updated: 12-19-97
How to use masks in graphical adventure games.
Masks can be used to remove unwanted values. In figure 1-1, a mask is
shown with a picture. The mask was applied to the picture to create
the result. Wherever a postion in the mask was set, the corresponding
part of the picture was removed.
In our game we want the player to hide objects. We would also like the
other objects to hide the player. The player and objects all have a
known shape, which masks are suitable for, except that we want everything
to have a sense of position and depth in the world. By themselves, masks
are two dimensional, so extra information must be collected about the mask
to make them more three dimensional. (Making a three dimensional grid
would not be a good idea. It would result in speed and memory problems.)
A first step to help fix our depth problem may be to give each mask a
number representing its depth. Shown in Figure 1-2 is an example of this
approach. It doesn't do too bad, if each object is flat and only exists
in the xy plane (assuming the z axis is depth).
What if we have objects that really have dimensions, and we cannot pretend
they only exist in the xy plane. We'd like the objects to have three
dimensional depth in their being as well as position in the picture.
(What if your player decides to walk around a wall, yet you don't want any
confusion about when he should be shown in front of or behind the wall.)
Two cases could be made. One for horizontal objects, the other for
verticle objects, as shown in figure 1-3.
Figure 1-3 may look confusing at first, but I purposely made the square
and circle intersect the 'X' shape. Notice how the square's depth is
determined by columns and the circle is determined by rows. Table legs
could be the mask dependent on column depth, and a table top could be the
mask dependent on row depth.
If you know what z-buffering is, you are probably seeing some simularities
between it and this technique. (For those not familiar with z-buffering,
it gives each position of the mask a depth.) I have avoided z-buffering
because it is probably a good assumption that you don't need that type
of complication and precision in objects and masks. Checking the
numerous depths may also create unnecessary overhead.
How to determine if an object is hit while moving.
The masks can also help determine if the player has hit an object.
Using a simple box of masks to represent the character and objects
(maybe four row dependent masks to specify the top, bottom, front,
and back, plus two column dependent masks to define its left and
right sides), a detection to see if any of the sides intersect, or
go through each other while moving would indicate a collision.
For the reasons of, "I'm still thinking about this," and, "I have other
things I need to do," I'll have to stop here. I'll leave what I haven't
covered as an assignment for you to do, until I have more time to
complete this page.
NOTE: All of the information on this page is purely theoretical. If it
doesn't work for you, it might not work at all. This information is being
shared to help others think about the subject and perhaps generate ideas
that they had not considered before.
(My Home Page)
- (My Personal Page)
- (My Computer Science Page)
- (My Resume)