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

The game class. More...

#include <Game.h>

Inheritance diagram for CGame:
Collaboration diagram for CGame:

Public Member Functions

 ~CGame ()
 Destructor.
 
void FireGun ()
 Fire the plane's gun.
 
void Initialize ()
 Initialize the game.
 
void ProcessFrame ()
 Process an animation frame.
 
void Release ()
 Release the renderer.
 
- Public Member Functions inherited from CCommon
float Wrap (float)
 Wrap horizontal distance.
 

Private Member Functions

void LoadSprites ()
 Start loading sprites.
 
void LoadSounds ()
 Load sounds.
 
void BeginGame ()
 Begin playing the game.
 
void KeyboardHandler ()
 The keyboard handler.
 
void RenderFrame ()
 Render an animation frame.
 
void CreateObjects ()
 Create game objects.

 
void CreateCrows (int, float)
 Create crows.
 
void CreateTrees ()
 Create trees.
 
void CreateClouds (eSprite, int, float, float, float, float)
 Create clouds.
 
void CreateFence (int)
 Create fence.
 
void ProcessGameState ()
 Process game state.
 
void DrawFrameRateText ()
 Draw frame rate text to screen.
 
void ChangeDrawMode ()
 Change draw mode.
 

Private Attributes

bool m_bDrawFrameRate = false
 Draw the frame rate.
 
std::vector< Sage::CSpriteDesc3D > m_stdRenderList
 Render list.
 
float m_fPlaneInitialHt = 0.0f
 Plane's initial height.
 
Sage::CEventTimer * m_pEndWaitEvent = nullptr
 End game wait event.
 
std::set< float > m_stdUsedDepthSet
 Set of used depths.
 

Additional Inherited Members

- 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

The game class is the object-oriented implementation of the game. This class must contain the following public member functions. Initialize() does initialization and will be run exactly once at the start of the game. ProcessFrame() will be called once per frame to create and render the next animation frame. Release() will be called at game exit but before any destructors are run.

Constructor & Destructor Documentation

◆ ~CGame()

CGame::~CGame ( )

Delete the particle engine, the object manager, and the wait event. The renderer needs to be deleted before this destructor runs so it will be done elsewhere.

Member Function Documentation

◆ BeginGame()

void CGame::BeginGame ( )
private

Call this function to start a new game. This should be re-entrant so that you can restart a new game without having to shut down and restart the program. Clear the particle engine to get rid of any existing particles, delete any old objects out of the object manager and create some new ones.

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

◆ ChangeDrawMode()

void CGame::ChangeDrawMode ( )
private

Cycle through available draw modes.

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

◆ CreateClouds()

void CGame::CreateClouds ( eSprite t,
int n,
float xvel,
float ymin,
float ymax,
float zplane )
private

Generate a number of clouds of the same type. All clouds move horizontally at the same speed. Clouds are placed at different Z coordinates, different from the plane, to avoid Z-fighting.

Parameters
tCloud sprite type.
nNumber of clouds of this type to be generated.
xvelHorizontal velocity of clouds.
yminSmallest altitude.
ymaxLargest altitude.
zplaneZ coordinate of the plane.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateCrows()

void CGame::CreateCrows ( int n,
float zplane )
private

Create the crows.

Parameters
nNumber of crows.
zplaneZ coordinate of the plane.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateFence()

void CGame::CreateFence ( int n)
private

Create a fence line. The fence parts consist of a single post and 2 rails so that that can be placed next to one another. A single post must be placed at the left-hand end.

Parameters
nNumber of fence parts.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateObjects()

void CGame::CreateObjects ( )
private

Ask the object manager to create the game objects.

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

◆ CreateTrees()

void CGame::CreateTrees ( )
private

Create an average of 4 trees per cell of random type and in random places near the front of the cell. Consecutive trees will be different.

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

◆ DrawFrameRateText()

void CGame::DrawFrameRateText ( )
private

Draw the current frame rate to a hard-coded position in the window. The frame rate will be drawn in a hard-coded position using the font specified in GameSettings.xml.

Here is the caller graph for this function:

◆ FireGun()

void CGame::FireGun ( )

Query the plane as to the position and orientation of the gun muzzle and create a bullet there, going in that direction slightly faster than the plane.

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

◆ Initialize()

void CGame::Initialize ( )

Create, initialize, and load the renderer and the audio player. Create the wait event and the object manager.

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

◆ KeyboardHandler()

void CGame::KeyboardHandler ( )
private

Poll the keyboard state and respond to the key presses that happened since the last frame. The keys are identified using virtual-key codes.

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

◆ LoadSounds()

void CGame::LoadSounds ( )
private

Create a media list Sage::CMediaList of eSound. For each sound, insert into the media list a pair consisting of an instance of the sound enumerated type eSound and the corresponding string used in the name field in a <sound> tag in GameSettings.xml. Pass the media list to the sound manager for loading.

Here is the caller graph for this function:

◆ LoadSprites()

void CGame::LoadSprites ( )
private

Create a media list Sage::CMediaList of eSprite. For each sprite, insert into the media list a pair consisting of an instance of the sprite enumerated type eSprite and the corresponding string used in the name field in a <sprite> tag in GameSettings.xml. Pass the media list to the renderer for loading.

Here is the caller graph for this function:

◆ ProcessFrame()

void CGame::ProcessFrame ( )

This function will be called regularly to process and render a frame of animation, which involves the following. Handle inputs. Notify the audio player at the start of each frame so that it can prevent multiple copies of a sound from starting on the same frame.
Move the game objects and the camera. Render a frame of animation.

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

◆ ProcessGameState()

void CGame::ProcessGameState ( )
private

Process any changes to the current game state. If the game is in state eGameState::Loading and both the renderer and the sound manager have finished loading (which may or may not be multithreaded), then begin the game. If the game is currently playing, then if all NPCs have been killed, then enter the wait state. If the game has been in the wait state for longer than 3 seconds, then restart the game.

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

◆ Release()

void CGame::Release ( )

Release all of the DirectX12 objects by deleting the renderer.

Here is the caller graph for this function:

◆ RenderFrame()

void CGame::RenderFrame ( )
private

Ask the object manager to draw the game objects. The renderer is notified of the start and end of the frame so that it can let Direct3D do its pipelining jiggery-pokery.

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