The Stroop Test Game
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.
 
void CreateRandomWord ()
 Create random word. More...
 
void CreateWorldEdges ()
 Create world edges. More...
 
void CreateStroopEdges ()
 Create edges of Stroop caricature. More...
 
void clear ()
 Reset to initial conditions. More...
 
void Update ()
 Update all objects. More...
 
void Draw ()
 Draw all objects. More...
 
void DrawGameText ()
 Draw game text. More...
 
void DrawScores ()
 Draw scores. More...
 
void DeactivateCurrent ()
 Expire all objects. More...
 
void MakeCurrentExplode ()
 Make the current word explode into characters. More...
 
void MakeAllExplode ()
 Make all words explode into characters. More...
 
void ProcessShutdown ()
 Initiate shutdown if the game is finished. More...
 
void EmitParticle (const LParticleDesc2D &)
 
void StroopWatchesCount ()
 
float GetCurrentHt ()
 Get the height of the current word. More...
 
Vector2 GetCurrentPos ()
 Get the position of the current word. More...
 
const size_t GetSize () const
 Get number of objects. More...
 

Private Member Functions

void ExplodeOldWords ()
 Explode old words. More...
 
void ExplodeOldLetters ()
 Explode old letters. More...
 
bool AnimateJointExplosion (CObject *)
 Animate a joint explosion. More...
 
void EmitSpark (const Vector2 &, const Vector2 &)
 Emit a spark. More...
 
void EmitSmoke (const Vector2 &, const Vector2 &)
 Emit a puff of smoke. More...
 
void CreateWord (const b2Vec2 &, char *, float, eWordColor)
 
CObjectCreateObject (const CObjDesc &)
 V Create word. More...
 
void LoadSnideComment ()
 Load snide comment into character buffers. More...
 
void DrawScore (LSpriteDesc2D &, int)
 Draw score, which may be negatve. More...
 

Private Attributes

std::string m_strSnarky
 A snarky comment.
 
std::vector< CObject * > m_stdList
 Object list.
 
Vector2 m_vSize
 Width and height of Render World.
 
bool m_bShuttingDown = false
 Are we shutting down?
 
UINT m_nNumCurrent = 0
 Number of characters in the current word.
 
CStroop m_cStroop
 Stroop caricature.
 

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 the Renderer.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to the Object Manager.
 
static LParticleEngine2D * m_pParticleEngine = nullptr
 Pointer to particle engine.

 
static CVectorFieldm_pVectorField = nullptr
 Pointer to a vector field.
 
static CBubbleEnginem_pBubbleEngine = nullptr
 Pointer to a bubble engine.
 
static bool m_bDrawVectors = false
 Do we draw the vector field?
 
static bool m_bDrawPressure = false
 Do we draw the pressures from the vector field?
 
static bool m_bDrawPoints = false
 Do we draw the points from the vector field?
 
static bool m_bDrawParticles = true
 Do we draw particles?
 
static eWordColor m_eCurColor = eWordColor::Black
 Color of the current word.
 
static bool m_bTried = false
 Whether the player has tried on the current word.
 
static UINT m_nWordCnt = INITIAL_WORDCOUNT
 Number of words.
 
static UINT m_nScore = 0
 Current score, can be negatice.
 
static UINT m_nDelivered = 0
 Number of words delivered.
 
static UINT m_nExcellent = 0
 Number of words scored as excellent.
 
static UINT m_nGood = 0
 Number of words scored as excellent.
 
static UINT m_nFair = 0
 Number of words scored as excellent.
 
static UINT m_nFailed = 0
 Number of words the player got wrong.
 
static UINT m_nMissed = 0
 Number of words the player did not attempt.
 
static eGameState m_eGameState = eGameState::Instructions
 Current game state.
 
static UINT m_nCntdownNum = 0
 The number we are displaying in the countdown.
 

Detailed Description

The Object Manager.

An abstract representation of the objects in the game.

Member Function Documentation

◆ AnimateJointExplosion()

bool CObjectManager::AnimateJointExplosion ( CObject p)
private

Animate a joint explosion.

Animate the explosion of a joint using the particle engine and vector field.

Parameters
pPointer to an object.

◆ clear()

void CObjectManager::clear ( )

Reset to initial conditions.

Reset back to initial conditions. This involves deleting all of the CObject instances pointed to by the object list, then clearing the object list itself.

◆ CreateObject()

CObject * CObjectManager::CreateObject ( const CObjDesc d)
private

V Create word.

Create new object.

Create an object of a specified type, enter it into the object list, and return a pointer to it.

Parameters
dObject descriptor.
Returns
Pointer to the object created.

◆ CreateRandomWord()

void CObjectManager::CreateRandomWord ( )

Create random word.

Create a word that reads "red", "green", or "blue" pseudorandomly, to be rendered in red, green, or blue chosen pseudorandomly. The initial position of the word is pseudorandmly offset a small amount from the window center line, just above the window so that it is initially out of sight.

