OpenMortal Apocalypse mirror
Sourceforge mirror
SourceForge.net Logo
      News | Info | Characters | Arenas | Screenshots | Forums | Download  
Developer: Making of | Character-HOWTO | AI Design | Submit a Character
Documentation: Main Page | Modules | Class Hierarchy | Class List | File List

CGame Class Reference
[Game logic (frontend + backend connection)]

The CGame class is for running the frontend of a game. More...

#include <Game.h>

List of all members.

Public Member Functions

 CGame (bool a_bIsReplay, bool m_bWide, bool a_bDebug)
 ~CGame ()
int Run ()
 Runs a whole game, with two or three rounds.
std::string & GetReplay ()
 Returns the replay string of the last round.
void DoReplay (const char *a_pcReplayFile)

Static Public Member Functions

static int GetBackgroundNumber ()

Protected Types

enum  TGamePhaseEnum {
  Ph_START, Ph_NORMAL, Ph_TIMEUP, Ph_KO,
  Ph_REWIND, Ph_SLOWFORWARD, Ph_REPLAY
}

Protected Member Functions

void Draw ()
 Draws the entire game screen:.
void DrawHitPointDisplay (int a_iPlayer)
void DrawHitPointDisplays ()
 Draws the hitpoint bars that are displayed on the top of the screen.
void DrawBackground ()
 Draws the background, using the m_poBackground object.
void DrawDoodads ()
 Draws every doodad that is currently defined in the backend.
void DrawPoly (const char *a_pcName, int a_iColor)
 In debug mode, this method is used to draw the frame of the fighters.
void AddBodyToBackground (int a_iPlayer)
void DoOneRound ()
 This methods executes one round of gameplay.
void Advance (int a_iNumFrames)
 This method reads and updates the game's variables.
int ProcessEvents ()
 ProcessEvents reads events from the SDL event system.
void HandleKey (int a_iPlayer, int a_iKey, bool a_bDown)
 A helper method of ProcessEvents; it manages keypresses and releases of players.
void HandleKO ()
void HurryUp ()
void TimeUp ()
void InstantReplay (int a_iKoAt)
 This methods starts and runs the "instant replay" mode that is done at the end of a game round.
bool IsTeamMode ()
bool IsNetworkGame ()
bool IsMaster ()
 Returns true if we control our own data, or false if the network supplies us with game data.
void ReadKeysFromNetwork ()

Protected Attributes

bool m_bIsReplay
bool m_bWide
 800 or 640 pixel width.
int m_iYOffset
 For wide mode.
bool m_bDebug
CBackgroundm_poBackground
SDL_Surface * m_poDoodads
int m_aiHitPointDisplayX [MAXPLAYERS]
int m_aiHitPointDisplayY [MAXPLAYERS]
bool m_abHitPointDisplayLeft [MAXPLAYERS]
int m_aiRoundsWonByPlayer [MAXPLAYERS]
int m_iNumberOfRounds
int m_iFrame
int m_iGameTime
CKeyQueue m_oKeyQueue
int m_iEnqueueDelay
std::string m_sReplayString
std::vector< int > m_aReplayOffsets
enum CGame::TGamePhaseEnum m_enGamePhase
SState::TGameMode m_enInitialGameMode

Static Protected Attributes

static int mg_iBackgroundNumber = 1


Detailed Description

The CGame class is for running the frontend of a game.

This involves reading the game state data from a source (be it a replay file or the backend), handling the keystrokes and network, etc.


Member Enumeration Documentation

enum CGame::TGamePhaseEnum [protected]
 

Enumeration values:
Ph_START 
Ph_NORMAL 
Ph_TIMEUP 
Ph_KO 
Ph_REWIND 
Ph_SLOWFORWARD 
Ph_REPLAY 


Constructor & Destructor Documentation

CGame::CGame bool  a_bIsReplay,
bool  m_bWide,
bool  a_bDebug
 

CGame::~CGame  ) 
 


Member Function Documentation

void CGame::AddBodyToBackground int  a_iPlayer  )  [protected]
 

void CGame::Advance int  a_iNumFrames  )  [protected]
 

This method reads and updates the game's variables.

In replay mode, this is done by parsing the replay string. Otherwise the perl backend is advanced the given number of steps.

Whichever the case, the variables will be available in g_oBackend.

Only the backend-driven variables are modified, the GamePhase and GameTime remain unchanged; these are up for DoOneRound and friends to modify.

void CGame::DoOneRound  )  [protected]
 

This methods executes one round of gameplay.

