CLevel Class Reference

Level class handles gameplay level action, and draws everything on the screen. More...

#include <Level.h>

Collaboration diagram for CLevel:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 CLevel ()
 ~CLevel ()
bool Init (HWND hWnd, LPDIRECT3DDEVICE9 pd3dDevice, int screenWidth, int screenHeight, IDirectSound8 *pDS, CTerrain *pTerrain, CTurtle *pTurtle, CSheep *pSheep, CLanguage *language)
bool OnEvent (LPDIRECT3DDEVICE9 pd3dDevice, IDirectSound8 *pDS, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, int *code)
void OnFrameMove (LPDIRECT3DDEVICE9 pd3dDevice, double fTime, float fElapsedTime)
void OnRender (LPDIRECT3DDEVICE9 pd3dDevice, float fElapsedTime, int counter)
void LevelStart (float hardness, bool details, CSheep *pSheep)
void ReleaseSheeps ()
void LevelRestart ()
void WindowMove (HWND hWnd, int screenWidth, int screenHeight)
void LevelShutDown ()
void OnLostDevice ()
void UnPause ()
void Pause ()
void OnResetDevice (HWND hWnd, LPDIRECT3DDEVICE9 pd3dDevice, int screenWidth, int screenHeight)
void UpdateTurtlePosition (float fElapsedTime)
void AddDwarf ()
void ScheduleGameAction (float fElapsedTime)
CSheepFindClosestSheep (CDwarf *dwarf)
void RedirectOtherDwarfs ()
void DistributeSheepsForStart ()


Detailed Description

Level class handles gameplay level action, and draws everything on the screen.

This class is responsible for handling all level action and drawing all level models. All calculations are processed in function OnFrameMove(), and rendering is done in function OnRender().

Author:
Petar Bajic
Date:
January, 16 2007.

Constructor & Destructor Documentation

CLevel::CLevel (  ) 

CLevel standard constructor. All level varibles are initialized to 0 or alike. To see some real initialization check out CLevel::Init() function.

Author:
Petar Bajic
Date:
January, 16 2007.

CLevel::~CLevel (  ) 

CLevel destructor. Deletes all that has been alocated in Level class. If you get memleak error after exiting program - here is the problem.

Author:
Petar Bajic
Date:
January, 16 2007.


Member Function Documentation

bool CLevel::Init ( HWND  hWnd,
LPDIRECT3DDEVICE9  pd3dDevice,
int  screenWidth,
int  screenHeight,
IDirectSound8 *  pDS,
CTerrain pTerrain,
CTurtle pTurtle,
CSheep pSheep,
CLanguage pLanguage 
)

Init function initializes all level components. Music is loaded, models are created, everything is allocated here. Some models are allocated before CLevel::Init (like sheep and turtle) because they are needed elsewhere (in movie, menu, etc.) These models are sent to Init as pointers (pTurtle, pSheep, pTerrain), so CLevel can use them instead of doing new allocation.

Author:
Petar Bajic
Date:
January, 16 2007.

bool CLevel::OnEvent ( LPDIRECT3DDEVICE9  pd3dDevice,
IDirectSound8 *  pDS,
HWND  hWnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam,
int *  code 
)

OnEvent is called from CGame::OnEvent() This function handles all events while player is playing the level. Keypress (ESC-exit, SPACE-pause, etc.) Mouse move and mouse press is handled in function OnFrameMove() because windows event handler is just not fast enough.

Author:
Petar Bajic
Date:
January, 16 2007.

void CLevel::OnFrameMove ( LPDIRECT3DDEVICE9  pd3dDevice,
double  fTime,
float  fElapsedTime 
)

Glorious OnFrameMove function!

If you want to change game behaviour - you do it in this function. Dwarfs are walking toward sheeps, snatching sheeps, running away, turtle is shooting, sheeps are pushing each other and jumping, dead dwarfs are flying away, magic flowers appear and disspear, sound effects are fired, elapsed time is checked and number of lives is set... all in this function.

If you want to add Dwarven spaceship flying above the field and snatching sheeps with a transportation beam - you do it here.

Mouse events are also handled here because this is the fastest function in the mexico. OnFrameMove is called 50 times per second, or whatever your framerate is.

Author:
Petar Bajic
Date:
January, 16 2007.

