Box2D Cannon Game
Game Physics with a 2D Physics Engine
Loading...
Searching...
No Matches
CObjectManager Class Reference

The object manager. More...

#include <ObjectManager.h>

Inheritance diagram for CObjectManager:
Collaboration diagram for CObjectManager:

Public Member Functions

 CObjectManager ()
 Constructor.
 
 ~CObjectManager ()
 Destructor.
 
void CreateObject (eSprite, b2Body *)
 Create new object.
 
void CreateTower ()
 Create a tower of crates.
 
void CreateBackground (eSprite)
 Create background.
 
void clear ()
 Reset to initial conditions.
 
void Draw ()
 Draw all objects.
 
void MakeCollisionSounds ()
 Make sounds for all objects.
 
void EmitSmoke (const Vector2 &, Vector2)
 Emit a smoke particle.
 
const bool AllCratesBelow (float) const
 Test all crates below height.
 

Private Member Functions

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

Private Attributes

Sage::CParticleDesc2D 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 CBox2DRenderer * m_pRenderer = nullptr
 Pointer to Render World.
 
static CObjectManagerm_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!
 

Detailed Description

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

Constructor & Destructor Documentation

◆ ~CObjectManager()

CObjectManager::~CObjectManager ( )

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

Here is the call graph for this function:

Member Function Documentation

◆ AllCratesBelow()

const bool CObjectManager::AllCratesBelow ( float h) const
Parameters
hHeight in Render World units.
Returns
true if all crates have y-coordinate less than h.
Here is the caller graph for this function:

◆ clear()

void CObjectManager::clear ( )

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.

Here is the caller graph for this function:

◆ CreateBackground()

void CObjectManager::CreateBackground ( eSprite t)

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.

Parameters
tSprite type.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateCrate()

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

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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateObject()

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

Create an object in the object manager.

Parameters
tSprite type.
pPointer to Physics World body.
Here is the caller graph for this function:

◆ CreateTower()

void CObjectManager::CreateTower ( )

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EmitSmoke()

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

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.
Here is the caller graph for this function:

◆ MakeCollisionSounds()

void CObjectManager::MakeCollisionSounds ( )

Make collision sounds for all objects.

Here is the caller graph for this function: