#include <Level.h>
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) |
CSheep * | FindClosestSheep (CDwarf *dwarf) |
void | RedirectOtherDwarfs () |
void | DistributeSheepsForStart () |
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().
CLevel::CLevel | ( | ) |
CLevel standard constructor. All level varibles are initialized to 0 or alike. To see some real initialization check out CLevel::Init() function.
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.
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.
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.
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.
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.
m_counter | - number of frames per second |
void CLevel::LevelStart | ( | float | hardness, | |
bool | details, | |||
CSheep * | pSheep | |||
) |
Level parameter setup. This function is called when user starts New Game.
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.
void CLevel::LevelRestart | ( | ) |
Restarting Level parameters. This function is called every time level is started from begining, or new level is reached.
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.
void CLevel::LevelShutDown | ( | ) |
Stopping Level Action
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.
void CLevel::UnPause | ( | ) |
UnPause level will unpause the music, hide the cursor, and roll the action
void CLevel::Pause | ( | ) |
Pause level will stop the music, show the cursor, pause action, write blinking: "Paused"
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.
void CLevel::UpdateTurtlePosition | ( | float | fElapsedTime | ) |
Turtle is moved with mouse or keyborad, shooting and moving is handled here.
void CLevel::AddDwarf | ( | ) |
Add another dwarf in action
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.
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.
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.
void CLevel::DistributeSheepsForStart | ( | ) |
Initializes sheep parameters and positiones sheep to random position in the field.