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

Defining the elements of Inverse Universe


In this section, we will discuss the behavior of each element of the game in as much detail as possible, starting from the player, to the enemies and to each of the three power-ups. So, let's begin with the Player class.

The Player class

The Player class will inherit from CCDrawNode and will have a radius to be used for circular collision detection, a speed variable that will be set based on the input from the accelerometer, and a reference to GameWorld. Let's begin by defining the init function for the Player class:

bool Player::init()
{
  if(!CCDrawNode::init())
    return false;

  // generate vertices for the player
  CCPoint vertices[] = {CCPoint(PLAYER_RADIUS * 1.75f, 0), 
    CCPoint(PLAYER_RADIUS * -0.875f, PLAYER_RADIUS), 
    CCPoint(PLAYER_RADIUS * -1.75, 0), CCPoint(PLAYER_RADIUS * -0.875f, 
    PLAYER_RADIUS * -1)};
  // draw a green coloured player
  drawPolygon(vertices, 4, ccc4f(0, 0, 0, 0), 1.5f, ccc4f(0, 1, 0, 1));

  scheduleUpdate...