Creating Different Game Modes
Learn how to create different game modes.
We'll cover the following...
Games typically run in modes. Modes specify what the game should do on the current tick, displaying the main menu or the game-over screen, for example. In computer science, this is often formalized as a state machine. It’s a good idea to start by defining our game’s basic mode structure, which acts as an outline for the rest of the program.
Flappy Dragon requires three modes:
-
Menu
: The player is waiting at the main menu. -
Playing
: The gameplay is in progress. -
End
: The game is over.
Transitions between these modes are relatively straightforward:
Game modes are best represented as an enum. Enumerations allow us to limit the value of a variable to one of a set of possible states. Under the prelude import, add a GameMode
enumeration to represent the available game modes:
enum GameMode {Menu,Playing,End,}
-
Line 1:
GameMode
is an enum. -
Lines ...