Box2D Joint Toy
Game Physics with a 2D Physics Engine
Loading...
Searching...
No Matches
CPulley Class Reference

The pulley class. More...

#include <Pulley.h>

Inheritance diagram for CPulley:
Collaboration diagram for CPulley:

Public Member Functions

 CPulley ()
 Constructor.
 
void Move ()
 Rotate the pulley wheels.
 
void Action ()
 Create or delete elephant.
 
- Public Member Functions inherited from CLevel
 CLevel (eSprite)
 
virtual ~CLevel ()
 Default constructor.
 
virtual void Draw ()
 Draw objects in level.
 

Private Member Functions

void CreateGround ()
 Create the ground.
 
b2Body * CreateWheel (float, float)
 Create a pulley wheel.
 
b2Body * CreateCrate (float, float)
 Create the elephant's crate.
 
b2Body * CreateObject (const b2Vec2 &, float, eSprite)
 Create an object.
 

Private Attributes

b2PulleyJoint * m_pJoint = nullptr
 Pointer to the pulley joint.
 
float m_fJointLenA = 0
 Length of left side of pulley.
 
b2Body * m_pWheel0 = nullptr
 Pointer to the left pulley wheel.
 
b2Body * m_pWheel1 = nullptr
 Pointer to the right pulley wheel.
 
float m_fWheelRad = 1
 Pulley wheel radius.
 
b2Vec2 m_vElephantSpawnPt
 Elephant spawn point.
 
bool m_bHasElephant = false
 Has elephant flag.
 

Additional Inherited Members

- Protected Member Functions inherited from CLevel
CLineObjectCreateLine (b2Body *, const b2Vec2 &, bool, b2Body *, const b2Vec2 &, bool)
 Create new line object.
 
- Protected Attributes inherited from CLevel
std::vector< CObject * > m_stdObject
 Object pointers.
 
std::vector< CLineObject * > m_stdLine
 Line list.
 
eSprite m_eBgSprite
 Type of background sprite.
 
- Static Protected Attributes inherited from CCommon
static b2World * m_pPhysicsWorld = nullptr
 Pointer to Box2D Physics World.
 
static CBox2DRenderer * m_pRenderer = nullptr
 Pointer to the renderer.
 
static CLevelm_pLevel = nullptr
 Pointer to current level.
 
static eLevel m_eCurLevel = eLevel::Windmill
 Current level.
 
static eDrawMode m_eDrawMode = eDrawMode::Sprites
 Draw mode.
 

Detailed Description

A pair of objects connected by a pulley joint, with a pair of pulley wheels that are animated in code.

Member Function Documentation

◆ Action()

void CPulley::Action ( )
virtual

If there is an elephant, then delete it. If there is no elephant, then create one at its spawn point offset by a small pseudo-random amount to make the crate swing about. This function assumes that the elephant is the last thing created, that is, it is the last thing in the object list.

Reimplemented from CLevel.

Here is the call graph for this function:

◆ CreateCrate()

b2Body * CPulley::CreateCrate ( float x,
float y )
private

The bucket is the thing on the left that the elephant falls into. It consists of a left side, a right side, and a bottom, all of which are rectangles.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.
Returns
Pointer to physics body.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateGround()

void CPulley::CreateGround ( )
private

Create the ground, which is an edge in Physics World at the bottom of the window.

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

◆ CreateObject()

b2Body * CPulley::CreateObject ( const b2Vec2 & v,
float d,
eSprite t )
private

Create an object, used for the safe and the elephant.

Parameters
vPosition in Physics World.
dObject density.
tType of object to be created.
Returns
Pointer to physics body.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateWheel()

b2Body * CPulley::CreateWheel ( float x,
float y )
private

The pulley wheels are going to be static objects that we rotate ourselves depending on the positions of the objects that the pulley is attached to.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.
Returns
Pointer to physics body.
Here is the caller graph for this function:

◆ Move()

void CPulley::Move ( )
virtual

Animate the pulley wheels by setting their orientations to reflect the amount of rope that has gone over them.

Reimplemented from CLevel.