Game Development Reference
In-Depth Information
In Listing 12-7, we see the header file for the class BeltCommanderController . As expected, the class
extends GameController . It also defines a protocol called BeltCommanderDelegate . This protocol
is implemented by RootViewController and is used to pass game state. There are two IBOutlets
associated with this class. The first, HealthBarView , is the UIView subclass that is responsible for
rendering the health bar at the upper right of the screen. The second, scoreLabel , is used to display
the player's score as the game is played.
In Listing 12-7, we see that there is a GameParameters object called gameParameters . This object is
used to determine which types of Actors should be included in the game. The idea is that this game
would be free and the player could purchase different types of Actors to make it more fun (and
profitable). Such in-app purchases are discussed in Chapter 10. For this chapter, we are assuming
all in-app purchases have been made.
Viper object is used to keep a reference to the ship in the game. Since we will want easy access
. The last field is called asteroids_destroyed and is used to track achievements, as described
9.
BeltCommanderController . The only ones
doNewGame: and tapGesture: ; the others we will cover as
doNewGame: is called by RootViewController to start
tapGesture: is called when a
t ureRecognizer detects a tap on the screen; we will see this shortly as well. More about
8. Let's focus on the setup first.
Understanding the Setup
There are few steps that we must take to get BeltCommanderController set up. Since we know that
BeltCommanderController extends GameController , we know that it should implement a doSetup
task, as shown in Listing 12-8.
Listing 12-8. BeltCommanderController.m (doSetup)
-(BOOL)doSetup{
if ([super doSetup]){
[self setGameAreaSize:CGSizeMake(480, 320)];
[self setIsPaused:YES];
NSMutableArray* classes = [NSMutableArray new];
[classes addObject:[Saucer class]];
[classes addObject:[Bullet class]];
[classes addObject:[Asteroid class]];
[classes addObject:[Powerup class]];
[self setSortedActorClasses:classes];
UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(tapGesture:)];
[self prepareAudio: AUDIO_BLIP];
[self prepareAudio: AUDIO_GOT_POWERUP];
 
Search WWH ::




Custom Search