The 8-ball Pool End Game
Game Physics with Bespoke Code
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 Create (eSprite, const Vector2 &)
 Create new object.
 
void Clear ()
 Reset to initial conditions.
 
void Move ()
 Move all objects.
 
void Draw ()
 Draw all objects.
 
void ResetImpulseVector ()
 Reset the Impulse Vector.
 
void AdjustImpulseVector (float)
 Adjust the Impulse Vector.
 
void AdjustCueBall (float)
 Move cue-ball up or down.
 
void Shoot ()
 Shoot the cue ball.
 
bool BallDown ()
 Is a ball down in a pocket?
 
bool CueBallDown ()
 Is the cue ball down in a pocket?
 
bool AllStopped ()
 Have all balls stopped moving?
 

Private Member Functions

void BroadPhase ()
 Ball, rail, and pocket collision response.
 
void NarrowPhase (CObject *, CObject *)
 Collision response for two balls.
 
void RailCollide (CObject *)
 Collision response for ball with rail.
 
void PocketCollide (CObject *)
 Collision response for ball with pocket.
 

Private Attributes

Sage::CParticleDesc2D m_cPDesc0
 Particle descriptor for balls in step mode.
 
Sage::CParticleDesc2D m_cPDesc1
 Particle descriptor for collisions in step mode.
 
Sage::CParticleDesc2D m_cPDesc2
 Particle descriptor for collisions in real-time mode.
 
CObjectm_pCueBall = nullptr
 Cue ball object pointer.
 
CObjectm_p8Ball = nullptr
 8 ball object pointer.
 
float m_fCueAngle = 0
 Cue ball impulse angle.
 
bool m_bDrawImpulseVector = true
 Whether to draw the impulse vector.
 

Additional Inherited Members

- Static Protected Attributes inherited from CCommon
static Sage::CSpriteRenderer * m_pRenderer = nullptr
 Pointer to the renderer.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to the object manager.
 
static Sage::CParticleEngine2D * m_pParticleEngine = nullptr
 Pointer to particle engine.
 
static bool m_bShowCollisions = false
 Show ball positions at TOI.
 
static bool m_bStepMode = false
 Is in step mode.
 
static bool m_bStep = false
 Step flag.
 
static float m_fXMargin = 78.0f
 Horizontal margin.
 
static float m_fYMargin = 64.0f
 Vertical margin.
 
static Vector2 m_vMargin = Vector2(m_fXMargin, m_fYMargin)
 Margins.
 
static Vector2 m_vTopLPocket = Vector2(71, 478)
 Position of top left pocket.
 
static Vector2 m_vTopRPocket = Vector2(955, 478)
 Position of top right pocket.
 
static Vector2 m_vTopCPocket = Vector2(514, 478)
 Position of top center pocket.
 
static Vector2 m_vBotLPocket = Vector2(71, 53)
 Position of bottom left pocket.
 
static Vector2 m_vBotRPocket = Vector2(955, 53)
 Position of bottom right pocket.
 
static Vector2 m_vBotCPocket = Vector2(514, 48)
 Position of bottom center pocket.
 

Detailed Description

A managed collection of all of the game objects.

Constructor & Destructor Documentation

◆ CObjectManager()

CObjectManager::CObjectManager ( )

Initialize the sprite descriptors for the circle and thick circle particles used to show discrete motion and collision points.

◆ ~CObjectManager()

CObjectManager::~CObjectManager ( )

Delete the cue-ball and 8-ball objects.

Member Function Documentation

◆ AdjustCueBall()

void CObjectManager::AdjustCueBall ( float d)

Adjust the cue ball up or down on the base line, being careful stop it at the horizontal rails. This should only be used in eGameState::Initial, but no check is made here.

Parameters
dDistance to move by.
Here is the caller graph for this function:

◆ AdjustImpulseVector()

void CObjectManager::AdjustImpulseVector ( float a)

Adjust the angle of the impulse vector. This should only be used in eGameState::Initial or eGameState::SetupShot, but no check is made here.

Parameters
aAmount to add to the angle of the impulse vector.
Here is the caller graph for this function:

◆ AllStopped()

bool CObjectManager::AllStopped ( )

Check whether both the cue-ball and the 8-ball have stopped moving. Notice that we can set the velocity vector to the zero vector and expect it to succeed because CObject::move zeros out the velocity of slow-moving objects.

Returns
true If both balls have stopped moving.
Here is the caller graph for this function:

◆ BallDown()

bool CObjectManager::BallDown ( )

Check whether the cue-ball or the 8-ball is in a pocket.

Returns
true If one of the balls is in a pocket.
Here is the caller graph for this function:

◆ BroadPhase()

void CObjectManager::BroadPhase ( )
private

Collision detection and response for all balls against each other and the rails and pockets. We do pocket collision for all balls first to remove them from the subsequent calculations.

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

◆ Clear()

void CObjectManager::Clear ( )

Delete all of the objects in the game. Ideally this should consist of a switch statement, but there are only two objects here, the cue-ball and the 8-ball.

Here is the caller graph for this function:

◆ Create()

void CObjectManager::Create ( eSprite t,
const Vector2 & v )

Create an object and save a pointer to it. Ideally this should consist of a switch statement, but there are only two objects here, the cue-ball and the 8-ball.

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

◆ CueBallDown()

bool CObjectManager::CueBallDown ( )

Check whether the cue-ball is down a pocket.

Returns
true If the cue-ball is in a pocket.
Here is the caller graph for this function:

◆ Draw()

void CObjectManager::Draw ( )

Draw all of the objects in the game, two balls, the directional arrow, and the step mode indicator and the collision indicator if necessary.

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

◆ Move()

void CObjectManager::Move ( )

Move all of the objects in the object list and perform broad phase collision detection and response. If in Step Mode, drop a particle.

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

◆ NarrowPhase()

void CObjectManager::NarrowPhase ( CObject * p0,
CObject * p1 )
private

Ball to ball collision detection and response. Deflect the balls in the appropriate directions and speeds, and play a sound at the point of impact at a volume proportional to the relative speed of at time of impact. See Section 5.2.1 of the documentation for details of the geometry used here.

Parameters
p0Pointer to first object.
p1Pointer to first object.
Here is the caller graph for this function:

◆ PocketCollide()

void CObjectManager::PocketCollide ( CObject * b)
private

Collision detection and response for ball-in-pocket. Check for a collision and does the necessary housework for disabling a ball that is in a pocket. If there is a collision, a sound is played at a volume proportional to the speed of collision and panned to the left or right according to where the pocket is on the table.

Parameters
bPointer to a ball object to collide with pockets.
Here is the caller graph for this function:

◆ RailCollide()

void CObjectManager::RailCollide ( CObject * b)
private

Collision detection and response for ball hitting any rail. Check for a collision and do the necessary housework for reflecting the ball if it hits a rail. If there is a collision, a sound is played at a volume proportional to the speed of collision at the point of impact. See Section 5.2.2 of the documentation for details of the geometry used here.

Parameters
bPointer to a ball object to collide with rails.
Here is the caller graph for this function:

◆ ResetImpulseVector()

void CObjectManager::ResetImpulseVector ( )

Make the impulse vector point from the center of the cue-ball to the center of the 8-ball and set it as visible so it gets drawn (assuming that the only reason to reset the impulse vector is because it needs to be drawn).

Here is the caller graph for this function:

◆ Shoot()

void CObjectManager::Shoot ( )

Shoot the cue-ball by giving it a fixed impulse. Disable the drawing of the impulse vector and play a sound that is panned left or right depending on where the cue-ball is on the table.

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