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

A car consisting of a body and two wheels, and a bridge to run on.

#include <Car.h>

Inheritance diagram for CCarAndBridge:
Collaboration diagram for CCarAndBridge:

Public Member Functions

 CCarAndBridge ()
 Constructor.
 
 ~CCarAndBridge ()
 Destructor.
 
void Move ()
 Reverse the car when it gets near the edges.
 
void Action ()
 Reverse the car.
 
- Public Member Functions inherited from CLevel
 CLevel (eSprite)
 
virtual ~CLevel ()
 Default constructor.
 
virtual void Draw ()
 Draw objects in level.
 

Private Member Functions

void CreateCar (float, float)
 Create the car.
 
b2Body * CreateCarBody (float, float)
 Create the car body.
 
b2Body * CreateWheel (float, float)
 Create a wheel.
 
void CreateBridge (float x, float y)
 Create bridge from platforms & ramps.
 
void CreatePlatform (float, float)
 Create a platform.
 
void CreateRampDown (float, float)
 Create a down ramp.
 
void CreateRampUp (float, float)
 Create an up ramp.
 

Private Attributes

b2WheelJoint * m_pWheelJoint1 = nullptr
 Pointer to a wheel joint.
 
b2WheelJoint * m_pWheelJoint2 = nullptr
 Pointer to a wheel joint.
 
CObjectm_pCarObject = nullptr
 Pointer to car object.
 

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.
 

Constructor & Destructor Documentation

◆ CCarAndBridge()

CCarAndBridge::CCarAndBridge ( )

Create a car and a bridge for it to run on.

Here is the call graph for this function:

Member Function Documentation

◆ Action()

void CCarAndBridge::Action ( )
virtual

Reverse the car by changing the sign of the motor speed on the wheel joints.

Reimplemented from CLevel.

Here is the caller graph for this function:

◆ CreateBridge()

void CCarAndBridge::CreateBridge ( float x,
float y )
private

Create the bridge from platforms and ramps.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateCar()

void CCarAndBridge::CreateCar ( float x,
float y )
private

Create the car body and wheels and attach the wheels to the body using wheel joints.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateCarBody()

b2Body * CCarAndBridge::CreateCarBody ( float x,
float y )
private

Create the car object with its body at a given point in Physics World.

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

◆ CreatePlatform()

void CCarAndBridge::CreatePlatform ( float x,
float y )
private

Create a horizontal platform.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateRampDown()

void CCarAndBridge::CreateRampDown ( float x,
float y )
private

Creat a ramp going down from left to right.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateRampUp()

void CCarAndBridge::CreateRampUp ( float x,
float y )
private

Creat a ramp going up from left to right.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateWheel()

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

Create a car wheel at a given point in Physics World.

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

◆ Move()

void CCarAndBridge::Move ( )
virtual

Ensure that the car reverses direction before hitting the left or right edge of the window. All other aspects of motion are, of course, handled by Box2D. This function assumes that the car wass the first object created.

Reimplemented from CLevel.

Here is the call graph for this function: