Box2D Cannon Game
Chapter 7 of Ian Parberry's "Introduction to Game Physics with Box2D"
|
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. | |
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 |
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.
int CCannon::BallsFired | ( | ) |
Get number of cannonballs fired in this level.
Return the number of cannonballs fired in this level of the game.
void CCannon::BarrelUp | ( | float | angle | ) |
Rotate the cannon barrel.
Rotate the cannon barrel up or down by a small increment.
angle | Angle 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 mark it for exploding on the next fire.
void CCannon::create | ( | ) |
Create a cannon.
Create a cannon in Physics World and Object World, linking the two representations together.
void CCannon::Explode | ( | ) |
Make cannon explode.
Make the cannon explode by destroying the joints, applying impulses to cannon parts so that they fly apart, and resetting their collision group indices so that they can collide.
BOOL CCannon::Fire | ( | ) |
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 has exploded already.
void CCannon::Reset | ( | ) |
Reset cannon to initial conditions.
Reset the cannon to its initial conditions ready for a new level to begin.
void CCannon::StartMovingLeft | ( | float | speed | ) |
Start the cannon moving.
Start the cannon moving using motors in the wheels.
speed | Speed of cannon. Positive means left, negative means right. |