The 8-ball Pool End Game
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Private Attributes | Friends | List of all members
CObject Class Reference

The game object. More...

#include <Object.h>

Inheritance diagram for CObject:
CCommon

Public Member Functions

 CObject (eSprite t, const Vector2 &p)
 Constructor. More...
 
void move ()
 Move object. More...
 
void draw ()
 Draw object. More...
 
void DropParticle (LParticleDesc2D *)
 Drop a particle. More...
 
void DeliverImpulse (float, float)
 Deliver an impulse. More...
 

Private Attributes

Vector2 m_vOldPos
 Previous position. Only needed for Step Mode.
 
Vector2 m_vVel
 Current velocity.
 
float m_fRadius = 0.0f
 Radius.
 
bool m_bInPocket = false
 Whether currently in a pocket.
 

Friends

class CObjectManager
 Object manager needs access so it can manage.
 

Additional Inherited Members

- Static Protected Attributes inherited from CCommon
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 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

The abstract representation of an object. CObjectManager is a friend of this class so that it can access any private members as needed to manage the objects without the need for reader and set functions for each private or protected member variable. This class must contain public member functions move() and draw() to move and draw the object, respectively.

Constructor & Destructor Documentation

◆ CObject()

CObject::CObject ( eSprite  t,
const Vector2 &  pos 
)

Create an object, given its sprite type and initial position.

Parameters
tType of ball.
posInitial position.

Member Function Documentation

◆ DeliverImpulse()

void CObject::DeliverImpulse ( float  a,
float  m 
)

React to an impulse of a given angle and magnitude. The velocity vector is instantaneously changed; no need to faff about with forces applied over time.

Parameters
aImpulse angle.
mImpulse magnitude.

◆ draw()

void CObject::draw ( )

Ask the renderer to draw the sprite described in the sprite descriptor. Note that CObject is derived from LBaseObject which is inherited from LSpriteDesc2D. Therefore LSpriteRenderer::Draw(const LSpriteDesc2D*) will accept this as a parameter, automatically down-casting it from CObject* to LSpriteDesc2D*, effectively drawing the object from its sprite descriptor.

◆ DropParticle()

void CObject::DropParticle ( LParticleDesc2D *  p)

Drop a particle using the back particle engine provided the object has actually moved in the last frame. This is intended to be used in Step Mode.

◆ move()

void CObject::move ( )

Move using Euler Integration, applying a constant amount of friction. Stop if the velocity is sufficiently small. Exactly what constitutes "sufficiently small" is hard-coded.