How to make a main menu?

How do I make a main menu that you see in alot of games these days? I'm kinda curious...
[90 byte] By [JasonD_dot_NET] at [2007-12-24]
# 1

I haven't tried it yet but I think something like the following should work:

- Declare a boolean boolGameStarted or boolShowMenu
- Create a custom menu class or something else, ie a simple array, that holds the currently select option
- Depending on the boolean, draw the menu options, e.g. strings or a sprite, and draw the currently selected option in a different color for example (ie. different color string or tint a sprite)
- In your code that handles the keyboard/gamepad menu, depending on the boolean, check for input (up or down, start/enter, etc) and change the currently selected menu option in the menu class or array according to the input

JohanHiemstra at 2007-10-8 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 2

Instead of a bool, you'll probably want an enumerated value:

public enum GameState
{
MainMenu,
OptionsMenu,
Pause,
Victory,
GameOver
}

You could also have a base class that shows the current "window" and inherit from it for each of the possible game states.

Ideally, each window would handle the input - have a curWindow object in your game class and pass it the input.

JimPerry at 2007-10-8 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 3

What I do is the following. At least that's what I did with MDX. Haven't got the chance to try XNA a lot yet. Will be a good mean to learn C# as I'm more of a VB.NET guy.

I have an abstract GameState class with a few Functions defined as MustInherit (like Update, Draw etc...). Every GameState like the Game itself, the menu etc... is a child class of GameState. Those classes implement the different functions.

Then there is the GameStateManager which is basically just a Stack of GameState objects. e.g. when I open the Menu, I push an instance of my Menu Class onto the stack. Once the menu gets closed, I pop it from the stack. Thus the game always only needs to call the Update, Draw etc... function of the "Top" element of the stack and the correct GameState will be rendered without having to track which GameState we are in using Booleans, Enums or whatever.

RizMan at 2007-10-8 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 4
The GameState route is definitely the one to go. I used that technique in a game I did for a game design contest. The code used Managed DirectX and VB.NET but the concepts should be easy enough to convert to XNA and C# if you want to take a look. You can get the source code for that from here.

Bob the Fish Source Code:
http://geekswithblogs.net/clingermangw/archive/2006/06/29/83650.aspx

You can follow the whole contest by reading the posts here (part of the contest was blogging about it was we worked on our games for the contest).

GWB Game Design Contest:
http://geekswithblogs.net/clingermangw/category/4558.aspx

The game itself is basically just five levels of very common games done in VB.NET with Managed DirectX. Only had 1 month to get it done, so I felt pretty good about it. Hopefully that helps.

Also, when I was having trouble understanding GameState and how it was used. I found these tutorials EXTREMELY helpful. This guy basically got me over my game development hump and a lot of things became a lot clearer for me, so maybe they'll help someone else out too. I always meant to contact the guy and say thank but never did, but he really helped me out a lot.

Tutorials from the guy I never thanked:
http://www.kalme.de/index.php?option=com_content&task=category&sectionid=4&id=14&Itemid=26

GeorgeClingerman at 2007-10-8 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 5
Thanks for the help :) I'll keep it all in mind :)
JasonD_dot_NET at 2007-10-8 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...