Game Development Reference
In-Depth Information
The actual menu creation is done in the InitializeMenu function because
this stops it from cluttering up the StartMenuState constructor. The
StartMenuState creates a vertical menu centered on the X axis and 150 pixels
up on the Y axis. This positions the menu neatly below the title text.
private void InitializeMenu()
{
_menu ¼ new VerticalMenu(0, 150, _input);
Button startGame ¼ new Button(
delegate(object o, EventArgs e)
{
// Do start game functionality.
},
new Text("Start", _generalFont));
Button exitGame ¼ new Button(
delegate(object o, EventArgs e)
{
// Quit
System.Windows.Forms.Application.Exit();
},
new Text("Exit", _generalFont));
_menu.AddButton(startGame);
_menu.AddButton(exitGame);
}
Two buttons are created: one for exit and one for start. It's easy to see how
additional buttons could be added (e.g., load saved game, credits, settings,
or website would all be fairly trivial to add using this system). The exit button
delegate is fully implemented, and when called, it will exit the program. The start
menu button functionality is empty for the time being; it will be filled in when we
make the inner game state.
The vertical menu is now being successfully created, but it won't be visible until
it's added to the render loop.
public void Render()
{
Gl.glClearColor(1, 1, 1, 0);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
_renderer.DrawText(_title);
 
Search WWH ::




Custom Search