The Cannon Lullaby Toy
Game Physics with a 2D Physics Engine
Loading...
Searching...
No Matches
CObject Class Reference

The game object. More...

#include <Object.h>

Inheritance diagram for CObject:
Collaboration diagram for CObject:

Public Member Functions

 CObject (eSprite, b2Body *)
 Constructor.
 
 ~CObject ()
 Destructor.
 
void draw ()
 Draw object in Render World.
 
void MakeCollide ()
 Unset the collision group index to enable collisions.
 
void SetBellRung ()
 Record that bell has been rung.
 
const bool GetBellRung () const
 Get whether bell has been rung.
 
const eSprite GetSpriteType () const
 Get sprite type.
 
const Vector2 GetPos () const
 Get position in Render World coordinates.
 
const float GetSpeed () const
 Get speed in Render World units.
 
const XMFLOAT4 & GetColor () const
 Get star color.
 
const float GetRingTime () const
 Get time bell was rung.
 
const bool EmitsStars () const
 Get star emission status.
 

Private Attributes

eSprite m_eSpriteType = eSprite(0)
 Sprite type.
 
b2Body * m_pBody = nullptr
 Physics World body.
 
bool m_bHasRungBell = false
 Whether bell has been hit by this object.
 
float m_fRingTime = 0
 Time bell was rung.
 
XMFLOAT4 m_f4Color
 Color overlay.
 

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

Game objects are responsible for remembering information about themselves, in particular, their representations in Render World and Physics World.

Constructor & Destructor Documentation

◆ CObject()

CObject::CObject ( eSprite t,
b2Body * b )

This constructor assumes that a Physics World body has already been created for this object. It then has responsibility for deleting it in its destructor.

Parameters
tSprite type.
bPointer to Physics World body.

◆ ~CObject()

CObject::~CObject ( )

This destructor assumes that Box2D hasn't been shut down yet.

Member Function Documentation

◆ draw()

void CObject::draw ( )

Draw in Render World. Position and orientation must be gotten from Physics World.

Here is the call graph for this function:

◆ EmitsStars()

const bool CObject::EmitsStars ( ) const

Only balls that haven't rung their bell emit stars.

Returns
true if this object is still emitting stars.

◆ GetBellRung()

const bool CObject::GetBellRung ( ) const

Reader function for the bell rung flag.

Returns
true if the bell has rung.

◆ GetColor()

const XMFLOAT4 & CObject::GetColor ( ) const

Reader function for the star color.

Returns
Star color for this object.

◆ GetPos()

const Vector2 CObject::GetPos ( ) const

Reader function for position in Render World.

Returns
Position in Render World coordinates.
Here is the call graph for this function:

◆ GetRingTime()

const float CObject::GetRingTime ( ) const

Reader function for the time that the bell was rung. No check is made whether the ring time is valid. The calling function must call GetBellRung() to fund out if it is.

Returns
The time that the bell was rung.

◆ GetSpeed()

const float CObject::GetSpeed ( ) const

Reader function for speed in Render World.

Returns
Speed in Render World units.
Here is the call graph for this function:

◆ GetSpriteType()

const eSprite CObject::GetSpriteType ( ) const

Reader function for sprite type.

Returns
Sprite type.
Here is the caller graph for this function:

◆ MakeCollide()

void CObject::MakeCollide ( )

Make ball that has rung its bell collide with other balls after half a second delay. The delay is to make sure that they get clear of their bell first so they don't collide with incoming balls.

◆ SetBellRung()

void CObject::SetBellRung ( )

Set the flag indicating that this object has rung its bell and record the TOI.

Here is the caller graph for this function: