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


Public Member Functions | |
| CObject (eSprite, b2Body *) | |
| Constructor. | |
| ~CObject () | |
| Destructor. | |
| void | draw () |
| Draw object in Render World. | |
| void | MakeCollisionSound () |
| Make collision sound, if appropriate. | |
| const bool | CrateBelow (float) const |
| Crate is below a given height. | |
| const eSprite | GetSpriteType () const |
| Get sprite type. | |
Private Attributes | |
| b2Body * | m_pBody = nullptr |
| Physics World body. | |
| b2Vec2 | m_b2vOldV |
| Old velocity vector, needed to infer collisions. | |
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! | |
Game objects are responsible for remembering information about themselves, in particular, their representations in Render World and Physics World.
| CObject::CObject | ( | eSprite | t, |
| b2Body * | b ) |
This constructor assumes that a Physics World body has already been created for this object. It then has responsibility for deleting it in its destructor.
| t | Sprite type. |
| b | Pointer to Physics World body. |
| CObject::~CObject | ( | ) |
This destructor assumes that Box2D hasn't been shut down yet.
| const bool CObject::CrateBelow | ( | float | h | ) | const |
If this is a crate, is it below a given height? We only care about crates, so we return true for everything else.
| h | Height in Render World units. |

| void CObject::draw | ( | ) |
Draw in Render World. Position and orientation must be gotten from Physics World.

| const eSprite CObject::GetSpriteType | ( | ) | const |
Reader function for sprite type.
| void CObject::MakeCollisionSound | ( | ) |
Kluge collision sounds by querying Physics World to see whether the object's velocity has changed. If the length squared of the change in velocity vector is larger than some arbitrarily chosen value, then conclude that a collision must have occurred, so make a sound.
