Game Development Reference
In-Depth Information
CCLOG(@"spawn enemy type %i", enemyType);
[enemy spawn];
break;
}
}
}
-(void) update:(ccTime)delta
{
updateCount++;
for (int i = (EnemyType_MAX - 1); i > = 0; i--)
{
int spawnFrequency = [Enemy getSpawnFrequencyForEnemyType:i];
if (updateCount % spawnFrequency == 0)
{
[self spawnEnemyOfType:i];
break;
}
}
}
The update method increases a simple update counter. It doesn't take into effect
the actual time passed, but because the variances are typically minimal, it's a fair trade-
off to make life a bit easier. This for loop oddly starts at (EnemyType_MAX - 1)
and runs until i is negative. The only purpose for this is that higher-numbered
EnemyTypes have spawn precedence over lower-numbered EnemyTypes . If a boss
monster is scheduled to appear at the same time as a cruiser, the boss will be spawned.
Otherwise, it could happen that the cruiser takes the boss's spawn slot by trying to
spawn at the same time, blocking the boss from ever spawning. It's a side effect of the
spawning logic, and I leave it up to you to extend and improve this code, because
you'll probably have to do anyway if you decide to write your own version of a classic
shoot-'em-up game.
The spawnFrequency is obtained from Enemy 's getSpawnFre-
quencyForEnemyType method:
Search Nedrilad ::




Custom Search