Jump to content
  • Advertisement
Sign in to follow this  
Tamior

Main menu in a game

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, everyone. I was wandering what is the best way to implement main menu from which you could start the game, change some options etc. Should I make another class for the whole game itself? Share your experience on that matter please. :)

Share this post


Link to post
Share on other sites
Advertisement
Make a small standalone executable that reads in all configurations from disk and let the player do their own settings in a modal dialog. When he/she press OK you fire off a "startGame" function in a DLL where you have your game code and send all configuration into that very function.

Separating the configuration part from the game part is a nifty thing to do imho :).

Share this post


Link to post
Share on other sites
What language? c++? Are you having problems with anything in particular? Another thing you could do is just have a variable with the game state and change it around everytime you want to access something in particular for example


enum GAME_STATE
{
/*...*/
};
switch(game_state)
{
case GAME_RUNNING:
RunGame();
break;
case GAME_OPTIONS:
ShowOptions();
break;
case GAME_MENU:
ShowMenu();
break;
};




I don't really think you would need a class especially not for the whole game :/

Share this post


Link to post
Share on other sites
Yes, I'm writing in C++. But I haven't made myself familiar with dlls yet. Gamestates is a good idea. The question is then should my game check this state every iteration of the main cycle and make decision based upon that check what to show, how to react to events, how to update itself? Isn't it better to make a class with static members that should keep all that stuff encapsulated?

Share this post


Link to post
Share on other sites
Quote:
Original post by Tamior
Yes, I'm writing in C++. But I haven't made myself familiar with dlls yet. Gamestates is a good idea. The question is then should my game check this state every iteration of the main cycle and make decision based upon that check what to show, how to react to events, how to update itself? Isn't it better to make a class with static members that should keep all that stuff encapsulated?


Yeah just have the switch statement in your main loop and check for the state every iteration. Rather than having the whole game in a class I would rather have a function and smaller functions to carry out smaller tasks for example


void ShowOptions()
{
if(HandleInput(..) == EXIT)
change_state();
RenderOptions(..);
}


Additionally you could put everything inside a namespace to make it cleaner. Also use classes to handle smaller tasks related to each other for example you might have a class to handle game resources, another class to handle I don't know the player stats. Write the classes in such a way the code is reusable so you can use it in other projects as well, and of course keep everything only the class cares about encapsulated. I'm just saying that a class for the whole game doesn't work I've had bad experiences with that trust me ;)

Share this post


Link to post
Share on other sites
No. ;)

Make a baseclass and derive every state from that.

ie.

class baseState {
void initState ( void );
void deInitState ( void );
void update ( void );
};

class introState : public baseState {
...
};

class gameState : public baseState {
...
};

class stateManager {
std::vector<baseState*> mvStates;

void changeState ( ... );
void pauseState ( ... );
void addState ( ... );
void removeState ( ... );
...
void run ( void ); // Game mainloop calls update of current state
void putMsg ( ... ); // Send a message to current state
};




Voila. Each state is separated and have different behaviours but the mainloop is still the same (call ->update(), each frame).

EDIT: tags are not named code in this forum.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!