Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members

nge::core::GameState Class Reference

State Machine Class. More...

#include <GameState.hpp>

Inheritance diagram for nge::core::GameState:

nge::game::StateCredits nge::game::StateIntro nge::game::StateMenu nge::game::StatePlay nge::game::StateSettings

List of all members.

Public Member Functions

virtual void Clear (GameManager *pManager)=0
 Called when state leaves.
virtual void Init (GameManager *pManager)=0
 Called when state enters.
virtual void OnEvent (GameManager *pManager)=0
 Called if an event happened.
virtual void Update (GameManager *pManager)=0
 Called each game iteration.
virtual ~GameState ()
 Destructor.

Protected Member Functions

IGUIImage * addScaledByScreenImage (GameManager *pManager, c8 *ImageFile)
 Returns an IGUIImage with an image scaled by the device's dimensions.
IGUIImage * addScaledImage (GameManager *pManager, c8 *ImageFile, dimension2di const &dimension)
 Returns an IGUIImage with an image scaled by the given dimension.
ITexture * addScaledTexture (IVideoDriver *driver, ITexture *SrcTexture, dimension2di destSize, stringc name)
void ChangeLevel (GameManager *pManager, Level *pLevel)
 Changes the active level.
void ChangeState (GameManager *pManager, GameState *pState)
 Calles the GameManager::ChangeState() method with new state.
void drawFPS (GameManager *pManager, s32 i_font=-1, SColor const &color=SColor(185, 0, 0, 0))
bool drawMiniLogo (GameManager *pManager, c8 *LogoFile, bool drawScaled=false, dimension2di scaleBy=dimension2di(96, 64))
void fadeIn (GameManager *pManager, u32 time=1500, SColor backColor=SColor(255, 0, 0, 0))
 Starts the fade in process. In the beginning the whole rect is drawn by the color and at the end.
void fadeOut (GameManager *pManager, u32 time=1500, SColor backColor=SColor(255, 0, 0, 0))
 Starts the fade out process. In the beginning everything is visible, and at the end of the time only the color will be drawn.
 GameState ()
 Constructor.

Protected Attributes

Levelm_pActiveLevel
NGEReceiverm_pEventReceiver
IGUIInOutFader * m_pInOutFader


Detailed Description

State Machine Class.

State Machine rules

All game states should inherit this class and implement the pure virtual methods as without it the system will not be able to handle new states right. Basically, when creating new state the system will call the Init() method when the state will be changed to, Update() each iteration, Clear() when state is about to end and OnEvent() when event happens while the state is on.

To create a new base state:
$StateName$ = The state's name, e.g: Intro, Menu, etc...
1. Inherit and implement all the pure virtual methods in the new state class.
2. Call on every pure virtual method to the GameState's implementation, e.g:

void New$StateName$State::Init(GameManager* pManager)
{
        GameState::Init(pManager);
}

void New$StateName$State::Update(GameManager* pManager)
{
        GameState::Update(pManager);
}

void New$StateName$State::Clear(GameManager* pManager)
{
        GameState::Clear(pManager);
}

void New$StateName$State::OnEvent(GameManager* pManager)
{
        GameState::OnEvent(pManager);
}


To use your base states create new states (see examples) that inherit your base states and override Only the method you need, for example if you don't need to change anything that happens on Init() just don't override it, but in your game state, not the base state, there you must implement every pure virtual method.
Every method you override must call it's base method e.g:
void New$StateName$State::PureVirtualMethod(GameManager* pManager)
{
        CState$StateName$::PureVirtualMethod(pManager);
}

void MyPlayState::Init(GameManager* pManager)
{
        StatePlay::Init(pManager);

        data_member_age = 10;
        some_other_data_member = 0;

        ChangeLevel(pManager, new MyLevel(pManager));
}

void MyPlayState::Update(GameManager* pManager)
{
        StatePlay::Update(pManager);

        drawFPS(pManager, 1, SColor(220,255,255,0));
        drawMiniLogo(pManager, "MyMiniLogoImage.png");
}

void MyPlayState::Clear(GameManager* pManager)
{
        StatePlay::Clear(pManager);

        if(texture)
                videoDriver->removeTexture(texture);
}