The game progresses through phases Ph_START, Ph_NORMAL, and Ph_KO. If a KO happened, it will invoke InstantReplay. At the end of the round m_aiRoundsWonByPlayer[x] will be incremented depending on the outcome. m_iNumberOfRounds will also increase by 1.

void CGame::DoReplay const char *  a_pcReplayFile  ) 
 

void CGame::Draw  )  [protected]
 

Draws the entire game screen:.

  • First, the background.
  • The players.
  • The debug wireframes (if debugging is turned on)
  • The doodads.
  • The hitpoint display.
  • The gametime display.
  • The FPS display.
  • The "Round x" text during Ph_Start
Input:
  • m_enGamePhase
  • g_oBackend.m_iGameTime
  • m_iNumberOfRounds
  • oFpsCounter

void CGame::DrawBackground  )  [protected]
 

Draws the background, using the m_poBackground object.

void CGame::DrawDoodads  )  [protected]
 

Draws every doodad that is currently defined in the backend.

void CGame::DrawHitPointDisplay int  a_iPlayer  )  [protected]
 

void CGame::DrawHitPointDisplays  )  [protected]
 

Draws the hitpoint bars that are displayed on the top of the screen.

Also draws the fighter names below the bars.

Input variables:

  • g_oBackend.m_aoPlayers[x].m_iHitPoints
  • g_oPlayerSelect.GetFighterName

void CGame::DrawPoly const char *  a_pcName,
int  a_iColor
[protected]
 

In debug mode, this method is used to draw the frame of the fighters.

Parameters:
a_pcName The name of the polygon (in the perl namespace)
a_iColor The game color to draw the polygon with.

int CGame::GetBackgroundNumber  )  [static]
 

std::string & CGame::GetReplay  ) 
 

Returns the replay string of the last round.

void CGame::HandleKey int  a_iPlayer,
int  a_iKey,
bool  a_bDown
[protected]
 

A helper method of ProcessEvents; it manages keypresses and releases of players.

It is only called when keypresses are actually relevant for the backend (not during instant replay, etc).

void CGame::HandleKO  )  [protected]
 

void CGame::HurryUp  )  [protected]
 

void CGame::InstantReplay int  a_iKoAt  )  [protected]
 

This methods starts and runs the "instant replay" mode that is done at the end of a game round.

This means doing phases Ph_REWIND and Ph_SLOWFORWARD.

Rewind will go back in time 200 ticks before the parameter a_iKoAt.

bool CGame::IsMaster  )  [protected]
 

Returns true if we control our own data, or false if the network supplies us with game data.

bool CGame::IsNetworkGame  )  [protected]
 

bool CGame::IsTeamMode  )  [protected]
 

int CGame::ProcessEvents  )  [protected]
 

ProcessEvents reads events from the SDL event system.

Relevant key events are fed to the backend. Esc brings up the menu.

Returns 1 on quit event (e.g. if the current game or replay should be aborted), 0 otherwise.

void CGame::ReadKeysFromNetwork  )  [protected]
 

int CGame::Run  ) 
 

Runs a whole game, with two or three rounds.

Return values:
0 if player 1 has won.
1 if player 2 has won.
-1 if the game was a draw.

void CGame::TimeUp  )  [protected]
 


Member Data Documentation

bool CGame::m_abHitPointDisplayLeft[MAXPLAYERS] [protected]
 

int CGame::m_aiHitPointDisplayX[MAXPLAYERS] [protected]
 

int CGame::m_aiHitPointDisplayY[MAXPLAYERS] [protected]
 

int CGame::m_aiRoundsWonByPlayer[MAXPLAYERS] [protected]
 

std::vector<int> CGame::m_aReplayOffsets [protected]
 

bool CGame::m_bDebug [protected]
 

bool CGame::m_bIsReplay [protected]
 

bool CGame::m_bWide [protected]
 

800 or 640 pixel width.

enum CGame::TGamePhaseEnum CGame::m_enGamePhase [protected]
 

SState::TGameMode CGame::m_enInitialGameMode [protected]
 

int CGame::m_iEnqueueDelay [protected]
 

int CGame::m_iFrame [protected]
 

int CGame::m_iGameTime [protected]
 

int CGame::m_iNumberOfRounds [protected]
 

int CGame::m_iYOffset [protected]
 

For wide mode.

CKeyQueue CGame::m_oKeyQueue [protected]
 

CBackground* CGame::m_poBackground [protected]
 

SDL_Surface* CGame::m_poDoodads [protected]
 

std::string CGame::m_sReplayString [protected]
 

int CGame::mg_iBackgroundNumber = 1 [static, protected]
 


The documentation for this class was generated from the following files: