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.
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]; ...
Get Cocos2d for iPhone 1 Game Development Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.