void MyPlayState::OnEvent(GameManager* pManager)
{
        StatePlay::OnEvent(pManager);

        if(     m_pEventReceiver->keyPressed(KEY_ESCAPE) ||
                m_pEventReceiver->keyPressed(KEY_RETURN) ||
                m_pEventReceiver->keyPressed(KEY_SPACE))
        {
                pManager->CloseDevice();
                return;
        }

        if(m_pEventReceiver->mouseLeftPressed())
                ChangeState(pManager, MyMenuState::Instance());
}

Definition at line 109 of file GameState.hpp.


Constructor & Destructor Documentation

virtual nge::core::GameState::~GameState (  )  [virtual]

Destructor.

nge::core::GameState::GameState (  )  [protected]

Constructor.


Member Function Documentation

IGUIImage* nge::core::GameState::addScaledByScreenImage ( GameManager pManager,
c8 ImageFile 
) [protected]

Returns an IGUIImage with an image scaled by the device's dimensions.

The image must be in power of 2, e.g: Scale of - 1024x1024 or 512x256 etc..

Parameters:
pManager : GameManager instance
ImageFile : The path to the image file to be set
Returns:
IGUIImage scaled by screen dimension

IGUIImage* nge::core::GameState::addScaledImage ( GameManager pManager,
c8 ImageFile,
dimension2di const &  dimension 
) [protected]

Returns an IGUIImage with an image scaled by the given dimension.

The image must be in power of 2, e.g: Scale of - 1024x1024 or 512x256 etc..

Parameters:
pManager : GameManager instance
ImageFile : The path to the image file to be set
dimension : The scaling dimension that should be applied onto the image
Returns:
IGUIImage scaled by dimension

ITexture* nge::core::GameState::addScaledTexture ( IVideoDriver *  driver,
ITexture *  SrcTexture,
dimension2di  destSize,
stringc  name 
) [protected]

void nge::core::GameState::ChangeLevel ( GameManager pManager,
Level pLevel 
) [protected]

Changes the active level.

A GameState::ChangeLevel() call should look something like this:

// Other code...
ChangeLevel(pManager, new CMyLevel());
// Other code...
Don't be scared of this new call, the methods will release the previous level before switching to the new one.
The new level instance can be accessed through GameState::m_ActiveLevel member.
Parameters:
pManager : GameManager instance
pLevel : new CMyLevel() - An instance of the level you wish to load.
See also:
Level

void nge::core::GameState::ChangeState ( GameManager pManager,
GameState pState 
) [protected]

Calles the GameManager::ChangeState() method with new state.

virtual void nge::core::GameState::Clear ( GameManager pManager  )  [pure virtual]

void nge::core::GameState::drawFPS ( GameManager pManager,
s32  i_font = -1,
SColor const &  color = SColor(185, 0, 0, 0) 
) [protected]

bool nge::core::GameState::drawMiniLogo ( GameManager pManager,
c8 LogoFile,
bool  drawScaled = false,
dimension2di  scaleBy = dimension2di(96, 64) 
) [protected]

void nge::core::GameState::fadeIn ( GameManager pManager,
u32  time = 1500,
SColor  backColor = SColor(255, 0, 0, 0) 
) [protected]

Starts the fade in process. In the beginning the whole rect is drawn by the color and at the end.

of the given time the color has faded out.

Parameters:
pManager : GameManager instance
time : Time in milliseconds to fade in
backColor : The color which should fade out

void nge::core::GameState::fadeOut ( GameManager pManager,
u32  time = 1500,
SColor  backColor = SColor(255, 0, 0, 0) 
) [protected]

Starts the fade out process. In the beginning everything is visible, and at the end of the time only the color will be drawn.

Parameters:
pManager : GameManager instance
time : Time in milliseconds to fade out
backColor : The color which should fade in

virtual void nge::core::GameState::Init ( GameManager pManager  )  [pure virtual]

virtual void nge::core::GameState::OnEvent ( GameManager pManager  )  [pure virtual]

virtual void nge::core::GameState::Update ( GameManager pManager  )  [pure virtual]


Member Data Documentation

Definition at line 197 of file GameState.hpp.

Definition at line 196 of file GameState.hpp.

IGUIInOutFader* nge::core::GameState::m_pInOutFader [protected]

Definition at line 195 of file GameState.hpp.


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

The NUSoftware Game Engine
The NUSoftware Game Engine Documentation © 2007-2008 by Tomer Nosrati. Generated on Sat Apr 26 16:52:35 2008 by Doxygen (1.5.5)