Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Game Menu with States [closed]

I was and have been looking for an example on how to make a game menu. For example i want to have the application open to the menu. From there it would either open "play game" "Show Credits" "Exit".

Everything i have seen so far is for popup menus..

So the answer iam looking for is about use "states" like pause state, game state , ect.. But i cant figure out the layout this should be or how it should be used..Nor how to create the MenuState and cant find an example anywhere

Using glut and freeglew

like image 267
Glen Morse Avatar asked Mar 02 '13 11:03

Glen Morse


1 Answers

GUI Implementation

The basic idea is to create some textured quads in front of the camera and when the user clicks on the screen translate it into world space and find out which quad, and therefore which button, they clicked on. You may find that orthographic projection is the way to go here.

The exact implementation will depend on how you are interacting with the keyboard and mouse (GLUT, SDL etc.).

You may want to consider using a GUI framework such as CEGUI, FLTK or similar though as this can often be a complex task.

Game States

Game states are a simple way to abstract from the passage of a uesr through the game. It allows you to model the different areas of the game as nodes on a DFA or by using a stack. You can then implement this by creating an api that GameState objects inherit from. you can then implement different kinds of game states by derriving classes from this interface.

The interface itself can provide methods to allow the state to be notified when it is made active and when it is 'paused' and similar.

If using a DFA to manage state then there is one active state that represents the current node the DFA. The state can then select a new state to go to based on the input to the game (Cliking the play button in the menu etc.).

If you are managing game states using a stack it is a little different. First you push the menu state onto the stack and then when a level is selected you can push that onto the stack too. When the level is over the state is popped from the stack and the user returns to the main menu state.

An example of a simple game engine is here: https://bitbucket.org/iwillspeak/thulium/src. GameState is the base class for game states. These are managed by the GameStateFactory. SampleState is a sample game state implementation.

like image 98
Will Avatar answered Nov 18 '22 13:11

Will