By placing many more enemies in a game we begin to require some group-based AI. A popular algorithm used in both video games and films is the Boids algorithm. It simulates flocking behavior. In this recipe, we will create a large number of enemies who flock together and chase the player.
Execute the following code:
@interface Ch7_AIFlocking : Ch7_LineOfSight {} /* CODE OMITTED */ @end @implementation Ch7_AIFlocking -(void) step:(ccTime)delta { [super step:delta]; //Process the 'boids' flocking algorithm [self processBoids]; } /* Make the flock of 'boids' follow the actor */ -(void) followActorWithEnemies { //All enemies constantly follow the actor for(int i=0; i<enemies.count; i++){ //Align enemies GameActor *enemy = [enemies objectAtIndex:i]; CGPoint directionVector = CGPointMake(actor.body->GetPosition().x - enemy.body-...