The Top-Down Tiled Game Prototype
A Basic Tiled Top-Down Shooter
Loading...
Searching...
No Matches
CGuard Class Reference

The guard object. More...

#include <Guard.h>

Inheritance diagram for CGuard:
Collaboration diagram for CGuard:

Public Member Functions

 CGuard (const Vector2 &, float)
 Constructor.
 
 ~CGuard ()
 Destructor.
 
void Move ()
 Move.
 
void Draw ()
 Draw.
 
- Public Member Functions inherited from CArmedObject
 CArmedObject (eObject, eSprite, const Vector2 &, float)
 Constructor.
 
virtual ~CArmedObject ()
 Destructor.
 
void CreateParticle (const Sage::CParticleDesc2D &)
 
- Public Member Functions inherited from CObject
 CObject (eObject, eSprite, const Vector2 &, float=0)
 Constructor.
 
virtual ~CObject ()
 Destructor.
 
void Draw ()
 Draw object.
 
const eObject GetType () const
 Get object type.
 
const Vector2 & GetPos () const
 Get position.
 

Protected Member Functions

const bool CloseToPlayer (const float) const
 Is close to player.
 
void CollisionResponse (const Vector2 &, float, CObject *=nullptr)
 Collision response.
 
void ChangeState (eState)
 Change state.
 
void DrawState ()
 Draw state text.
 
const std::wstring GetStateString () const
 Get state text.
 
- Protected Member Functions inherited from CArmedObject
const Vector2 GetViewVector () const
 Compute view vector.
 
const Vector2 GetGunOffset () const
 Get gun offset.
 
bool RotateTowards (const Vector2 &)
 Swivel towards position.
 
void DeathFX ()
 Death special effects.
 
- Protected Member Functions inherited from CObject

Protected Attributes

const UINT m_nMaxHealth = 4
 Maximum health.
 
UINT m_nHealth = m_nMaxHealth
 Current health.
 
eState m_eState = eState::Ready
 Guard state.
 
Sage::CEventTimer * m_pFrameEvent = nullptr
 Frame event timer.
 
Sage::CEventTimer * m_pGunFireEvent = nullptr
 Gun fire event.
 
- Protected Attributes inherited from CArmedObject
UINT m_nHealth = 1
 Current health.
 
float m_fRotSpeed = 0
 Rotational speed.
 
Vector2 m_vGunOffset
 Sprite gun offset.
 
Sage::CParticleEngine2D * m_pLocalParticleEngine = nullptr
 Pointer to particle engine.

 
- Protected Attributes inherited from CObject
eObject m_eObject = eObject::Unknown
 Object type.
 
eSprite m_eSprite = eSprite::Player
 Sprite type.
 
float m_fScale = 1.0f
 Scale.
 
Vector2 m_vPos
 Position.
 
float m_fRoll = 0
 Roll angle.
 
float m_fRadius = 0
 Damage bounding circle radius.
 
Vector2 m_vCenterOffset
 Sprite center offset.
 
float m_fCollisionRadius = 0.0f
 Collision radius.
 

Private Types

enum class  eState { Ready , Reloading }
 State of mind. More...
 

Friends

class CObjectManager
 Object manager needs access so it can manage.
 

Additional Inherited Members

- 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_bShowState = false
 Show NPC state flag.
 
static bool m_bShowBounds = false
 Draw bounding boxes and circles flag.
 

Detailed Description

The abstract representation of a guard.

Member Enumeration Documentation

◆ eState

enum class CGuard::eState
strongprivate

Possible states of mind for a guard.

Constructor & Destructor Documentation

◆ CGuard()

CGuard::CGuard ( const Vector2 & p,
float d )

Create and initialize a guard object given its position.

Parameters
pPosition of guard.
dInitial orientation of guard.

◆ ~CGuard()

CGuard::~CGuard ( )

The destructor deletes the event timers created by the constructor.

Member Function Documentation

◆ ChangeState()

void CGuard::ChangeState ( eState newState)
protected

Change state and perform any processing associated with entering the new state. Does nothing if there is no change in state, that is, the new state is the same as the current state.

Parameters
newStateThe new state.
Here is the caller graph for this function:

◆ CloseToPlayer()

const bool CGuard::CloseToPlayer ( const float d) const
protected

Player proximity test.

Parameters
dRequired distance to player.
Returns
true if within required distance of player.
Here is the call graph for this function:

◆ CollisionResponse()

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

Response to collision. If colliding with an object, play a sound.

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 CGuard::Draw ( )
virtual

Draw the sprite offset by the center offset.

Reimplemented from CArmedObject.

Here is the call graph for this function:

◆ DrawState()

void CGuard::DrawState ( )
protected

Draw the current state as a text string near the guard location on the screen.

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

◆ GetStateString()

const std::wstring CGuard::GetStateString ( ) const
protected

Get a string that describes the current state.

Returns
String that describes the current state.
Here is the caller graph for this function:

◆ Move()

void CGuard::Move ( )
virtual

Rotate the guard and fire the gun at at the closest available target if there is one.

Reimplemented from CArmedObject.

Here is the call graph for this function: