Book Image

Cocos2d-X Game Development Blueprints

By : Karan Sequeira
Book Image

Cocos2d-X Game Development Blueprints

By: Karan Sequeira

Overview of this book

Table of Contents (17 chapters)
Cocos2d-x Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The Tower class


Our Tower class will inherit from CCSprite and will contain all the properties that we saw in the TowerDataSet and TowerData structures. In addition to that, the Tower class will also possess the behavior of targeting and shooting enemies, as well as upgrading itself.

Let's take a look at how the Tower class is declared in Tower.h:

class Tower: public CCSprite
{
public:
  Tower();
  virtual ~Tower();

  static Tower* create(GameWorld* game_world, 
    int type, CCPoint position);

  virtual bool init(GameWorld* game_world, 
    int type, CCPoint position);
  // copy the data within the TowerDataSet library inside GameGlobals
  void SetTowerProperties();

  // update functions
  virtual void Update();
  void UpdateRotation();

  // functions that take care of upgradation & resale
  void Upgrade();
  void Sell();

  // basic tower behaviour
  void CheckForEnemies();
  void SetTarget(Enemy* enemy);
  void Shoot(float dt);
  void ShootBullet();
  void ShootLightning();
  
...