O'Reilly logo

Cocos2d for iPhone 1 Game Development Cookbook by Nathan Burba

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

AI flocking using Boids

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.

AI flocking using Boids

Getting ready

Please refer to the project RecipeCollection03 for full working code of this recipe.

How to do it...

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]; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required