The Top Down Game Prototype
A Basic 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 &)
 Constructor.
 
 ~CGuard ()
 Destructor.
 
void Move ()
 Move.
 
void Draw ()
 Draw.
 
- Public Member Functions inherited from CArmedObject
 CArmedObject (eObject, eSprite, const Vector2 &)
 Constructor.
 
virtual ~CArmedObject ()
 Destructor.
 
void CreateParticle (const Sage::CParticleDesc2D &)
 
- Public Member Functions inherited from CObject
 CObject (eObject, eSprite, const Vector2 &)
 Constructor.
 
virtual ~CObject ()
 Destructor.
 
const eObject GetType () const
 Get object type.
 

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 Attributes

eState m_eState = eState::Alert
 Guard state.
 
bool m_bCCW = true
 Whether to scan counterclockwise.
 
Sage::CEventTimer * m_pWaitEvent = nullptr
 Wait event.
 
Sage::CEventTimer * m_pAlertEvent = nullptr
 Alert event.
 
Sage::CEventTimer * m_pScanningEvent = nullptr
 Scanning event.
 
Sage::CEventTimer * m_pFrameEvent = nullptr
 Stray 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_vCenterOffset
 Sprite center offset.
 
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.
 
Vector2 m_vPos
 Position.
 
float m_fRoll = 0
 Roll angle.
 
float m_fRadius = 0
 Bounding circle radius.
 

Private Types

enum class  eState { Alert , Waiting , Scanning , 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 CPlayerm_pPlayer = nullptr
 Pointer to player character.
 
static bool m_bGodMode = false
 God mode flag.
 
static bool m_bShowState = false
 Show NPC state flag.
 
static bool m_bShowBounds = false
 Show collision circle 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)

Create and initialize a guard object given its position.

Parameters
pPosition of guard.
Here is the call graph for this function:

◆ ~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:
Here is the caller graph for this function:

◆ CollisionResponse()

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

Response to collision. If colliding with a bullet, play a sound, decrement health, and if health is zero then die.

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 current frame of the sprite offset by the center offset value. The current frame will be 0 if not reloading. Change state from Reloading to Waiting once the reloading animation has finished.

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. This will be used to draw the guard's current state on the screen if the player so desires.

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

◆ Move()

void CGuard::Move ( )
virtual

Take action based on state.

Reimplemented from CArmedObject.

Here is the call graph for this function: