Box2D Cannon Game With Stars
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CObjectManager Class Reference

The object manager. More...

#include <ObjectManager.h>

Inheritance diagram for CObjectManager:
CCommon

Public Member Functions

 CObjectManager ()
 Constructor.
 
 ~CObjectManager ()
 Destructor. More...
 
void CreateWorldEdges ()
 Create the edges of the world. More...
 
void CreateObject (eSprite, b2Body *)
 Create new object. More...
 
void CreateTower ()
 Create a tower of crates. More...
 
void clear ()
 Reset to initial conditions. More...
 
void Draw ()
 Draw all objects.
 
void EmitSmoke (const Vector2 &, Vector2)
 Emit a smoke particle. More...
 
const bool AllCratesBelow (float) const
 Test all crates below height. More...
 

Private Member Functions

void CreateCrate (float, float, const b2FixtureDef &)
 Create a crate. More...
 

Private Attributes

LParticleDesc2D m_cSmokeDesc
 Particle descriptor for smoke particle.
 
std::vector< CObject * > m_stdList
 Object list.
 

Additional Inherited Members

- Static Protected Attributes inherited from CCommon
static b2World * m_pPhysicsWorld = nullptr
 Pointer to Box2D Physics World.
 
static CRendererm_pRenderer = nullptr
 Pointer to Render World.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to object manager.

 
static LParticleEngine2D * m_pParticleEngine = nullptr
 Pointer to particle engine.
 
static bool m_bEasterEgg = false
 Easter egg!
 

Detailed Description

The object manager.

The object manager is an abstract representation of all of the objects in the game.

Constructor & Destructor Documentation

◆ ~CObjectManager()

CObjectManager::~CObjectManager ( )

Destructor.

The destructor clears the object list, which destructs all of the objects in it.

Member Function Documentation

◆ AllCratesBelow()

const bool CObjectManager::AllCratesBelow ( float  h) const

Test all crates below height.

Parameters
hHeight in Render World units.
Returns
true if all crates have y-coordinate less than h.

◆ clear()

void CObjectManager::clear ( )

Reset to initial conditions.

Delete all of the entities managed by the object manager. This involves deleting all of the CObject instances pointed to by the object list, then clearing the object list itself.

◆ CreateCrate()

void CObjectManager::CreateCrate ( float  x,
float  y,
const b2FixtureDef &  fd 
)
private

Create a crate.

Create a crate in Physics World and Object World.

Parameters
xHorizontal coordinate in Physics World units.
yVertical coordinate in Physics World units.
fdCrate fixture definition.

◆ CreateObject()

void CObjectManager::CreateObject ( eSprite  t,
b2Body *  p 
)

Create new object.

Create an object in the object manager.

Parameters
tSprite type.
pPointer to Physics World body.

◆ CreateTower()

void CObjectManager::CreateTower ( )

Create a tower of crates.

Create a tower of crates at a hard-coded location.

◆ CreateWorldEdges()

void CObjectManager::CreateWorldEdges ( )

Create the edges of the world.

Create world edges in Physics World. Place Box2D edge shapes in the Physics World in places that correspond to the bottom, right, and left edges of the screen in Render World. The left and right edges continue upwards for a distance. There is no top to the world.

◆ EmitSmoke()

void CObjectManager::EmitSmoke ( const Vector2 &  p,
Vector2  v 
)

Emit a smoke particle.

Create a smoke particle using the front particle engine so that it appears in front of the cannon. This particle will scale in and fade out over its lifespan, which is hard-coded. Friction is added to make it slow down horizontally, and upward acceleration is added to make it appear to rise due to the high temperature of an expolosion.

Parameters
pInitial position.
vInitial velocity.