Game Development Reference
In-Depth Information
The other interesting thing about the task doHit: , as shown in Listing 12-21, is how it creates
Particles to emphasize the destruction of the parent Asteroid . By creating 1 to 5 Particles that
look just like Asteroids and sending them out in random directions, we make a very pleasing
Asteroid destruction.
Let's continue and explore a little about the class Saucer.
The Saucer Class
The Saucer class is mostly a troublemaker. It appears at either the top or the bottom of the screen,
shooting Bullets at the Viper . What makes the Saucer class troublesome is that the Bullets
most often break apart Asteroids , creating an unpredictable pattern. The implementation of the
Saucer class in this chapter is much likes its implementation in the other chapters. However, some
modification was made to the step: task as shown in Listing 12-22.
Listing 12-22. Saucer.m (step:)
-(void)step:(GameController*)gameController{
if (health <= 0){
[gameController incrementScore:[self radius]*10];
[gameController removeActor:self];
return;
}
CGSize gameAreaSize = [gameController gameAreaSize];
CGPoint center = [self center];
if (center.y < −[self radius]){
[linearMotion setDirection:DIRECTION_DOWN];
} else if (center.y > gameAreaSize.height + [self radius]){
[linearMotion setDirection:DIRECTION_UP];
}
if (arc4random()%180 == 0){
BeltCommanderController* bc = (BeltCommanderController*)gameController;
[gameController addActor:[Bullet bulletAt:[self center] TowardPoint:[bc viper].center
From:self]];
}
}
In Listing 12-22, we see the implementation of the class step: from the class Saucer . In this task,
we check to see if the Saucer's health is below zero. If it is, we increment the gameControllers
score and remove the Saucer from the game. The next part of the task step: is to determine if
the Saucer should change direction on account of going off the screen. The last section of the
task step: is responsible for shooting Bullets . In order to do this, we get the viper property of
the gameController so we can target the Bullet on it. This is the first case where we had to cast
gameController to BeltCommanderController . It raises the question of how we might add a general
way to reference particular actors (like Viper) without depending on class definition. But, this is an
exercise for another time.
The last Actor we are looking at is Powerup .
 
Search WWH ::




Custom Search