The menu encapsulates its own logic in the
MainMenu class, which inherits from the
SceneObject class. This makes the
MainMenu class a native UI element which can be instantiated as any other UI Element.
New instances of the
MainMenu class can be made as in the following example:
Main Menu Elements
Both the main menu and high-score menu use similar UI elements which are hierarchically stacked:
- Button (Start)
- Button (Highscore)
- Button (Exit)
- Button (Back)
The hierarchy is generated by adding the parent element while instantiating new UI elements.
Button classes are part of the C# UI Framework and the
Table class which is used for the high-score menu is part of the Sydewinder project. To create custom UI elements the UI System can be extended.
Main Menu Appearance
To give a unique look to the game the UI elements mentioned above are styled in various ways.
Button elements will use the same style, while the common style will be applied using a single function.
Main Menu Navigation
After clicking the Highscore button, the camera moves smoothly towards the Highscore plane and returns to the Main Menu plane when the Back button is clicked.
HUD - Overview
When you play the game a Heads-Up-Display (HUD) shows the status of the current game session.
In contrast to the
MainMenu class, the
Hud class inherits from the
Component class and is not rendered as a material on a 3D object. Instead, it is always rendered on top of the current screen and independent of the camera position and level.
The HUD is managed by the
Hud class. It is also responsible for the Game Paused and Game Over dialog options. All the UI elements are initialized with the
InitializeMainHud method and are shown or hidden based on the state of the game.
Similar to the main menu, the HUD is a hierarchical collection of UI elements with a
Canvas class used as a top most element. These are arranged in the following hierarchy:
- Panel (Top of screen)
- Text (Score)
- Text (Level)
- Panel (Bottom of screen)
- Text (Energy)
- Text (Weapon)
- Panel (Game Paused dialog)
- Text (Game Paused)
- Button (Resume Game)
- Button (Exit Game)
- Panel (Game Over dialog)
- Text (Game Over)
- Text (Your Name:)
- Button (OK)
- Panel (Top of screen)
The Game Paused and Game Over dialog options are controlled with references to the corresponding
Panel elements in conjunction with Show/Hide methods.
For updating a score, level, energy or a weapon name while playing the game, the
Hud class internally stores references to the
Text elements and provides various methods for setting the corresponding values. These methods are called in the game loop.