The Blank Game
A Blank 2D Game with Sound and a Sprite
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CGame Class Reference

The game class. More...

#include <Game.h>

Inheritance diagram for CGame:

Public Member Functions

 ~CGame ()
 Destructor. More...
 
void Initialize ()
 Initialize the game. More...
 
void ProcessFrame ()
 Process an animation frame. More...
 
void Release ()
 Release the renderer. More...
 

Private Member Functions

void LoadImages ()
 Load images. More...
 
void LoadSounds ()
 Load sounds. More...
 
void BeginGame ()
 Begin playing the game. More...
 
void CreateObjects ()
 Create game objects.
 
void KeyboardHandler ()
 The keyboard handler. More...
 
void RenderFrame ()
 Render an animation frame. More...
 
void DrawFrameRateText ()
 Draw frame rate text to screen. More...
 

Private Attributes

bool m_bDrawFrameRate = false
 Draw the frame rate.
 
LSpriteDesc2D * m_pSpriteDesc = nullptr
 Sprite descriptor.
 
LSpriteRenderer * m_pRenderer = nullptr
 Pointer to renderer.
 

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 sprite descriptor. 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.

◆ 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.

◆ Initialize()

void CGame::Initialize ( )

Create the renderer and the sprite descriptor load images and sounds, and begin the game.

◆ KeyboardHandler()

void CGame::KeyboardHandler ( )
private

Poll the keyboard state and respond to the key presses that happened since the last frame.

◆ LoadImages()

void CGame::LoadImages ( )
private

Load the specific images needed for this game. This is where eSprite values from GameDefines.h get tied to the names of sprite tags in gamesettings.xml. Those sprite tags contain the name of the corresponding image file. If the image tag or the image file are missing, then the game should abort from deeper in the Engine code leaving you with an error message in a dialog box.

◆ LoadSounds()

void CGame::LoadSounds ( )
private

Initialize the audio player and load game sounds.

◆ ProcessFrame()

void CGame::ProcessFrame ( )

This function will be called regularly to process and render a frame of animation, which involves the following. Handle keyboard input. 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. Render a frame of animation.

◆ Release()

void CGame::Release ( )

Release all of the DirectX12 objects by deleting the renderer.

◆ RenderFrame()

void CGame::RenderFrame ( )
private

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.