Archived

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

MarsuGL

making a game menu

Recommended Posts

hello, i want to make a game menu lanched at the startup of my game. i will use opengl and fonts, but the problem is that a want to know what are the usual way to make a menu? using a file ? using linked lists ? i dont know... how are we doing a good menu ? i DO NOT want to use someone else library for that. cheers, Marsu

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Well, if it''s just a simple menu (just a few options like ''New'' ''Load'' ''Options'' ''Quit''), you could have a seperate menu function for each sub-menu (the new game menu, the load menu, the options-main menu, the options-sound menu, etc.) that would contain a switch statement, which would call the approiate functions (either a sub-menu function or a function that actually did something, like new_game() ).

But that can get tedious and error-prone if you add a lot of choices to the menu. A list would be a good idea. You have a group of lists (possibly put into an array) in which each list represents one sub-menu (the new game menu, the options menu, etc.). The actually elements in the lists will be a structure like this

struct menu_item {
int type; // 1 to go to another menu, 2 to call a function
int menu_link; //sub-menu in array to go to (1,2,3,etc.)
/* a function pointer which will be used if type == 2 */
/* a bounding box or something for collision detection */
};

For items that don''t call a function and only link to another menu (like new game would link to the new game menu) could set the function pointer to 0. Items that did call functions (like the exit option would have to call an exit_game() function that would do clean up and then exit) would just set the function pointer to point to the function it needed.

Now, in the actually menu function (or whatever starts the menu), it will have a variable called curr_menu (or something similar) that will start set to 0. This is the index for the menu array I mentioned earlier. Then you can just take in a mouse click (or other form of input), check it to see if it collides with a menu item and, if so, take the approiate action (if type==1, change the curr_menu value to menu_link. if type==2, call the function that the function pointer points to.)

You can probably set up the array of lists inside a header file somewhere because it would be too hard to do it from an external file (you wouldn''t be able to set the function pointer...).

Well, I was of help (and made sense)!

Share this post


Link to post
Share on other sites