OK, your half way there anyway, instead of your game loop consisting of a set Render() and Update() though how about allowing it to use one of the followiung structures:
If we have your generic game loop, with blank updates in:
class CGame
{
virtual void Update();
virtual void Render();
}
From this we can derive the kind of state you were using:
class CMainGame
{
virtual void Update();
virtual void Render();
// whatever else you were using
}
In the main loop this would just appear as:
CGame *m_currentState;
WinMain()
{
m_currentState = new CMainGame;
for(;;)
{
m_currentState->Update();
m_currentState->Render();
}
}
This should just be similar to what your doing right now, the beauty of this system is you can create your own CGame states now and stick em on m_currentState, be they an intro, a menu, a pause screen, a bonus stage etc, you can lay them out in a stack, just have 1 at a time, however you want really. An intro will work exactly the same, its update will be small and might just check for a keypress, once its found one or ended it'll close its self and move on to the next state, which will have its own update and render functions. All the while the main game loop remains small, tidy, easy to add to, heavily object oriented and can mainly be kept and improved from game to game. The menus you mention could be part of the base state (CGame), if the main update spots a certain key is pressed it'll Render() a menu at the top, this would allow the menus to work in ANY state, frontend, main game etc.
If this doesn't make any sense in any way just ask or if your not bothered about OO coding (or using c++ or similar) go for the method above.
Main Topics
Browse All Topics





by: MoonoverPosted on 2003-07-02 at 13:52:39ID: 8843992
Normally, the GUI is not hand-coded, but is part of a graphic engine... one of the simple 3D engine I have experimented with is WildTangent (www.wildtangent.com) ... it is not the best, but there is a good documentation, and I find it easy to use (i learned it during my gameprogramming course at my university) ...
Most of the time, the interfaces are designed in Photoshop, and imported in the game with the graphic engine functions ...
A game loop I use goes something like this:
loop until Quit
{
if startup
{
load menu
startup = false
}
if( playgame == true )
{
do the standard stuff ( update position of object, check AI, physics, display refresh, blablabla )
}
if( gameOver == true )
{
- do something like freezing the display or play an end animation -- deallocate memory and stuff -
playgame = false
gameOver = false
startup = true
}
}
Hope it helps!
David