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

Firing projectiles at moving targets

For AI actors to interact with their environment realistically, they must make calculations that human players make naturally. One common interaction involves firing a projectile at a moving target.

Firing projectiles at moving targets

Getting ready

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

How to do it...

Execute the following code:

@implementation Ch7_ProjectileAiming -(void) step: (ccTime) dt { [super step:dt]; /* CODE OMITTED */ //Firing projectiles fireCount += dt; if(fireCount > 1.0f){ fireCount = 0; [self fireMissiles]; } } /* Each enemy fires a missile object */ -(void) fireMissiles { for(int i=0; i<enemies.count; ...

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