Ned's Turkey Farm
A Simple 2.5D Side Scroller
Loading...
Searching...
No Matches
CCrowObject Class Reference

Crow object. More...

#include <CrowObject.h>

Inheritance diagram for CCrowObject:
Collaboration diagram for CCrowObject:

Public Member Functions

 CCrowObject (const Vector3 &)
 Constructor.
 
void Move ()
 Move depending on time and speed.
 
- Public Member Functions inherited from CObject
 CObject ()
 Default constructor.
 
 CObject (eSprite, const Vector3 &)
 Constructor.
 
virtual ~CObject ()
 Destructor.
 
void Kill ()
 Kill the object.
 
bool TooOld ()
 Kill me.
 
void GetRenderList (std::vector< Sage::CSpriteDesc3D > &)
 Get render list.
 
const Vector3 & GetPos () const
 Get position.
 
const Vector3 & GetVel () const
 Get velocity.
 
const float GetRoll () const
 Get roll angle.
 
const eSprite GetType () const
 Get sprite type.
 
virtual void SetVel (const Vector3 &)
 Set velocity.
 
virtual void SetRoll (float)
 Set roll angle.
 
void SetRotSpeed (float)
 Set roll speed.
 
void SetLifeTime (float)
 Set lifetime.
 
- Public Member Functions inherited from CCommon
float Wrap (float)
 Wrap horizontal distance.
 

Private Types

enum  eState { Cruising , Avoiding }
 Mental states for the crow. More...
 

Private Member Functions

void Think ()
 Artificial intelligence.
 
void CruisingAi ()
 Ai for cruising along.
 
void AvoidingAi ()
 Ai for avoiding plane.
 
void SetState (eState state)
 Change state.
 

Private Attributes

const float CLOSE_DISTANCE = 300.0f
 Distance for close to plane.
 
const float FAR_DISTANCE = 500.0f
 Distance for "far from" plane.
 
const float FALLBACK_HT = 150.0f
 Fall back at this vertical distance from plane.
 
const float BEHIND_DISTANCE = -5.0f
 Horizontal distance considered to be behind plane.
 
eState m_eState = eState::Cruising
 Current state.
 
Vector3 m_vPlanePos = Vector3::Zero
 Plane current position.
 
float m_fPlaneDist = FLT_MAX
 Euclidean distance to plane.
 
float m_fPlaneDistX = FLT_MAX
 Horizontal distance to plane.
 
float m_fPlaneDistY = FLT_MAX
 Vertical distance to plane.
 
float m_fMaxAltitude = 0.0f
 Maximum altitude.
 
float m_fMinAltitude = 0.0f
 Minimum altitude.
 
float m_fDeltaAltitude = 0.0f
 Change in altitude.
 
float m_fDesiredHeight = 0.0f
 Desired altitude.
 
float m_fHeightTime = 0.0f
 Time between height changes.
 
float m_fHeightDelayTime = 0.0f
 Time to next height change.
 
float m_fSpeedVariationTime = 0.0f
 Last time speed varied.
 
float m_fSpeedVariationDuration = 0.0f
 Time to next speed variation.
 
float m_fLastAiTime = 0.0f
 Last time AI was used.
 
float m_fAiDelayTime = 0.0f
 Time until AI next used.
 

Additional Inherited Members

- Protected Attributes inherited from CObject
Sage::CSpriteDesc3D * m_pSpriteDesc = nullptr
 Pointer to sprite descriptor.
 
Vector3 m_vVel = Vector3::Zero
 Velocity.
 
float m_fRollSpeed = 0.0f
 Roll speed in revs per second.
 
float m_fFrameTimer = 0.0f
 Last time the frame was changed.
 
float m_fFrameInterval = 0.1f
 Interval between frames.
 
float m_fBirthTime = 0.0f
 Time of creation.
 
float m_fLifeTime = FLT_MAX
 Time that object lives.
 
Sage::CParticleEngine3D * m_pParticleEngine = nullptr
 Pointer to a particle engine.
 
- Static Protected Attributes inherited from CCommon
static CRendererm_pRenderer = nullptr
 Pointer to the renderer.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to the object manager.
 
static CPlaneObjectm_pPlayer = nullptr
 Pointer to player character.
 
static float m_fWorldScale = 2.0f
 World scale.
 
static Vector3 m_vCellSize = Vector3::Zero
 Cell size.
 
static UINT m_nNumCells = 3
 Number of cells.
 
static float m_fWorldWidth = 0.0f
 World width.
 
static eDrawMode m_eDrawMode = eDrawMode::Playing
 Draw mode.
 
static eGameState m_eGameState = eGameState::Loading
 Game state.
 

Detailed Description

AI for the crow objects. Behaviour is based on a simple state machine with two states. State transitions involve an element of randomness. Crows change their speed and desired height at random, and randomly look for the plane. If the plane is close enough when they look, then they enter the avoiding state. If it's where it can't do them any harm, they go back to cruising.

Member Enumeration Documentation

◆ eState

enum CCrowObject::eState
private

The crow is either cruising along happily or actively avoiding the player's plane.

Constructor & Destructor Documentation

◆ CCrowObject()

CCrowObject::CCrowObject ( const Vector3 & pos)

Create a crow moving at a fixed velocity, at a specified position, with that position clamped so that the top of the sprire doesn't go above m_fMaxAltitude and the bottom of the sprite doesn't go below m_fMinAltitude. This uses the height of the first frame of the crow animation by default, so it's best that all crow frames be the same size.

Parameters
posInitial position.

Member Function Documentation

◆ AvoidingAi()

void CCrowObject::AvoidingAi ( )
private

These crows are trying to get away from the plane.

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

◆ CruisingAi()

void CCrowObject::CruisingAi ( )
private

These crows are just cruising along, periodically looking for the plane.

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

◆ Move()

void CCrowObject::Move ( )
virtual

Intelligent move function. Just move like a dumb object then modify private variables "intelligently".

Reimplemented from CObject.

Here is the call graph for this function:

◆ SetState()

void CCrowObject::SetState ( eState state)
private

Change the current state, taking whatever actions are necessary on entering the new state.

Parameters
stateNew state
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Think()

void CCrowObject::Think ( )
private

The real work is done by a function for each state. This function merely calls the appropriate function for the current state periodically, based on a timer.

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