Game Development Reference
In-Depth Information
typedef enum
EnemyTypeUFO = 0,
} EnemyTypes;
@interface Enemy : CCSprite
EnemyTypes type;
int initialHitPoints;
int hitPoints;
@property (readonly, nonatomic) int initialHitPoints;
@property (readonly, nonatomic) int hitPoints;
+(id) enemyWithType:(EnemyTypes)enemyType;
+(int) getSpawnFrequencyForEnemyType:(EnemyTypes)enemyType;
-(void) spawn;
There is nothing too exciting here. The EnemyTypes enum is used to differentiate
between the three different types of enemies currently supported, with
EnemyType_MAX used as the upper limit for loops, as you'll soon see. The Enemy
class has a member variable that stores the type so that you can use switch state-
ments to branch the code depending on the type of enemy as needed.
The implementation of Enemy contains a lot of code I'd like to discuss, so I'll split the
discussion into several topics and present only the relevant code, beginning with the
initWithType method in Listing 8-8 .
Listing 8-8. Initializing an Enemy with a Type
#import "Enemy.h"
#import "GameLayer.h"
Search Nedrilad ::

Custom Search