Box2D Binary Counter
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CBitCounter Class Reference

Single-bit counter. More...

#include <BitCounter.h>

Inheritance diagram for CBitCounter:
CCommon

Public Member Functions

 CBitCounter (float, float, bool=false)
 Constructor. More...
 
Vector2 GetPos ()
 Get position. More...
 

Private Member Functions

b2Body * CreateBlock (eSprite, float x, float, bool=true)
 Create a block. More...
 
b2Body * CreateRamp (float, float)
 Create a triangular ramp. More...
 

Private Attributes

b2Body * m_pArm = nullptr
 Pointer to the body of the swing arm in Physics World.
 

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 eGameState m_eGameState = eGameState::Start
 Current game state.
 
static CCounterm_pCounter = nullptr
 Pointer to a counter.
 
static UINT m_nCurNum = 0
 Current number.
 

Detailed Description

Single-bit counter.

A single-bit counter in Physics World, consisting of two blocks, a ramp, a swing-arm, and two legs.

Constructor & Destructor Documentation

◆ CBitCounter()

CBitCounter::CBitCounter ( float  x,
float  y,
bool  last = false 
)

Constructor.

A bit-counter consists of a rempt, a ledge, a block, an arm, and two legs. All except the last one, that is. The last one is just a ledge.

Parameters
xX-coordinate in Render World.
yY-coordinate in Render World.
lastTrue if this is the last bit-counter.

Member Function Documentation

◆ CreateBlock()

b2Body * CBitCounter::CreateBlock ( eSprite  t,
float  x,
float  y,
bool  stat = true 
)
private

Create a block.

Create a rectangular block in Physics World, given its Render World coordinates. Note that this is not relative to the location of the bit-counter.

Parameters
tSprite type.
xX-coordinate in Render World.
yY-coordinate in Render World.
stattrue for a static block, false for a dynamic one.

◆ CreateRamp()

b2Body * CBitCounter::CreateRamp ( float  x,
float  y 
)
private

Create a triangular ramp.

Create a static triangular ramp in Physics World, given its Render World coordinates. Note that this is not relative to the location of the bit-counter.

Parameters
xX-coordinate in Render World.
yY-coordinate in Render World.

◆ GetPos()

Vector2 CBitCounter::GetPos ( )

Get position.

Reader function for the position of the arm in Render World coordinates.

Returns
Position of the arm in Render World coordinates.