O'Reilly logo

Cocos2d for iPhone 0.99 Beginner's Guide by Pablo Ruiz

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

Time for action - throwing enemies at your hero

To make it simple, we will just make the simplest, dumbest enemies; those would be the ones that just move forward no matter what. They are slow and easy to shoot down and some of them will shoot back. For the time being, we will have them appear at regular time intervals. The following are the steps involved in the creation of the Enemy class:

  1. Add a new class to your project named Enemy.
  2. Replace the Enemy.h file's content with the following code:
    #import <Foundation/Foundation.h> #import "cocos2d.h" #import "GameScene.h" @interface Enemy : CCNode { CCSprite * mySprite; GameLayer * theGame; float lastTimeFired; float fireInterval; float firingSpeed; float movementSpeed; bool launched; int hp; int maxHp; ...

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