Simulating bullets

Bullets and other fast moving objects are a fundamental part of many video games. In this recipe, we will see how to properly implement bullet physics.

Simulating bullets

Getting ready

Please refer to the project RecipeCollection02 for full working code of this recipe. Also note that some of the following code has been omitted for brevity.

How to do it...

Execute the following code:

@implementation Ch4_Bullets /* Fire the gun */ -(void) fireGun { //Fire 10 bullets per second if(fireCount > 0){ return; } fireCount = 0.2f; CCSpriteFrameCache *cache = [CCSpriteFrameCache sharedSpriteFrameCache]; //Fire bullet in the correct direction float gunAngle = ...

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.