Archived

This topic is now archived and is closed to further replies.

Neen10do

Got a Game.... now a menu

Recommended Posts

Ive created my basic 2d shooter in directdraw... got some basica weapons and things down like that. however, i cant let my ship die yet.... because tehre is no menu for the player to return to! my problem is... my game is structured around the game engine right now... with the message loop tending to the game input / output itself.... the game starts right up when executing it... and pressing escape exits straight to windows. input, output, and the technicalities in creating said menu is not my problem. my problem is creating the menu engine so to speak seperate from the rest of the game, and allow these to be co-exsisting, so you can go from one to another. i guess my basic question is how do i drastically change the play modes in my game (aka from menu to game and vice versa?) thanks! ---------------------- i code therefore i am. Aero DX - Coming to a bored Monitor near you!

Share this post


Link to post
Share on other sites
The easiest way is going to be a case statement that checks the different gamestates. Something like this..


  
enum EGameState
{
MenuState,
PlayingState,
GameOverState
};

int GameState = MenuState;

switch (GameState)
{
case MenuState: //menu code

break;
case PlayingState: //game code

break;
case GameOverState: //game over code

break;
}

Share this post


Link to post
Share on other sites
The only other obvious option is to do multiple event loops but that really isn''t preferable. I make multiple functions that handle each main state, and one event loop with the above switch to call the correct state handler. These states can also have transition handler functions too, but once you figure the first part out, adding this is just a matter of adding transition states.

Share this post


Link to post
Share on other sites
thanks!

i guess i can do that enumeration... and then in my WinMain PeekMessage loop... i can do switch and then call those different functions. thanks a lot.

----------------------
i code therefore i am.

Aero DX - Coming to a bored Monitor near you!

Share this post


Link to post
Share on other sites
You could also go object oriented and create an abstract GameState base class with functions like Draw() and Process() then derive gamestates from that and overload the functions. I prefer this method because then all of the game logic is encapsulated and you''re using the stengths of C++ to your advantage.

Share this post


Link to post
Share on other sites
i thought of this, but i already created a level class that encapsulated all the things the level does (checks input, weapon state, moves enemies, bullets etc).

----------------------
i code therefore i am.

Aero DX - Coming to a bored Monitor near you!

Share this post


Link to post
Share on other sites