Here is how I do it:
I have a method named setupWave
which initiates a round or wave:
- (void) setupWave {
// remainingCount is the number of enemies that will be spawned in the current wave
remainingCount = (int)((((waveCount + 1)/2.0) + ((gameDifficulty + 1)/1.5)) * 3);
// dieCount is used to find when the wave ends
dieCount = remainingCount;
[self stepAI];
}
this method stepAI
creates an enemy and calls itself after a delay till the remainingCount != 0
- (void) stepAI {
// code to initialize the enemy object goes here
// you can adjust the enemy parameters like health, range, etc., based on current wave as below:
tmpAttacker.maxHealth = BASEHP + (BASEHP / 10.0) * waveCount;
remainingCount--;
// calls the `stepAI` again after some delay to spawn next enemy, until remainingCount reaches 0
if (remainingCount > 0) {
[self runAction:[CCSequence actions:
[CCDelayTime actionWithDuration:TIMEBETWEENUNITS], //for delay
[CCCallFunc actionWithTarget:self selector:@selector(stepAI)], //calls itself again
nil]];
}
}
this method gets invoked when the enemy dies:
- (void) attacker:(id)sender diedWhile:(AttackerState)tState {
dieCount--;
// if the die count reaches 0, that is after all the enemies in current wave are dead,
// initiate the next wave after some delay
if (dieCount == 0) {
waveCount++;
[self runAction:[CCSequence actions:
[CCDelayTime actionWithDuration:TIMEBETWEENWAVES], // for delay
[CCCallFunc actionWithTarget:self selector:@selector(setupWave)],
nil]];
}
All the coding is in Objective-C, I will change into pseudo code, if this is harder to understand.