Game Development Reference
In-Depth Information
-(void) initEnemies
{
// create the enemies array containing further arrays for each type
enemies = [NSMutableArray arrayWithCapacity:EnemyType_MAX];
// create the arrays for each type
for (NSUInteger i = 0; i < EnemyType_MAX; i++)
{
// depending on enemy type the array capacity is set
// to hold the desired number of enemies
NSUInteger capacity;
switch (i)
{
case EnemyTypeUFO:
capacity = 6;
break;
case EnemyTypeCruiser:
capacity = 3;
break;
case EnemyTypeBoss:
capacity = 1;
break;
default:
[NSException exceptionWithName:@"EnemyCache Exception"
reason:@"unhandled enemy type"
userInfo:nil];
break;
}
// no alloc needed since the enemies array will retain anything added to it
NSMutableArray* enemiesOfType = [NSMutableArray arrayWithCapacity:capacity];
[enemies addObject:enemiesOfType];
for (NSUInteger j = 0; j < capacity; j++)
{
Enemy * enemy = [Enemy enemyWithType:i];
[batch addChild:enemy z:0 tag:i];
Search Nedrilad ::




Custom Search