Max Houghton
/
MazeGame_el15mh
el15mh 200929957
Menu/Menu.h@10:989e5dbd12ee, 2017-05-04 (annotated)
- Committer:
- el15mh
- Date:
- Thu May 04 17:39:23 2017 +0000
- Revision:
- 10:989e5dbd12ee
- Parent:
- 9:960dfc71c224
Documented and final revision
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el15mh | 9:960dfc71c224 | 1 | #ifndef MENU_H |
el15mh | 9:960dfc71c224 | 2 | #define MENU_H |
el15mh | 9:960dfc71c224 | 3 | |
el15mh | 9:960dfc71c224 | 4 | #include <stdlib.h> // used to generate random number values |
el15mh | 9:960dfc71c224 | 5 | |
el15mh | 9:960dfc71c224 | 6 | #include "mbed.h" |
el15mh | 9:960dfc71c224 | 7 | #include "N5110.h" |
el15mh | 9:960dfc71c224 | 8 | #include "Gamepad.h" |
el15mh | 9:960dfc71c224 | 9 | #include "MazeEngine.h" |
el15mh | 9:960dfc71c224 | 10 | #include "Animations.h" |
el15mh | 9:960dfc71c224 | 11 | #include "Maze.h" |
el15mh | 9:960dfc71c224 | 12 | #include "Ball.h" |
el15mh | 9:960dfc71c224 | 13 | |
el15mh | 10:989e5dbd12ee | 14 | /** |
el15mh | 10:989e5dbd12ee | 15 | @brief Menu Class runs the menu which the program uses as a basis. |
el15mh | 10:989e5dbd12ee | 16 | @author Max Houghton |
el15mh | 10:989e5dbd12ee | 17 | @date April 4 2017 |
el15mh | 10:989e5dbd12ee | 18 | */ |
el15mh | 10:989e5dbd12ee | 19 | |
el15mh | 9:960dfc71c224 | 20 | class Menu |
el15mh | 9:960dfc71c224 | 21 | { |
el15mh | 9:960dfc71c224 | 22 | |
el15mh | 9:960dfc71c224 | 23 | public: |
el15mh | 9:960dfc71c224 | 24 | |
el15mh | 9:960dfc71c224 | 25 | /** |
el15mh | 9:960dfc71c224 | 26 | * @details - constructor |
el15mh | 9:960dfc71c224 | 27 | */ |
el15mh | 9:960dfc71c224 | 28 | Menu(); |
el15mh | 9:960dfc71c224 | 29 | |
el15mh | 9:960dfc71c224 | 30 | /** |
el15mh | 9:960dfc71c224 | 31 | * @details - destructor |
el15mh | 9:960dfc71c224 | 32 | */ |
el15mh | 9:960dfc71c224 | 33 | ~Menu(); |
el15mh | 9:960dfc71c224 | 34 | |
el15mh | 9:960dfc71c224 | 35 | /** Initialise Menu |
el15mh | 9:960dfc71c224 | 36 | * |
el15mh | 9:960dfc71c224 | 37 | * @details - Creates objects and default parameters for the game |
el15mh | 9:960dfc71c224 | 38 | * |
el15mh | 9:960dfc71c224 | 39 | */ |
el15mh | 9:960dfc71c224 | 40 | void init(); |
el15mh | 9:960dfc71c224 | 41 | |
el15mh | 9:960dfc71c224 | 42 | /** Main Menu Function |
el15mh | 9:960dfc71c224 | 43 | * |
el15mh | 9:960dfc71c224 | 44 | * @details - The main function which runs the game and allows player to select all different game parameters. |
el15mh | 10:989e5dbd12ee | 45 | * @param lcd - N5110 Library, used for drawing strings and printing bitmaps |
el15mh | 10:989e5dbd12ee | 46 | * @param pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. |
el15mh | 10:989e5dbd12ee | 47 | * @param device - FXOS8700CQ Libary, used to read data from accelerometer |
el15mh | 10:989e5dbd12ee | 48 | * @param animate - Animations Library to provide short animations. |
el15mh | 9:960dfc71c224 | 49 | * |
el15mh | 9:960dfc71c224 | 50 | */ |
el15mh | 9:960dfc71c224 | 51 | void main(N5110 &lcd, |
el15mh | 9:960dfc71c224 | 52 | Gamepad &pad, |
el15mh | 9:960dfc71c224 | 53 | FXOS8700CQ &device, |
el15mh | 9:960dfc71c224 | 54 | Animations &animate); |
el15mh | 9:960dfc71c224 | 55 | |
el15mh | 9:960dfc71c224 | 56 | /** Intro Function |
el15mh | 9:960dfc71c224 | 57 | * |
el15mh | 9:960dfc71c224 | 58 | * @details - The main function which runs the game and allows player to select all different game parameters. |
el15mh | 9:960dfc71c224 | 59 | * @details - Called from main file when the game is loading. |
el15mh | 10:989e5dbd12ee | 60 | * @param lcd - N5110 Library, used for drawing strings and printing bitmaps |
el15mh | 10:989e5dbd12ee | 61 | * @param pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. |
el15mh | 10:989e5dbd12ee | 62 | * @param animate - Animations Library to provide short animations. |
el15mh | 9:960dfc71c224 | 63 | * |
el15mh | 9:960dfc71c224 | 64 | */ |
el15mh | 9:960dfc71c224 | 65 | void intro(N5110 &lcd, Gamepad &pad, Animations &animate); |
el15mh | 9:960dfc71c224 | 66 | |
el15mh | 9:960dfc71c224 | 67 | private: |
el15mh | 9:960dfc71c224 | 68 | |
el15mh | 9:960dfc71c224 | 69 | /** |
el15mh | 9:960dfc71c224 | 70 | * |
el15mh | 9:960dfc71c224 | 71 | * @details - Game Loop function. |
el15mh | 10:989e5dbd12ee | 72 | * @param lcd - N5110 Library, used for drawing strings and printing bitmaps |
el15mh | 10:989e5dbd12ee | 73 | * @param pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. |
el15mh | 10:989e5dbd12ee | 74 | * @param device - FXOS8700CQ Libary, used to read data from accelerometer |
el15mh | 10:989e5dbd12ee | 75 | * @param animate - Animations Library to provide short animations. |
el15mh | 10:989e5dbd12ee | 76 | * @param difficulty - Integer value to specificy desired difficulty; maze Index is randomly chosen according to difficulty value. |
el15mh | 10:989e5dbd12ee | 77 | * @param tone - Boolean value to select whether sound is used or not. |
el15mh | 10:989e5dbd12ee | 78 | * @param FPS - Specifies the frame rate at which the game is to be played at. |
el15mh | 9:960dfc71c224 | 79 | * |
el15mh | 9:960dfc71c224 | 80 | */ |
el15mh | 9:960dfc71c224 | 81 | void playGame(N5110 &lcd, |
el15mh | 9:960dfc71c224 | 82 | Gamepad &pad, |
el15mh | 9:960dfc71c224 | 83 | FXOS8700CQ &device, |
el15mh | 9:960dfc71c224 | 84 | Animations &animate, |
el15mh | 9:960dfc71c224 | 85 | int mazeIndex, |
el15mh | 9:960dfc71c224 | 86 | bool tone, |
el15mh | 9:960dfc71c224 | 87 | float FPS); |
el15mh | 9:960dfc71c224 | 88 | |
el15mh | 9:960dfc71c224 | 89 | /** |
el15mh | 9:960dfc71c224 | 90 | * |
el15mh | 9:960dfc71c224 | 91 | * @details - Prints all chosen game parameters to serial port - used mostly for debugging. |
el15mh | 10:989e5dbd12ee | 92 | * @param mazeIndex - specifies which of the 10 mazes is to be drawn. |
el15mh | 10:989e5dbd12ee | 93 | * @param x - x coordiante for centre of ball when drawn initially. |
el15mh | 10:989e5dbd12ee | 94 | * @param y - y coordiante for centre of ball when drawn initially. |
el15mh | 10:989e5dbd12ee | 95 | * @param control - Boolean value to specify desired control method. |
el15mh | 10:989e5dbd12ee | 96 | * @param colour - Boolean value to select type of ball; filled or transparent. |
el15mh | 10:989e5dbd12ee | 97 | * @param FPS - Specifies the frame rate at which the game is to be played at. |
el15mh | 9:960dfc71c224 | 98 | * |
el15mh | 9:960dfc71c224 | 99 | */ |
el15mh | 9:960dfc71c224 | 100 | void printGameParameters(int mazeIndex, |
el15mh | 9:960dfc71c224 | 101 | int x, |
el15mh | 9:960dfc71c224 | 102 | int y, |
el15mh | 9:960dfc71c224 | 103 | int radius, |
el15mh | 9:960dfc71c224 | 104 | bool control, |
el15mh | 9:960dfc71c224 | 105 | bool colour, |
el15mh | 9:960dfc71c224 | 106 | float FPS); |
el15mh | 9:960dfc71c224 | 107 | |
el15mh | 9:960dfc71c224 | 108 | |
el15mh | 9:960dfc71c224 | 109 | /** |
el15mh | 9:960dfc71c224 | 110 | * |
el15mh | 9:960dfc71c224 | 111 | * @details - Game Options Function to allow user to choose game style. |
el15mh | 10:989e5dbd12ee | 112 | * @param lcd - N5110 Library, used for drawing strings and printing bitmaps |
el15mh | 10:989e5dbd12ee | 113 | * @param pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. |
el15mh | 10:989e5dbd12ee | 114 | * @param animate - Animations Library to provide short animations. |
el15mh | 10:989e5dbd12ee | 115 | * @param tone - Boolean value to select whether sound is used or not. |
el15mh | 9:960dfc71c224 | 116 | */ |
el15mh | 9:960dfc71c224 | 117 | void options(N5110 &lcd, Gamepad &pad, Animations &animate, bool tone); |
el15mh | 9:960dfc71c224 | 118 | |
el15mh | 9:960dfc71c224 | 119 | |
el15mh | 9:960dfc71c224 | 120 | /** |
el15mh | 9:960dfc71c224 | 121 | * |
el15mh | 9:960dfc71c224 | 122 | * @details - LCD Settings Function to allow user to alter appearance of game on LCD. |
el15mh | 10:989e5dbd12ee | 123 | * @param lcd - N5110 Library, used for drawing strings and printing bitmaps |
el15mh | 10:989e5dbd12ee | 124 | * @param pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. |
el15mh | 10:989e5dbd12ee | 125 | * @param animate - Animations Library to provide short animations. |
el15mh | 9:960dfc71c224 | 126 | * |
el15mh | 9:960dfc71c224 | 127 | */ |
el15mh | 9:960dfc71c224 | 128 | void lcdSettings(N5110 &lcd, Gamepad &pad, Animations &animate); |
el15mh | 9:960dfc71c224 | 129 | |
el15mh | 9:960dfc71c224 | 130 | /** |
el15mh | 9:960dfc71c224 | 131 | * |
el15mh | 9:960dfc71c224 | 132 | * @details - Sound Settings to allow user to turn sound on or off. This changes the boolean value of the '_tone' variable. |
el15mh | 10:989e5dbd12ee | 133 | * @param lcd - N5110 Library, used for drawing strings and printing bitmaps |
el15mh | 10:989e5dbd12ee | 134 | * @param pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. |
el15mh | 10:989e5dbd12ee | 135 | * @param animate - Animations Library to animate slide bar to display brightness level settings. |
el15mh | 9:960dfc71c224 | 136 | * |
el15mh | 9:960dfc71c224 | 137 | */ |
el15mh | 9:960dfc71c224 | 138 | void soundSettings(N5110 &lcd, Gamepad &pad, Animations &animate); |
el15mh | 9:960dfc71c224 | 139 | |
el15mh | 9:960dfc71c224 | 140 | /** |
el15mh | 9:960dfc71c224 | 141 | * |
el15mh | 9:960dfc71c224 | 142 | * @details - Control Options Function which allows user select control technique. This chanes the boolean value of the '_control' variable. |
el15mh | 10:989e5dbd12ee | 143 | * @param lcd - N5110 Library, used for drawing strings and printing bitmaps |
el15mh | 10:989e5dbd12ee | 144 | * @param pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. |
el15mh | 10:989e5dbd12ee | 145 | * @param animate -Animations Library to provide animations for either joystick or gamepad tilt selection. |
el15mh | 9:960dfc71c224 | 146 | * |
el15mh | 9:960dfc71c224 | 147 | */ |
el15mh | 9:960dfc71c224 | 148 | void controlOptions(N5110 &lcd, Gamepad &pad, Animations &animate); |
el15mh | 9:960dfc71c224 | 149 | |
el15mh | 9:960dfc71c224 | 150 | /** |
el15mh | 9:960dfc71c224 | 151 | * |
el15mh | 9:960dfc71c224 | 152 | * @details - Difficulty Options Function to allow player to select difficulty level. This changes the value of integer variable '_difficulty' to 1, 2, 3 or 4. The maze index for the maze is then selected randomly according to this difficulty value. |
el15mh | 10:989e5dbd12ee | 153 | * @param lcd - N5110 Library, used for drawing strings and printing bitmaps |
el15mh | 10:989e5dbd12ee | 154 | * @param pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. |
el15mh | 9:960dfc71c224 | 155 | * |
el15mh | 9:960dfc71c224 | 156 | */ |
el15mh | 9:960dfc71c224 | 157 | void difficultyOptions(N5110 &lcd, Gamepad &pad); |
el15mh | 9:960dfc71c224 | 158 | |
el15mh | 9:960dfc71c224 | 159 | /** |
el15mh | 9:960dfc71c224 | 160 | * |
el15mh | 9:960dfc71c224 | 161 | * @details - Ball colour function to select the style of ball used in the game. This function changes the value of boolean variable '_colour'; true corresponds to a transparent fill and false to solid fill. |
el15mh | 10:989e5dbd12ee | 162 | * @param lcd - N5110 Library, used for drawing strings and printing bitmaps |
el15mh | 10:989e5dbd12ee | 163 | * @param pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. |
el15mh | 10:989e5dbd12ee | 164 | * @param animate - Animations Library to provide animations for either solid or transparent fill selection. |
el15mh | 9:960dfc71c224 | 165 | * |
el15mh | 9:960dfc71c224 | 166 | */ |
el15mh | 9:960dfc71c224 | 167 | void ballColourOptions(N5110 &lcd, Gamepad &pad, Animations &animate); |
el15mh | 9:960dfc71c224 | 168 | |
el15mh | 9:960dfc71c224 | 169 | /** |
el15mh | 9:960dfc71c224 | 170 | *s |
el15mh | 9:960dfc71c224 | 171 | * @details - LCD Inverse Colour function which allows user to switch colours on the LCD. |
el15mh | 10:989e5dbd12ee | 172 | * @param lcd - N5110 Library, used for drawing strings and printing bitmaps |
el15mh | 10:989e5dbd12ee | 173 | * @param pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. |
el15mh | 9:960dfc71c224 | 174 | * |
el15mh | 9:960dfc71c224 | 175 | */ |
el15mh | 9:960dfc71c224 | 176 | void lcdInverseColour(N5110 &lcd, Gamepad &pad); |
el15mh | 9:960dfc71c224 | 177 | |
el15mh | 9:960dfc71c224 | 178 | /** |
el15mh | 9:960dfc71c224 | 179 | * @details - LCD Background Colour function which changes the PWM value of the LCD backlight LED. |
el15mh | 10:989e5dbd12ee | 180 | * @param lcd - N5110 Library, used for drawing strings and printing bitmaps |
el15mh | 10:989e5dbd12ee | 181 | * @param pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. |
el15mh | 10:989e5dbd12ee | 182 | * @param animate - Animations Library to provide animation for switch. |
el15mh | 9:960dfc71c224 | 183 | */ |
el15mh | 9:960dfc71c224 | 184 | void lcdBackgroundColour(N5110 &lcd, Gamepad &pad, Animations &animate); |
el15mh | 9:960dfc71c224 | 185 | |
el15mh | 9:960dfc71c224 | 186 | /** |
el15mh | 9:960dfc71c224 | 187 | * @details - Animate Joystick function creats a short animation of moving joystick. |
el15mh | 10:989e5dbd12ee | 188 | * @param lcd - N5110 Library, used for drawing strings and printing bitmaps |
el15mh | 10:989e5dbd12ee | 189 | * @param animate - Animations Library to provide animation for moving joystick bitmaps. |
el15mh | 9:960dfc71c224 | 190 | */ |
el15mh | 9:960dfc71c224 | 191 | void animateJoystick(N5110 &lcd, Animations &animate); |
el15mh | 9:960dfc71c224 | 192 | |
el15mh | 9:960dfc71c224 | 193 | /** |
el15mh | 9:960dfc71c224 | 194 | * @details - Animate Gamepad function creats a short animation of moving gamepad. |
el15mh | 10:989e5dbd12ee | 195 | * @param lcd - N5110 Library, used for drawing strings and printing bitmaps |
el15mh | 10:989e5dbd12ee | 196 | * @param animate - Animations Library to provide animation for moving gamepad bitmaps. |
el15mh | 9:960dfc71c224 | 197 | */ |
el15mh | 9:960dfc71c224 | 198 | void animateGamepad(N5110 &lcd, Animations &animate); |
el15mh | 9:960dfc71c224 | 199 | |
el15mh | 9:960dfc71c224 | 200 | /** |
el15mh | 9:960dfc71c224 | 201 | * @details - Animate Stickman function creates a short animation of jumping man to signify goal reached. |
el15mh | 10:989e5dbd12ee | 202 | * @param lcd - N5110 Library, used for drawing strings and printing bitmaps |
el15mh | 10:989e5dbd12ee | 203 | * @param pad - Gamepad Library, used to flash LEDS on and off. |
el15mh | 10:989e5dbd12ee | 204 | * @param animate - Animations Library to provide animation for moving stickman bitmap. |
el15mh | 9:960dfc71c224 | 205 | */ |
el15mh | 9:960dfc71c224 | 206 | void animateStickman(N5110 &lcd, Gamepad &pad, Animations &animate); |
el15mh | 9:960dfc71c224 | 207 | |
el15mh | 9:960dfc71c224 | 208 | /** |
el15mh | 9:960dfc71c224 | 209 | * @details - Game Speed function which changes the FPS used in the game loop. |
el15mh | 10:989e5dbd12ee | 210 | * @param lcd - N5110 Library, used for drawing strings and printing bitmaps |
el15mh | 10:989e5dbd12ee | 211 | * @param pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. |
el15mh | 9:960dfc71c224 | 212 | */ |
el15mh | 9:960dfc71c224 | 213 | void speedSettings(N5110 &lcd, Gamepad &pad); |
el15mh | 9:960dfc71c224 | 214 | |
el15mh | 9:960dfc71c224 | 215 | /** |
el15mh | 9:960dfc71c224 | 216 | * @details - Returns a random number between two set values |
el15mh | 10:989e5dbd12ee | 217 | * @param difficulty - Specified value dictating the level of maze to be played |
el15mh | 9:960dfc71c224 | 218 | */ |
el15mh | 9:960dfc71c224 | 219 | int randomMazeIndexGenerator(int difficulty); |
el15mh | 9:960dfc71c224 | 220 | |
el15mh | 9:960dfc71c224 | 221 | /** |
el15mh | 9:960dfc71c224 | 222 | * @details - Creates _engine object to be used when running the game loop. |
el15mh | 10:989e5dbd12ee | 223 | * @param _engine - instance of MazeEngine class. |
el15mh | 10:989e5dbd12ee | 224 | * @return _mazeIndex |
el15mh | 9:960dfc71c224 | 225 | */ |
el15mh | 9:960dfc71c224 | 226 | MazeEngine _engine; |
el15mh | 9:960dfc71c224 | 227 | |
el15mh | 9:960dfc71c224 | 228 | /** |
el15mh | 9:960dfc71c224 | 229 | * @details - Integer to select the specific maze to be drawn by engine. |
el15mh | 10:989e5dbd12ee | 230 | * @param _mazeIndex - variable to be passed down to engine. |
el15mh | 9:960dfc71c224 | 231 | */ |
el15mh | 9:960dfc71c224 | 232 | int _mazeIndex; |
el15mh | 9:960dfc71c224 | 233 | |
el15mh | 9:960dfc71c224 | 234 | /** |
el15mh | 9:960dfc71c224 | 235 | * @details - Integer to select the desired difficulty by user. |
el15mh | 10:989e5dbd12ee | 236 | * @param _difficulty - variable to be passed down to engine. Value used in randomMazeIndexGenerator() function |
el15mh | 9:960dfc71c224 | 237 | */ |
el15mh | 9:960dfc71c224 | 238 | int _difficulty; |
el15mh | 9:960dfc71c224 | 239 | |
el15mh | 9:960dfc71c224 | 240 | /** |
el15mh | 9:960dfc71c224 | 241 | * @details - Integer to select the frame rate at which the game is updated at. |
el15mh | 10:989e5dbd12ee | 242 | * @param _FPS - value is used as delay between updates when running game loop |
el15mh | 9:960dfc71c224 | 243 | */ |
el15mh | 9:960dfc71c224 | 244 | float _FPS; |
el15mh | 9:960dfc71c224 | 245 | |
el15mh | 9:960dfc71c224 | 246 | /** |
el15mh | 9:960dfc71c224 | 247 | * @details - Boolean value to select the desired control method by user. |
el15mh | 10:989e5dbd12ee | 248 | * @param _control - value of true corresponds to joystick input, false corresponds to accelerometer values used as input. |
el15mh | 9:960dfc71c224 | 249 | */ |
el15mh | 9:960dfc71c224 | 250 | bool _control; |
el15mh | 9:960dfc71c224 | 251 | |
el15mh | 9:960dfc71c224 | 252 | /** |
el15mh | 9:960dfc71c224 | 253 | * @details - Boolean value to select the desired ball fill type. |
el15mh | 10:989e5dbd12ee | 254 | * @param _control - value of true corresponds to transparent fill, false corresponds to solid fill of ball when playing the game. |
el15mh | 9:960dfc71c224 | 255 | */ |
el15mh | 9:960dfc71c224 | 256 | bool _colour; |
el15mh | 9:960dfc71c224 | 257 | |
el15mh | 9:960dfc71c224 | 258 | /** |
el15mh | 9:960dfc71c224 | 259 | * @details - Boolean value to signify when the goal has been reached. |
el15mh | 10:989e5dbd12ee | 260 | * @param _goal - when this variable becomes true, the particular maze has been completed. |
el15mh | 9:960dfc71c224 | 261 | */ |
el15mh | 9:960dfc71c224 | 262 | bool _goal; |
el15mh | 9:960dfc71c224 | 263 | |
el15mh | 9:960dfc71c224 | 264 | /** |
el15mh | 9:960dfc71c224 | 265 | * @details - Boolean value to dictate if the buzzer on the gamepad is to be used in the menu when moving between options or selecting desired parameters. |
el15mh | 10:989e5dbd12ee | 266 | * @param _tone - A true value allows for sound to be used in the menu. |
el15mh | 9:960dfc71c224 | 267 | */ |
el15mh | 9:960dfc71c224 | 268 | bool _tone; |
el15mh | 9:960dfc71c224 | 269 | |
el15mh | 9:960dfc71c224 | 270 | }; |
el15mh | 9:960dfc71c224 | 271 | |
el15mh | 9:960dfc71c224 | 272 | #endif /* MENU_H */ |