Game Development Reference
In-Depth Information
Listing 6-10. Actor.m
#import "Actor.h"
@implementation Actor
@synthesize actorId;
@synthesize added;
@synthesize removed;
@synthesize center;
@synthesize rotation;
@synthesize speed;
@synthesize radius;
@synthesize needsViewUpdated;
@synthesize representation;
@synthesize variant;
@synthesize state;
@synthesize alpha;
@synthesize behaviors;
-(id)initAt:(CGPoint)aPoint WithRadius:(float)aRadius
AndRepresentation:(NSObject<Representation>*)aRepresentation{
self = [super init];
if (self != nil){
[self setActorId:[NSNumber numberWithLong:nextId++]];
[self setCenter:aPoint];
[self setRotation:0];
[self setRadius:aRadius];
[self setRepresentation:aRepresentation];
[self setAlpha:1.0];
}
return self;
}
-(void)step:(GameController*)controller{
//implemented by subclasses.
}
-(BOOL)overlapsWith: (Actor*) 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;
}
-(void)setVariant:(int)aVariant{
if (aVariant != variant){
variant = aVariant;
needsViewUpdated = YES;
}
}
-(void)setState:(int)aState{
if (aState != state){
state = aState;
n
Search WWH ::




Custom Search