Advertisement

Menus

Started by November 23, 2000 01:55 AM
3 comments, last by Peon 24 years, 1 month ago
I just realized I have no idea to make a new game on my game''s menu! I know how to attach a window and add items, etc... but the new game has really got me stumped. Initially, I just had my game start as soon as it was run. Obviously, that''s stupid. I tried a bunch of dumb tricks I came up with but none suceeded in giving me a satisfactory new game function. How is this normally done? what I want my program to do is stay idle until someone selects game -> new from the menu and then the game begins. A new game should be able to be started at any time. FYI, I am doing a GDI pong clone with a Win32 application (I think that''s right ) thanks as always peon
Peon
What I do, is have a global game state. At the beginning this state is set to the menu, and thus calls the menu function that just loops through and waits for the user to select new game(or whatever). Then, set the state to ingame, and call the main game function each frame. If the user chooses to exit the game, set the state back to the main menu.
Hope this helps
Advertisement
I am not sure about this, as I don''t often in code in Windows and don''t know anything about Windows menus but I think that you could make your program call an initial function which some how checks the status of your menu and then if the new game is clicked then it will branch to the new game part.

e.g

  void main(){     if (state==MENU_WAIT)        result = CheckMenu();  // this function does not exist                               // it represents a message that                               // should maybe be sent back from                               // Windows if an option is clicked     if (result==START_GAME)     {         // result maybe the result of the click         // and may hold the code for the New Game         // option on the menu         state=NEW_GAME;         Start_Game();     }}  


I have no idea how codes are returned from the application Window. But the example above is just the main() functio which runs once a frame or something and checks the state of the application Window. If the user has pressed New Game option of the menu then result will hold the code. The function CheckMenu() Is not real this was my way of hypothetically representing how Windows may return if a menu option was clicked. I don''t know if that code example was okay or not.

Does MS Visual C++ or what ever IDE you are using allow u to specify what functions are called by a specific menu option. For example when you specify the properties for new game option, is there a section where it allows you to specify a function to be called when you click on it, such as your New_Game() function.

I hope I have helped at leat a little bit. I don''t know much about Windows programming, so I do not know If I have helped at all. If this has given you any ideas or has helped let me know, if not then..... I tried.

Dark Star

---------------------------------------------You Only Live Once - Don't be afriad to take chances.
Ah ok, I think that makes sense. That''s sorta what I was doing but I come up with strange methods of doing things sometimes that if I suggested them on this board, people would think I''m crazy You shoulda seen the code for my half completed nibbles game, lol. I don''t think ANYONE would come up with a method quite like mine, and that''s not a good thing.

Thanks all

Peon
Peon
I encapsualte all my state information into a class of its own. I find this organizes the data logically, as well as greatly simplifying the task. I am currently working on a pretty large game, and the state is pretty complex, as it has many substates, and it does things such as save previous states (like if you are playing the game, and then you pause, and go to the main menu, you need to save you state in the game).

If you game is going to grow, i would suggest making a separate class to track that information. If you use member functions of the class to retrieve state information, and to set it, it is very easy to expand later.

This topic is closed to new replies.

Advertisement