void CLevel::OnRender ( LPDIRECT3DDEVICE9  pd3dDevice,
float  fElapsedTime,
int  m_counter 
)

Glorious Render function!

In this function all models are rendered to the screen, as well as 2D interface. Only Level mode is rendered here, when in menu or movie mode rendering is done in their Render functions. Models are positioned in OnFrameMove funcition, here only matrices are set and models are rendered.

Parameters:
m_counter - number of frames per second
Author:
Petar Bajic
Date:
January, 16 2007.

void CLevel::LevelStart ( float  hardness,
bool  details,
CSheep pSheep 
)

Level parameter setup. This function is called when user starts New Game.

Author:
Petar Bajic
Date:
January, 16 2007.

void CLevel::ReleaseSheeps (  ) 

When exiting level (to menu), all sheeps except first one are released. If player returns from menu to play level - he starts from begining with only one sheep. One remaining sheep is released when exiting game completely.

Author:
Petar Bajic
Date:
January, 16 2007.

void CLevel::LevelRestart (  ) 

Restarting Level parameters. This function is called every time level is started from begining, or new level is reached.

Author:
Petar Bajic
Date:
January, 16 2007.

void CLevel::WindowMove ( HWND  hWnd,
int  screenWidth,
int  screenHeight 
)

When window is resized, this function is caled to set (invisible) mouse to new center of window.

Author:
Petar Bajic
Date:
January, 16 2007.

void CLevel::LevelShutDown (  ) 

Stopping Level Action

Author:
Petar Bajic
Date:
January, 16 2007.

void CLevel::OnLostDevice (  ) 

This function is called when device is being reset (switching to fullscreen and such) Its important to call this function BEFORE device is reset. Particles are making most problems when not properly restarted because they are POOL resources as oposed to MANAGED resources.

Author:
Petar Bajic
Date:
January, 16 2007.

void CLevel::UnPause (  ) 

UnPause level will unpause the music, hide the cursor, and roll the action

Author:
Petar Bajic
Date:
January, 16 2007.

void CLevel::Pause (  ) 

Pause level will stop the music, show the cursor, pause action, write blinking: "Paused"

Author:
Petar Bajic
Date:
January, 16 2007.

void CLevel::OnResetDevice ( HWND  hWnd,
LPDIRECT3DDEVICE9  pd3dDevice,
int  screenWidth,
int  screenHeight 
)

This function is called when device is being reset (switching to fullscreen and such) Its important to call this function AFTER device is reset Particles are making most problems when not properly restarted because they are POOL resources as oposed to MANAGED resources.

Author:
Petar Bajic
Date:
January, 16 2007.

void CLevel::UpdateTurtlePosition ( float  fElapsedTime  ) 

Turtle is moved with mouse or keyborad, shooting and moving is handled here.

Author:
Petar Bajic
Date:
January, 16 2007.

void CLevel::AddDwarf (  ) 

Add another dwarf in action

Author:
Petar Bajic
Date:
January, 16 2007.

void CLevel::ScheduleGameAction ( float  fElapsedTime  ) 

This function takes care of time, and events that happen in specified time interval.

Magic flower appear at rendom moment each level. Dwarfs are added every 5 seconds or so, they show up and go for the sheep. If level time has been count down - level is finished here.

Author:
Petar Bajic
Date:
January, 16 2007.

CSheep * CLevel::FindClosestSheep ( CDwarf dwarf  ) 

Find closest sheep to given dwarf, plus set facing of dwarf to face the closest sheep If there is no sheep available, dwarf will move toward center futile.

Author:
Petar Bajic
Date:
January, 16 2007.

void CLevel::RedirectOtherDwarfs (  ) 

This function is called when dwarf (carrying a sheep) is killed, or some sheep changed position, or dwarf snatched a sheep Then all other dwarfs are redirected, so they can find another available sheep.

Author:
Petar Bajic
Date:
January, 16 2007.

void CLevel::DistributeSheepsForStart (  ) 

Initializes sheep parameters and positiones sheep to random position in the field.

Author:
Petar Bajic
Date:
January, 16 2007.


The documentation for this class was generated from the following files:
Generated on Wed Mar 26 16:00:54 2008 for Turtle Shepherd by  doxygen 1.5.3