Creating the clown
Now that we have built the boundary within which we will restrict the clown's movements, and a perfectly bouncy trampoline, it is time to actually create the clown. We will create a class to handle the daredevil personality of our clown and will very intelligently name the class Clown
.
Our Clown
class will inherit from GameObject
, so we need not worry about updating the position of the clown with respect to his body. However, we will define the clown's state machine in this class. For now, let's look at the CreateClown
function in the GameWorld.cpp
file:
void GameWorld::CreateClown() { // clown will be a dynamic body b2BodyDef clown_def; clown_def.type = b2_dynamicBody; // clown will start off at the centre of the screen clown_def.position.Set(SCREEN_TO_WORLD(SCREEN_SIZE.width/2), SCREEN_TO_WORLD(SCREEN_SIZE.height/2.75)); b2Body* clown_body = world_->CreateBody(&clown_def); // create clown, set physics body & add to batch node clown_ = Clown...