Game Development Reference
In-Depth Information
Chapter 15
Gameplay Programming
This chapter looks into the gameplay programming of the Jewel Jam game. First it talks about
interaction between game objects. Then it introduces a few new game objects that are used in the
game. Finally, you tackle the main gameplay element of this game: finding combinations of jewels
and handling them properly.
Interaction between Game Objects
This section looks at how game objects communicate with each other. Before game objects can do
that, you first need a way for these objects to find each other.
The previous chapter presented the game world as a hierarchy of game objects. Each of these game
objects may process user input and may exhibit some kind of behavior. For example, the jewel grid
game object checks whether the player has dragged one of the rows in the grid and performs a
row-shifting operation if needed. This is a typical example of how many game objects in games are
designed. They process input from the player, and they react to it, which in turn can influence other
game objects (such as the positions of jewels on the grid). In the Painter game, you saw that the ball
and the paint cans interact with each other in a similar fashion. In more complicated games, many
different game objects interact with each other.
The challenge is, how do these game objects find each other? In the case of the Painter game, the
PainterGameWorld class has member variables that refer to each of the game objects. This isn't a
very good solution, because it makes the game world completely dependent on the game it's a part
of. In the Jewel Jam game world, you only have a hierarchy of GameObject instances, which makes it
much more complicated to find a particular game object.
You should design your classes in such a way that they can be used in many different games. In the
last version of the game Jewel Jam, there was very little interaction between the game objects, so you
could get away with a simple design. This won't work anymore now. For example, the jewel grid needs
to be able to find the object that represent the player's score so that it can update this score when
the player makes a valid combination of jewels. The grid also needs to find the moving jewel cart so
that it can move the cart back to the left when it's required. To do these things, you need a way to find
objects in the game world without making the game world rely on code specific to the game.
209
 
Search WWH ::




Custom Search