Adding another level

From IrrWizard

Jump to: navigation, search

Introduction

This short tutorial will show you how to add another game level to the code generated by IrrWizard.


Adding another Level

The easiest way to add another Level is to copy CGameStateLevel01.cpp and CGameStateLevel01.h, and name them CGameStateLevel02.cpp and CGameStateLevel02.h. Also do a text find and replace and change all instances of CGameStateLevel01 to CGameStateLevel02.

In the Init() function of CGamePlayLevel02, change the name of the new level map, in this case 20kdm3.bsp:

//! Initialisation, loads data required for level.
void CGameStateLevel02::Init(CGameManager* pManager)
{   
  // perform generic initialisation from parent   
  CGamePlayState::Init(pManager);      
  CGamePlayState::LoadMap(pManager, "20kdm3.bsp", core::vector3df(-1300,-144,-1249));
} 


Calling the new level

To test our new level, we can add the call in CGameStateLevel01 when a function key is pressed

//! Keyboard event for level (state), main keyboard events
void CGameStateLevel01::KeyboardEvent(CGameManager * pManager)
{   
  // go to credit screen mode...   
  if(pManager->getKey(irr::KEY_F1)) ChangeState(pManager, CGameCreditsState::Instance());  
  // go back to introduction mode...
  if(pManager->getKey(irr::KEY_F2)) ChangeState(pManager, CGameIntroState::Instance()); 
  // go to game level 2...
  if(pManager->getKey(irr::KEY_F3)) ChangeState(pManager, CGameStateLevel02::Instance());
}
           


Remember to add the GameStateLevel02.h file at the top.

Personal tools