Request for a basic game program layout
Hello. I could use a hand with a little something; does anyone her know of where I could find a template of how to layout my code for my game? Or perhaps a simple game with source code I can look at? I have an intro that times out to a title screen to a demo to a main menu, repeat. Pressing Enter goes straight ot the main menu, unless you''re at the main menu .... and so it goes. What I''m trying to organize is initialization of levels, the gameloop, perhaps cutscenes, game over, enter your name for the high score, etc. I''d love to see a basic template to get me started; I know there''s a million ways to do it but I just need some simple direction to get started ....
Chris Barry
Jesus saves ... the rest of you take 2d4 fire damage.
What we are using in the project I am working on is a screen concept. We have a base class called Screen that provides base functionality such as loading resources, freeing resources, logic and rendering. Then each type of screen in the game is a class based on the Screen class that overrides the base functionality with its own particular requirements. The basic game loop is then something like this:
To switch screens, do the following:
A cutscene, for example, will play the movie until either the movie ends or the user presses a key. This is checked in the Logic of the cutscene object. Then it will call SwitchToScreen with the new screen object that will be shown next.
Steve ''Sly'' Williams Code Monkey Krome Studios
Screen *currentScreen = NULL;Screen *nextSCreen = NULL;while (!done){ ProcessMessages(); // If screen change is requested, then change now if (nextScreen != currentScreen) { if (currentScreen) currentScreen->FreeResources(); currentScreen = nextScreen; if (currentScreen) currentScreen->LoadResources(); } // Do logic and rendering for current screen if (currentScreen) { currentScreen->Logic(); currentScreen->Render(); }}
To switch screens, do the following:
void SwitchToScreen(Screen *newScreen){ if (currentScreen == newScreen) return; nextScreen = newScreen;}
A cutscene, for example, will play the movie until either the movie ends or the user presses a key. This is checked in the Logic of the cutscene object. Then it will call SwitchToScreen with the new screen object that will be shown next.
Steve ''Sly'' Williams Code Monkey Krome Studios
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement