Game Development Reference
In-Depth Information
Figure 6-5. Mr. Nom's world superimposed onto our game screen
Notice that Mr. Nom's world is confined to a grid of 10 × 13 cells. We address cells in a
coordinate system with the origin in the upper-left corner at (0,0), spanning to the bottom-right
corner at (9,12). Any part of Mr. Nom must be in one of these cells and, thus, have integer x and
y coordinates within this world. The same is true for the stains in this world. Each part of Mr. Nom
fits into exactly one cell of 1 × 1 units. Note that the type of units doesn't matter—this is our own
fantasy world free from the shackles of the SI system or pixels!
Mr. Nom can't travel outside this small world. If he passes an edge, he'll just come out the other
end, and all his parts will follow. (We have the same problem here on earth by the way—go in
any direction for long enough and you'll come back to your starting point.) Mr. Nom can also
only advance cell by cell. All his parts will always be at integer coordinates. He'll never, for
example, occupy two and a half cells.
Note As stated earlier, what we use here is not a strict MVC pattern. If you are interested in the
real definition of an MVC pattern, we suggest you read Design Patterns: Elements of Reusable
Object-Oriented Software , by Erich Gamm, Richard Helm, Ralph Johnson, and John M. Vlissides
(a.k.a. the Gang of Four) (Addison-Wesley, 1994). In their book, the MVC pattern is known as the
Observer pattern.
The Stain Class
The simplest object in Mr. Nom's world is a stain. It just sits in a cell of the world, waiting to be
eaten. When we designed Mr. Nom, we created three different visual representations of a stain.
The type of a stain does not make a difference in Mr. Nom's world, but we'll include it in our
Stain class anyway. Listing 6-8 shows the Stain class.
 
 
Search WWH ::




Custom Search