Game Development Reference
In-Depth Information
Chapter 23
Pairing the Penguins
23.1 Introduction
In this chapter, we will program the main gameplay for the Penguin Pairs game. We
will discuss how to move penguins around on the board, and what to do when a
penguin collides with another game object such as a shark or another penguin.
23.2 Penguin Selection
Before we can move penguins around, we need to be able to select a penguin. When
we click on an animal such as a penguin or a seal, four arrows should appear that
allow us to control in which direction the animal should move. In order to display
these arrows and handle the input, we will add a class called AnimalSelector that will
deal with this. Since the animal selector contains four arrows, it will inherit from
the GameObjectList class. Furthermore, we want to achieve a nice visual effect that
when the player moves the mouse over one of the arrows, it becomes darker. We
can achieve this effect by adding a class Arrow that contains two sprites: one for
the 'regular' arrow, and one for the arrow image when we hover over it. Further-
more, the Arrow class should be able to show an arrow in any of the four possible
directions.
23.2.1 The Arrow Class
Although we could have a single arrow image and rotate it depending on the desired
direction, we have chosen to keep things simple by having an image that contains
the arrow pointing in all four directions (see Fig. 23.1 ). Therefore, when we load the
sprite, the sheet index indicates which arrow we should show. For the hover status,
we load another sprite containing the same arrow images, in the same order, but
 
Search WWH ::




Custom Search