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 clown's state machine


A Finite State Machine (FSM) is nothing but a system to manage the various states that a particular machine (the clown in our case) can be in. You can create an FSM to describe the various stages of an entity's lifecycle. The term entity could be anything from the main character in a game where the states would be walking, running, jumping, shooting, dying, and so on. Similarly, an entity could be the game itself where the states would be: game world creation, game world update, collision detection, level completion, game over, and so on.

A common way to represent the states within an FSM is to enumerate them, which in the case of our clown's states is the following enum that you will find in the GameGlobals.h file:

enum EClownState
{
  E_CLOWN_NONE = 0,
  E_CLOWN_UP,
  E_CLOWN_DOWN,
  E_CLOWN_BOUNCE,
  E_CLOWN_ROCKET,
  E_CLOWN_BALLOON,
};

For this simple game, we have just five states the clown can be in, excluding the E_CLOWN_NONE state of course. The Clown...