Game Development Reference
In-Depth Information
asteroids as they break apart, since each new asteroid has a level of one less than its creator. The
last thing we do in the
asteroidOfLevel:At:
is to add a
LinearMotion
behavior the
Asteroid
so it
moves in a straight line, wrapping around the screen.
Another thing to note in Listing 7-8 is that we are creating an
ImageRepresentation
in a slightly
different way than we have up until this point. Previously, all the
ImageRepresentations
we created
used the actor as the
delegate
, This made sense because it put all of the information about an
actor into a single file. However, we will want the
Asteroid
class and the particles we create
to look the same, though different size. To facilitate this, we have created a new class called
AsteroidRepresentationDelegate
that is responsible for specifying how things that look like
asteroids are rendered. Let's move on to the class
AsteroidRepresentationDelegate
.
Asteroid
is drawn is defined in the class
AsteroidRepresentationDelegate
. This
Asteroid,
as well as the p
articles
we create when an
Asteroid
AsteroidRepresentationDelegate
is shown in Listing 7-19.
static AsteroidRepresentationDelegate* instance;
@synchronized(self) {
if(!instance) {
instance = [AsteroidRepresentationDelegate new];
}
}
return instance;
}
-(int)getFrameCountForVariant:(int)aVariant AndState:(int)aState{
return 31;
}
-(NSString*)getNameForVariant:(int)aVariant{
if (aVariant == VARIATION_A){
return @"A";
} else if (aVariant == VARIATION_B){
return @"B";
} else if (aVariant == VARIATION_C){
return @"C";
} else {
return nil;
}
}
-(NSString*)baseImageName{
return @"Asteroid";
}