![]() |
Box2D Cannon Game
Game Physics with a 2D Physics Engine
|
The cannon. More...
#include <Cannon.h>


Public Member Functions | |
| CCannon () | |
| Constructor. | |
| void | Explode () |
| Make cannon explode. | |
| bool | Fire () |
| Fire the cannon. | |
| void | BarrelUp (float) |
| Rotate the cannon barrel. | |
| void | SetSpeed (float) |
| Set the motor speed in the wheel joints. | |
| void | CoolDown () |
| Cannon temperature drops over time. | |
| const UINT | GetNumFired () const |
| Get number of cannonballs fired in this level. | |
| const bool | IsDead () const |
| Whether cannon has exploded. | |
| const Vector2 | GetPos () const |
| Get cannon position. | |
| void | GetTemps (float &, float &) const |
| Get current and max temperatures. | |
Private Member Functions | |
| b2Body * | CreateBase (float, float, int) |
| Create a cannon base in Physics World. | |
| b2Body * | CreateBarrel (float, float, int) |
| Create a cannon barrel in Physics World. | |
| b2Body * | CreateWheel (float, float, int) |
| Create a cannon wheel in Physics World. | |
| void | DeliverImpulse (b2Body *, const b2Vec2 &, const b2Vec2 &=b2Vec2(0, 0)) |
| Apply an impulse in Physics World. | |
| void | MakeCollide (b2Body *) |
| Make cannon parts collide-able in Physics World. | |
Additional Inherited Members | |
Static Protected Attributes inherited from CCommon | |
| static b2World * | m_pPhysicsWorld = nullptr |
| Pointer to Box2D Physics World. | |
| static CBox2DRenderer * | m_pRenderer = nullptr |
| Pointer to Render World. | |
| static CObjectManager * | m_pObjectManager = nullptr |
| Pointer to object manager. | |
| static Sage::CParticleEngine2D * | m_pParticleEngine = nullptr |
| Pointer to particle engine. | |
| static eDrawMode | m_eDrawMode = eDrawMode::Sprites |
| Draw mode. | |
| static bool | m_bEasterEgg = false |
| Easter egg! | |
The cannon is a composite made up of several sprites in Render World and several bodies in Physics World. It represents the player.
| CCannon::CCannon | ( | ) |
Null constructor. Create a cannon in Physics World and Object World, linking the two representations together. All positions are hard-coded.

| void CCannon::BarrelUp | ( | float | a | ) |
Rotate the cannon barrel up or down by a small increment.
| a | Angle increment in radians. Positive means up, negative means down. |

| void CCannon::CoolDown | ( | ) |
Cool the cannon's temperature, unless it is too high already, in which case mark it for exploding on the next fire.


|
private |
| x | Cannon barrel's x coordinate in Render World. |
| y | Cannon barrel's y coordinate in Render World. |
| nIndex | Cannon barrel's collision group index. |


|
private |
| x | Cannon base's x coordinate in Render World. |
| y | Cannon base's y coordinate in Render World. |
| nIndex | Cannon base's collision group index. |


|
private |
| x | Cannon wheel's x coordinate in Render World. |
| y | Cannon wheel's y coordinate in Render World. |
| nIndex | Cannon wheel's collision group index. |


|
private |
Deliver an impulse to part of the cannon, which is made up of many bodies in Physics World.
| b | Body to apply impulse to. |
| v | Vector direction and magnitude of impulse. |
| ds | Vector dispolacement to point at which impulse is applied. |

| void CCannon::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 | ( | ) |
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.


| const UINT CCannon::GetNumFired | ( | ) | const |
Return the number of cannonballs fired in this level of the game.

| const Vector2 CCannon::GetPos | ( | ) | const |
Reader function for the cannon's position.


| void CCannon::GetTemps | ( | float & | tcur, |
| float & | tmax ) const |
Reader function for the current and max temperatures.
| tcur | [OUT] Current temperature. |
| tmax | [OUT] Maximum temperature experienced. |

| const bool CCannon::IsDead | ( | ) | const |
Determine whether the cannon has exploded already.

|
private |
Reset the collision group index for part of cannon, which is made up of many bodies in Physics World.
| b | Body to reset collision group index of. |

| void CCannon::SetSpeed | ( | float | s | ) |
Start the cannon moving using motors in the wheels.
| s | Speed of cannon. Negative means left, positive means right. |
