Game Development Reference
In-Depth Information
different operations on a grid like this. These operations can be useful for many different games. For
example, removing a row from a grid is an operation that is used a lot in Tetris games. A game like
Bejeweled needs operations that can remove a number of items from a row or a column and fill the
grid again.
In addition to the operations you can perform on grids, you also have to think about the items the
grid contains. In this example, you used a two-dimensional grid containing references to sprites. For
more complicated games, it's useful to have a grid of game objects instead, so you can add more
behavior and interaction to the objects that are part of the grid.
Hierarchy of Game Objects
This section shows you how to create a hierarchy of game objects. You start by defining a very basic
GameObject class, and you add code that supports putting game objects into hierarchies.
Anatomy of a Game Object
Most games have quite a complicated structure of game objects. First there might be a background
consisting of various layers of moving objects (mountains, air, trees, and so on). Then there are
objects moving around that the player can interact with. These objects may be enemies of the
player, so they need some level of intelligence; they can also be more static, such as power-ups,
trees, doors, or ladders.
Sometimes objects don't even have a physical appearance in the shape of a sprite. For example, the
player's current score could also be a game object, but rather than having a sprite associated with
it, a font display the current score somewhere. Or imagine a game where an invisible enemy has to
be defeated, and its position can only be seen by the effect it has on its surroundings. Other game
objects are even more complex: game objects that consist of other game objects.
Suppose you have a game object that represents a house. It might consist of many other game
objects, such as a door, stairs, windows, and a kitchen (which itself, in turn, consists of different
game objects).
In the case of puzzle games, the grid that represents the playing field could also be considered
a game object that consists of a grid of other game objects. Given these different types of game
objects and the relations between them, you can say that game objects generally form part of a
hierarchy . This hierarchy can be completely flat, as in the first example game, Painter; but the Jewel
Jam game explained in the following chapters has a complicated hierarchy of game objects.
Many games use a hierarchy of game objects. Especially in 3D games, such a hierarchy is very
important because of the complexity of three-dimensional environments. Objects in 3D games are
normally represented not by sprites, but by one or more 3D models. The advantage of a hierarchy
is that these objects can be grouped together, so that if you pick up a vase that contains a scroll
with magic writing on it, the scroll moves along with the vase. Such hierarchies are also called scene
graphs because they present the scene (the environment) as a graph-like structure.
In the Painter game, the basic type of game object is represented by the ThreeColorGameObject
class. It's clear that not all game objects have three possible colors, a current position, and a current
velocity. Until now, this is how you've represented game objects, simply because it was sufficient for
the basic examples you were working on. If you want to develop bigger, more complicated games,
 
Search WWH ::




Custom Search