Box2D Cannon Game with Stars
Chapter 8 of Ian Parberry's "Introduction to Game Physics with Box2D"
 All Classes Files Functions Variables Enumerations Friends Pages
Public Member Functions | Friends | List of all members
CCannon Class Reference

The cannon object. More...

#include <cannon.h>

Public Member Functions

 CCannon ()
 Constructor.
 
void create ()
 Create a cannon.
 
void Explode ()
 Make cannon explode.
 
BOOL Fire ()
 Fire the cannon.
 
void BarrelUp (float angle)
 Rotate the cannon barrel up.
 
void StartMovingLeft (float speed)
 Start the cannon moving.
 
int BallsFired ()
 Get number of cannonballs fired in this level.
 
BOOL IsDead ()
 Whether cannon has exploded.
 
void CoolDown ()
 Cannon temperature drops over time.
 
void Reset ()
 Reset cannon to initial conditions.
 

Friends

class CObjectWorld
 

Detailed Description

The cannon object.

The cannon object is a composite made up of several sprites in Render World and several bodies in Physics World. It is intended to represent the player.

Member Function Documentation

int CCannon::BallsFired ( )

Get number of cannonballs fired in this level.

Number of cannonballs fired in this level of the game.

Returns
Number of cannonballs fired.
void CCannon::BarrelUp ( float  angle)

Rotate the cannon barrel up.

Rotate cannon barrel a small amount.

Parameters
angleAngle increment in radians. Positive means up, negative means down.
void CCannon::CoolDown ( )

Cannon temperature drops over time.

Cool the cannon's temperature, unless it is too high already, in which case it explodes.

void CCannon::create ( )

Create a cannon.

Create cannon in Physics World and Object World, linking the two representations together.

void CCannon::Explode ( )

Make cannon explode.

Make cannon explode. Destroy the joints, apply impulses to cannon parts so that they fly apart, and reset their collision group indices so that they can collide.

BOOL CCannon::Fire ( )

Fire the cannon.

Fire the cannon. If enough time has passed for reloading, create a cannonball in both Render World and Physics World, and send it on its way. Apply a recoil impulse to the cannon in Physics World. Increment the cannon's temperature. All this is assuming that the cannon isn't nose down and hasn't already exploded.

BOOL CCannon::IsDead ( )

Whether cannon has exploded.

Determine whether the cannon is dead.

Returns
TRUE If it's dead, Dave.
void CCannon::Reset ( )

Reset cannon to initial conditions.

Reset the cannon to initial conditions.

void CCannon::StartMovingLeft ( float  speed)

Start the cannon moving.

Start cannon moving.

Parameters
speedSpeed of cannon. Positive means left, negative means right.