Game Development Reference
In-Depth Information
Chapter 6
Create Your Characters:
Game Engine, Image Actors,
and Behaviors
In this chapter and the next, we will be creating classes for characters that will be used in the
complete game presented in this topic. But first, we need to refactor the code from the previous
chapters to create reusable classes that make up a simple game engine. We will explore the classes
and protocols that make up this game engine so you can understand how they fit together.
We will further abstract how actors are drawn on the screen by introducing the protocol
Representation , which will allow us to create image-based actors as well as actors that are
programmatically drawn (presented in the following chapter). The protocol Representation will
provide us with a shared API for working with these two different types of on-screen actors.
We will also introduce the concept of behavior through the protocol Behavior . This protocol provides
us with a pattern for describing what an actor does in the game in a reusable way.
By building our first character, the power-up, you will start to learn how to use a game engine. We
will create an example GameController subclass that lets a bunch of power-ups loose on the screen,
so you can get a feel for how this character looks and behaves.
Understanding the Game Engine Classes
Our simple game engine starts with two core classes: GameController and Actor . GameController is
very much like the controller classes from the preceding chapter, except that it has been refined for
more general use. The Actor class has similarly been improved to accommodate a greater number of
Actor types. The Actor class also defines two protocols, Representation and Behavior that are used
to describe each actor in different ways. The protocol Representation describes the tasks required
131
 
Search WWH ::




Custom Search