The Cannon Lullaby Toy
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 CreateWorldEdges ()
 Create the edges of the world.
 
void CreateObject (eSprite, b2Body *)
 Create object.
 
void CreateBells ()
 Create bells.
 
void ElevateFlower (UINT, float)
 Elevate flower.
 
void EmitSmoke (const Vector2 &, Vector2)
 Emit a smoke particle.
 
void clear ()
 Reset to initial conditions.
 
void Draw ()
 Draw all objects.
 
void step ()
 Animation step.
 
const bool AllBellsRung () const
 Whether all balls have rung their bells.
 

Private Member Functions

b2Body * CreateBell (eSprite, const Vector2 &)
 Create bell.
 
void DrawSunflowers ()
 Draw leaves.
 
void EmitStars ()
 Emit stars in the wake of each object.
 
void MakeBallsCollide ()
 Make balls collide after they have rung their bell.
 
void RemoveDeadBalls ()
 Remove collided balls after small delay.
 

Private Attributes

Sage::CParticleDesc2D m_cSmokeDesc
 Particle descriptor for smoke.
 
Sage::CParticleDesc2D m_cStarDesc
 Particle descriptor for star.
 
Sage::CParticleDesc2D m_cPopDesc
 Particle descriptor for ball pop.
 
std::vector< CObject * > m_stdList
 Object list.
 
b2Body * m_pBellBody [NUMBELLS] = {nullptr}
 Pointers to bell bodies.
 
b2Body * m_pEdges = nullptr
 Pointer to body for world edges and ledge.
 

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 the Object Manager.
 
static Sage::CParticleEngine2D * m_pFrontParticleEngine = nullptr
 Pointer to front particle engine.

 
static Sage::CParticleEngine2D * m_pBackParticleEngine = nullptr
 Pointer to front particle engine.
 
static CCannonm_pCannon = nullptr
 Pointer to a cannon.
 
static Vector2 m_vBellPos [NUMBELLS] = {Vector2(0.0f)}
 Positions of bells.
 
static float m_fGravity = 20.0f
 Magnitude of gravity in Render World units.
 
static eDrawMode m_eDrawMode = eDrawMode::Sprites
 Draw mode.
 

Detailed Description

An abstract representation of all of the objects in the game.

Constructor & Destructor Documentation

◆ CObjectManager()

CObjectManager::CObjectManager ( )

Initialize the sprite descriptors for the pop, start, and smole animations.

◆ ~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

◆ AllBellsRung()

const bool CObjectManager::AllBellsRung ( ) const

Test whether all bells have been rung.

Returns
true if all balls have rung their bells.
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:

◆ CreateBell()

b2Body * CObjectManager::CreateBell ( eSprite t,
const Vector2 & pos )
private

Create a single bell in both Render World and Physics World.

Parameters
tSprite type.
posPosition of the bell in Render World coordinates.
Returns
Pointer to bell body in Physics World.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateBells()

void CObjectManager::CreateBells ( )

NUMBELLS bells are created in hard-coded positions, and those positions are recorded in array m_vBellPos[NUMBELLS]. Assumes that there are NUMBELLS consecutive bell sprite types starting at eSprite::BellC.

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

◆ CreateObject()

void CObjectManager::CreateObject ( eSprite t,
b2Body * p )
Parameters
tSprite type.
pPointer to body in Physics World.
Here is the caller graph for this function:

◆ CreateWorldEdges()

void CObjectManager::CreateWorldEdges ( )

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 edge.

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

◆ Draw()

void CObjectManager::Draw ( )

Draw the game objects using Painter's Algorithm. The background is drawn first, then the game objects are asked to draw themselves in the order that they are in the object list. That is, they are drawn from back to front.

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

◆ DrawSunflowers()

void CObjectManager::DrawSunflowers ( )
private

Draw sunflowers consisting of a line for the stem, a flower at the top, and a series of even;y spaced leaves going up the stem, getting smaller with height.

Here is the caller graph for this function:

◆ ElevateFlower()

void CObjectManager::ElevateFlower ( UINT n,
float d )

Manually changes a flower's height in both the Object Manager and Physics World.

Parameters
nFlower index.
dAmount to add to its height.
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:

◆ EmitStars()

void CObjectManager::EmitStars ( )
private

Emit a star particle behind each ball that is flagged as an emitter of stars. They go into the back particle engine so that the balls are draw on top of them.

Here is the caller graph for this function:

◆ MakeBallsCollide()

void CObjectManager::MakeBallsCollide ( )
private

Ask all balls to make themselves collidable if their state allows it.

Here is the caller graph for this function:

◆ RemoveDeadBalls()

void CObjectManager::RemoveDeadBalls ( )
private

Get rid of cannonballs after they have rung their bell and 10 seconds have elapased since the time they rang it. Play a sound and emit a particle too.

Here is the caller graph for this function:

◆ step()

void CObjectManager::step ( )

Emit stars from the flying cannon balls, make them collide with each other after they hit, and then remove them after a decent interval.

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