Tiled Platformer Prototype
A Basic Tiled Platformer
Loading...
Searching...
No Matches
CPlayer Class Reference

The player object. More...

#include <Player.h>

Inheritance diagram for CPlayer:
Collaboration diagram for CPlayer:

Public Member Functions

 CPlayer (const Vector2 &)
 Constructor.
 
 ~CPlayer ()
 Destructor.
 
void Move ()
 Move player object.
 
void Draw ()
 Draw.
 
void SetAction (const eAction, const eDirection=eDirection::Continue)
 Set action.
 
const Vector2 & GetPos () const
 Get position.
 
const eAction GetAction () const
 Get current action.
 
const bool IsAlive () const
 True if alive.
 
- Public Member Functions inherited from CObject
 CObject (eObject, eSprite, const Vector2 &)
 Constructor.
 
virtual ~CObject ()
 Destructor.
 
void Move ()
 Move object.
 
void Draw ()
 Draw object.
 
const eObject GetType () const
 Get object type.
 

Private Member Functions

void CollisionResponse (const Vector2 &, float, CObject *=nullptr)
 Collision response.
 
void BloodSpray (const Vector2 &)
 Create a spray of blood.
 

Private Attributes

UINT m_nHealth = 1
 Health.
 
eAction m_eAction = eAction::Standing
 Current action.
 
eDirection m_eDirection = eDirection::Right
 Current direction.
 
bool m_bOnGround = false
 True if on ground.
 
Sage::CEventTimer * m_pFrameEvent = nullptr
 Frame event timer.
 

Additional Inherited Members

- Protected Member Functions inherited from CObject
- Protected Attributes inherited from CObject
eObject m_eObject = eObject::Unknown
 Object type.
 
eSprite m_eSprite = eSprite::Saw
 Sprite type.
 
Vector2 m_vPos
 Position.
 
float m_fRoll = 0
 Roll angle.
 
float m_fRadius = 0
 Collision radius.
 
Vector2 m_vVelocity
 Velocity.
 
bool m_bStatic = true
 Is static (does not move).
 
- Static Protected Attributes inherited from CCommon
static Sage::CSpriteRenderer * m_pRenderer = nullptr
 Pointer to renderer.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to object manager.
 
static Sage::CParticleEngine2D * m_pParticleEngine = nullptr
 Pointer to particle engine.
 
static CTileManagerm_pTileManager = nullptr
 Pointer to tile manager.
 
static CPlayerm_pPlayer = nullptr
 Pointer to player character.
 
static Vector2 m_vWorldSize
 World height and width.
 
static bool m_bGodMode = false
 God mode flag.
 
static bool m_bShowBounds = false
 Draw bounding boxes and circles flag.
 
static eGameState m_eGameState = eGameState::Loading
 Game state.
 

Detailed Description

The abstract representation of the player object. The player differs from the other objects in the game in that it moves in respond to device inputs.

Constructor & Destructor Documentation

◆ CPlayer()

CPlayer::CPlayer ( const Vector2 & p)

Create and initialize a player object.

Parameters
pInitial position of player.

◆ ~CPlayer()

CPlayer::~CPlayer ( )

The destructor deletes the event timer created by the constructor.

Member Function Documentation

◆ BloodSpray()

void CPlayer::BloodSpray ( const Vector2 & norm)
private

Create a particle effect for a spray of blood.

Parameters
normContact normal.
Here is the caller graph for this function:

◆ CollisionResponse()

void CPlayer::CollisionResponse ( const Vector2 & norm,
float d,
CObject * pObj = nullptr )
privatevirtual

Response to collision. If the object being collided with is a bullet, then play a sound, otherwise call CObject::CollisionResponse for the default collision response.

Parameters
normCollision normal.
dOverlap distance.
pObjPointer to object being collided with (defaults to nullptr, which means collision with a wall).

Reimplemented from CObject.

Here is the call graph for this function:

◆ Draw()

void CPlayer::Draw ( )

Draw the sprite.

Here is the call graph for this function:

◆ GetAction()

const eAction CPlayer::GetAction ( ) const

Reader function for action.

Returns
Action.
Here is the caller graph for this function:

◆ GetPos()

const Vector2 & CPlayer::GetPos ( ) const

Reader function for position.

Returns
Position.
Here is the caller graph for this function:

◆ IsAlive()

const bool CPlayer::IsAlive ( ) const

Test whether alive.

Returns
True if not dead or dying.
Here is the caller graph for this function:

◆ Move()

void CPlayer::Move ( )

Move in response to device input. The amount of motion is proportional to the frame time.

Here is the call graph for this function:

◆ SetAction()

void CPlayer::SetAction ( const eAction action,
const eDirection d = eDirection::Continue )

Set action and direction. If the new action is eAction::Dying and the current action is not eAction::Dying, then restart the frame event and play a death sound. If the new action is not eAction::Jumping or the current action is not eAction::Walking, then change the current action to the new action. If the new direction is not eDirection::Continue then change the current direction to the new direction, otherwise leave it the same.

Parameters
actionThe new action.
dThe new direction of action, defaults to eDirection::Continue.
Here is the caller graph for this function: