Game Development Reference
In-Depth Information
Here you can see the
updateScene
task as defined in the class Example01Controller. The class
Example01Controller extends
GameController
so it inherits the game engine logic defined in that
class. The
updateScene
task simply adds a new power-up every 5 seconds and then calls the super-
implementation of
updateScene
. The header file for the class
Powerup
is shown in Listing 6-12.
Listing 6-12. Powerup.h
#import <Foundation/Foundation.h>
#import "Actor.h"
#import "ImageRepresentation.h"
#import "ExpireAfterTime.h"
enum{
STATE_GLOW = 0,
STATE_NO_GLOW,
PWR_STATE_COUNT
};
enum{
VARIATION_HEALTH = 0,
VARIATION_CASH,
VARIATION_DAMAGE,
PWR_VARIATION_COUNT
};
@interface Powerup : Actor <ImageRepresentationDelegate,ExpireAfterTimeDelegate>{
}
+(id)powerup:(GameController*)aController;
@end
This header file starts by defining two enumerations. The first enumeration defines the values for the
two states of
Powerup
, STATE_GLOW or STATE_NO_GLOW. The second enumeration defines the
values for the three variations of
Powerup
. Both of these enumerations end with a value that has
the word COUNT in it. For those developers who are not coming from a C background, this is an
old trick used to create a constant for the number of items in an enumeration. For example, in the
first enumeration, STATE_GLOW has a value of 0, so STATE_NO_GLOW has a value of 1. This gives
PWR_STATE_COUNT a value of 2, which is the number of states there are. Clever, no?
The class
Powerup
as defined in Listing 6-12 extends
Actor
. It also conforms to the protocols
ImageRepresentationDelegate
and
ExpireAfterTimeDelegate
. We will look at the tasks that come
with these protocols when we look at the details of the
ImageRepresentation
and
ExpireAfterTime
.
The only new task defined for the
Powerup
class is the constructor
powerup
:. Let's take a look at that
task in Listing 6-13.