Game Development Reference
In-Depth Information
-(BOOL)overlapsWith: (Actor02*) actor {
float xdist = abs(self.center.x - actor.center.x);
float ydist = abs(self.center.y - actor.center.y);
float distance = sqrtf(xdist*xdist+ydist*ydist);
return distance < self.radius + actor.radius;
}
@end
In Listing 5-8, we see the implementation of the class Actor02 . The task initAt:WithRadius:AndImage:
is used to initialize an Actor02 with some basic information. This task also assigns a random actorId
value by using the value nextId and incrementing it. Because nextId is of type long, you will have to
create an incredible number of actors before you get two actors with the same ID.
step: takes an instance of Example02Controller and is used incrementally to update the
Actor02 . Subclasses will provide an implementation to this task to provide
overlapsWith: , is used to check to see if this Actor02 overlaps with another Actor02 .
Viper02 and see how it is different from Viper01 . The header for Viper02 is
Listing 5-9. Viper02.h
@class Example02Controller;
@interface Viper02 : Actor02 {
}
@property CGPoint moveToPoint;
+(id)viper:(Example02Controller*)controller;
-(void)doCollision:(Actor02*)actor In:(Example02Controller*)controller;
@end
In Listing 5-9, we see that the header for Viper02 is not much different from Viper01 , as shown
in Listing 5-2. Viper02 extends the class Actor02 instead of UIImageView . We have the property
moveToPoint , which is the same, but the property speed is absent because that is inherited from
Actor02 . We have a new constructor to simplify the creation of a Viper02 and a new task called
doCollision:In: that is used to handle the new functionality of colliding with an asteroid. Listing
5-10 shows the implementation of the class Viper02 .
Listing 5-10. Viper02.m
#import "Viper02.h"
#import "Example02Controller.h"
 
Search WWH ::




Custom Search