◆ CreateStroopEdges()

void CObjectManager::CreateStroopEdges ( )

Create edges of Stroop caricature.

Create the edges in the Stroop outline so that the words and characters will bounce off him in a satisfactory manner. I laboriously copied down points on Stroop's outline from a screenshot using an image editor when I was too tired to do any real work yet too jazzed up to relax.

◆ CreateWord()

void CObjectManager::CreateWord ( const b2Vec2 &  pos,
char *  txt,
float  s,
eWordColor  clr 
)
private
Parameters
posPosition in Physics World.
txtWord in text format, zero terminated.
sScale.
clrColor that text is to be rendered in.

◆ CreateWorldEdges()

void CObjectManager::CreateWorldEdges ( )

Create world edges.

Create world edges in Physics World. Place Box2D edge shapes in the Physics World in places that correspond to the top, 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.

◆ DeactivateCurrent()

void CObjectManager::DeactivateCurrent ( )

Expire all objects.

Make the current word's color eWordColor::Black.

◆ Draw()

void CObjectManager::Draw ( )

Draw all objects.

Draw the game objects using Painter's Algorithm. Draw the eSprite::Background first, then the objects in the object list, then the particles in the particle engine.

draw objects in object list

◆ DrawGameText()

void CObjectManager::DrawGameText ( )

Draw game text.

Draw game text appropriate to the game state, including the countdown timer.

◆ DrawScore()

void CObjectManager::DrawScore ( LSpriteDesc2D &  d,
int  n 
)
private

Draw score, which may be negatve.

Draw a single score. It is assumed that the score is greater than -100 and less than or equal to 100. Bad things happen otherwise.

Parameters
d[in, out] Sprite descriptor.
nScore.

◆ DrawScores()

void CObjectManager::DrawScores ( )

Draw scores.

Draw scores to the window, hopefully over the top of the dashboard, which we assume has been drawn already.

◆ EmitParticle()

void CObjectManager::EmitParticle ( const LParticleDesc2D &  d)

Create a particle using the front particle engine. This is a public member function because the contact listener needs to call it.

Parameters
dParticle descriptor.

◆ EmitSmoke()

void CObjectManager::EmitSmoke ( const Vector2 &  pos,
const Vector2 &  vel 
)
private

Emit a puff of smoke.

Create a smoke particle using the front particle engine.

Parameters
posPosition in Render World coordinates.
velVelocity in Render World units.

◆ EmitSpark()

void CObjectManager::EmitSpark ( const Vector2 &  pos,
const Vector2 &  vel 
)
private

Emit a spark.

Create a spark particle using the front particle engine.

Parameters
posPosition in Render World coordinates.
velVelocity in Render World units.

◆ ExplodeOldLetters()

void CObjectManager::ExplodeOldLetters ( )
private

Explode old letters.

Explode any individuals letters left over from old words.

◆ ExplodeOldWords()

void CObjectManager::ExplodeOldWords ( )
private

Explode old words.

Find all objects in the object list that are not eWordColor::Gray and are older than WORD_EXPLODE_DELAY and trigger a joint explosion if they are in a joint.

◆ GetCurrentHt()

float CObjectManager::GetCurrentHt ( )

Get the height of the current word.

Get the height of the current word, which is defined to be the average height of the characters in it.

Returns
Average height of current word in Render World units.

◆ GetCurrentPos()

Vector2 CObjectManager::GetCurrentPos ( )

Get the position of the current word.

Get the position of the current word in Render World units. This is obtained by averaging the positions of the letters in it.

Returns
Position of the current word in Render WOrld coordinates.

◆ GetSize()

const size_t CObjectManager::GetSize ( ) const

Get number of objects.

Reader function for number of objects in the object list.

Returns
Number of objects in object list.

◆ LoadSnideComment()

void CObjectManager::LoadSnideComment ( )
private

Load snide comment into character buffers.

Load a snide comment based on score achieved into the character buffers.

◆ MakeAllExplode()

void CObjectManager::MakeAllExplode ( )

Make all words explode into characters.

Make all words explode by resetting their birth time close to the current time.

◆ MakeCurrentExplode()

void CObjectManager::MakeCurrentExplode ( )

Make the current word explode into characters.

Make the current word explode by resetting its birth time close to the current time.

◆ ProcessShutdown()

void CObjectManager::ProcessShutdown ( )

Initiate shutdown if the game is finished.

Shutdown process to be called when all of the words have been presented to the player.

◆ StroopWatchesCount()

void CObjectManager::StroopWatchesCount ( )

Make the Stroop caricature's eyes swivel towards the current word.

◆ Update()

void CObjectManager::Update ( )

Update all objects.

Update all of the objects in the object list, explode the old words, move the particles in the particle engine, and update the vector field and the Stroop animation.