Menu class used as basis for program; running the game and allowing the user to change the style and difficulty of the game via an interface.
Menu.cpp@0:b32f6570a26d, 2017-04-02 (annotated)
- Committer:
- el15mh
- Date:
- Sun Apr 02 13:13:29 2017 +0000
- Revision:
- 0:b32f6570a26d
- Child:
- 1:21b7a5edb9c2
menu test using menu class;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el15mh | 0:b32f6570a26d | 1 | /* |
el15mh | 0:b32f6570a26d | 2 | |
el15mh | 0:b32f6570a26d | 3 | @file Menu.cpp |
el15mh | 0:b32f6570a26d | 4 | |
el15mh | 0:b32f6570a26d | 5 | (c) Max Houghton 02.14.17 |
el15mh | 0:b32f6570a26d | 6 | Roller Maze Project, ELEC2645, Univeristy of Leeds |
el15mh | 0:b32f6570a26d | 7 | |
el15mh | 0:b32f6570a26d | 8 | */ |
el15mh | 0:b32f6570a26d | 9 | |
el15mh | 0:b32f6570a26d | 10 | #include "Menu.h" |
el15mh | 0:b32f6570a26d | 11 | |
el15mh | 0:b32f6570a26d | 12 | // constructor function used when object is initialised |
el15mh | 0:b32f6570a26d | 13 | Menu::Menu() |
el15mh | 0:b32f6570a26d | 14 | { |
el15mh | 0:b32f6570a26d | 15 | |
el15mh | 0:b32f6570a26d | 16 | } |
el15mh | 0:b32f6570a26d | 17 | |
el15mh | 0:b32f6570a26d | 18 | // destructor function |
el15mh | 0:b32f6570a26d | 19 | Menu::~Menu() |
el15mh | 0:b32f6570a26d | 20 | { |
el15mh | 0:b32f6570a26d | 21 | |
el15mh | 0:b32f6570a26d | 22 | } |
el15mh | 0:b32f6570a26d | 23 | |
el15mh | 0:b32f6570a26d | 24 | void Menu::main() |
el15mh | 0:b32f6570a26d | 25 | { |
el15mh | 0:b32f6570a26d | 26 | int selected = 0; |
el15mh | 0:b32f6570a26d | 27 | |
el15mh | 0:b32f6570a26d | 28 | while(1) { |
el15mh | 0:b32f6570a26d | 29 | |
el15mh | 0:b32f6570a26d | 30 | // lcd.printString("Testing", 0, 2); |
el15mh | 0:b32f6570a26d | 31 | switch (selected) { |
el15mh | 0:b32f6570a26d | 32 | |
el15mh | 0:b32f6570a26d | 33 | case 1: |
el15mh | 0:b32f6570a26d | 34 | |
el15mh | 0:b32f6570a26d | 35 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 36 | lcd.printString(">Play game", 0, 0); |
el15mh | 0:b32f6570a26d | 37 | lcd.printString(" Game options", 0, 1); |
el15mh | 0:b32f6570a26d | 38 | lcd.printString(" LCD settings", 0, 2); |
el15mh | 0:b32f6570a26d | 39 | lcd.printString(" Sound", 0, 3); |
el15mh | 0:b32f6570a26d | 40 | |
el15mh | 0:b32f6570a26d | 41 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 42 | |
el15mh | 0:b32f6570a26d | 43 | // either clicking joystick or pressing A selects function |
el15mh | 0:b32f6570a26d | 44 | if (pad.check_event(Gamepad::A_PRESSED) || |
el15mh | 0:b32f6570a26d | 45 | pad.check_event(Gamepad::JOY_PRESSED)){ |
el15mh | 0:b32f6570a26d | 46 | |
el15mh | 0:b32f6570a26d | 47 | play(); // call the game function |
el15mh | 0:b32f6570a26d | 48 | } |
el15mh | 0:b32f6570a26d | 49 | |
el15mh | 0:b32f6570a26d | 50 | wait_ms(250); // 1s propogation delay |
el15mh | 0:b32f6570a26d | 51 | |
el15mh | 0:b32f6570a26d | 52 | break; |
el15mh | 0:b32f6570a26d | 53 | |
el15mh | 0:b32f6570a26d | 54 | case 2: |
el15mh | 0:b32f6570a26d | 55 | |
el15mh | 0:b32f6570a26d | 56 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 57 | lcd.printString(" Play game", 0, 0); |
el15mh | 0:b32f6570a26d | 58 | lcd.printString(">Game options", 0, 1); |
el15mh | 0:b32f6570a26d | 59 | lcd.printString(" LCD settings", 0, 2); |
el15mh | 0:b32f6570a26d | 60 | lcd.printString(" Sound", 0, 3); |
el15mh | 0:b32f6570a26d | 61 | |
el15mh | 0:b32f6570a26d | 62 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 63 | |
el15mh | 0:b32f6570a26d | 64 | |
el15mh | 0:b32f6570a26d | 65 | if (pad.check_event(Gamepad::A_PRESSED) || |
el15mh | 0:b32f6570a26d | 66 | pad.check_event(Gamepad::JOY_PRESSED)){ |
el15mh | 0:b32f6570a26d | 67 | |
el15mh | 0:b32f6570a26d | 68 | options(); |
el15mh | 0:b32f6570a26d | 69 | } |
el15mh | 0:b32f6570a26d | 70 | |
el15mh | 0:b32f6570a26d | 71 | wait_ms(250); // 1s propogation delay |
el15mh | 0:b32f6570a26d | 72 | |
el15mh | 0:b32f6570a26d | 73 | break; |
el15mh | 0:b32f6570a26d | 74 | |
el15mh | 0:b32f6570a26d | 75 | case 3: |
el15mh | 0:b32f6570a26d | 76 | |
el15mh | 0:b32f6570a26d | 77 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 78 | lcd.printString(" Play game", 0, 0); |
el15mh | 0:b32f6570a26d | 79 | lcd.printString(" Game options", 0, 1); |
el15mh | 0:b32f6570a26d | 80 | lcd.printString(">LCD settings", 0, 2); |
el15mh | 0:b32f6570a26d | 81 | lcd.printString(" Sound", 0, 3); |
el15mh | 0:b32f6570a26d | 82 | |
el15mh | 0:b32f6570a26d | 83 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 84 | |
el15mh | 0:b32f6570a26d | 85 | |
el15mh | 0:b32f6570a26d | 86 | if (pad.check_event(Gamepad::A_PRESSED) || |
el15mh | 0:b32f6570a26d | 87 | pad.check_event(Gamepad::JOY_PRESSED)){ |
el15mh | 0:b32f6570a26d | 88 | |
el15mh | 0:b32f6570a26d | 89 | lcdSettings(); |
el15mh | 0:b32f6570a26d | 90 | } |
el15mh | 0:b32f6570a26d | 91 | |
el15mh | 0:b32f6570a26d | 92 | wait_ms(250); // 1s propogation delay |
el15mh | 0:b32f6570a26d | 93 | |
el15mh | 0:b32f6570a26d | 94 | break; |
el15mh | 0:b32f6570a26d | 95 | |
el15mh | 0:b32f6570a26d | 96 | case 4: |
el15mh | 0:b32f6570a26d | 97 | |
el15mh | 0:b32f6570a26d | 98 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 99 | lcd.printString(" Play game", 0, 0); |
el15mh | 0:b32f6570a26d | 100 | lcd.printString(" Game options", 0, 1); |
el15mh | 0:b32f6570a26d | 101 | lcd.printString(" LCD settings", 0, 2); |
el15mh | 0:b32f6570a26d | 102 | lcd.printString(">Sound", 0, 3); |
el15mh | 0:b32f6570a26d | 103 | |
el15mh | 0:b32f6570a26d | 104 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 105 | |
el15mh | 0:b32f6570a26d | 106 | |
el15mh | 0:b32f6570a26d | 107 | if (pad.check_event(Gamepad::A_PRESSED) || |
el15mh | 0:b32f6570a26d | 108 | pad.check_event(Gamepad::JOY_PRESSED)){ |
el15mh | 0:b32f6570a26d | 109 | |
el15mh | 0:b32f6570a26d | 110 | soundSettings(); |
el15mh | 0:b32f6570a26d | 111 | } |
el15mh | 0:b32f6570a26d | 112 | |
el15mh | 0:b32f6570a26d | 113 | wait_ms(250); // 1s propogation delay |
el15mh | 0:b32f6570a26d | 114 | |
el15mh | 0:b32f6570a26d | 115 | break; |
el15mh | 0:b32f6570a26d | 116 | |
el15mh | 0:b32f6570a26d | 117 | default: |
el15mh | 0:b32f6570a26d | 118 | |
el15mh | 0:b32f6570a26d | 119 | selected = 1; |
el15mh | 0:b32f6570a26d | 120 | |
el15mh | 0:b32f6570a26d | 121 | break; |
el15mh | 0:b32f6570a26d | 122 | } |
el15mh | 0:b32f6570a26d | 123 | |
el15mh | 0:b32f6570a26d | 124 | char d = pad.get_direction(); |
el15mh | 0:b32f6570a26d | 125 | |
el15mh | 0:b32f6570a26d | 126 | if ((d == NW) || |
el15mh | 0:b32f6570a26d | 127 | (d == N) || |
el15mh | 0:b32f6570a26d | 128 | (d == NE)){ |
el15mh | 0:b32f6570a26d | 129 | |
el15mh | 0:b32f6570a26d | 130 | selected -= 1; |
el15mh | 0:b32f6570a26d | 131 | } |
el15mh | 0:b32f6570a26d | 132 | |
el15mh | 0:b32f6570a26d | 133 | if ((d == SW) || |
el15mh | 0:b32f6570a26d | 134 | (d == S) || |
el15mh | 0:b32f6570a26d | 135 | (d == SE)){ |
el15mh | 0:b32f6570a26d | 136 | |
el15mh | 0:b32f6570a26d | 137 | selected += 1; |
el15mh | 0:b32f6570a26d | 138 | } |
el15mh | 0:b32f6570a26d | 139 | |
el15mh | 0:b32f6570a26d | 140 | // printf("Joystick position = %c \n", d); |
el15mh | 0:b32f6570a26d | 141 | // printf("Selected = %i \n", selected); |
el15mh | 0:b32f6570a26d | 142 | |
el15mh | 0:b32f6570a26d | 143 | } |
el15mh | 0:b32f6570a26d | 144 | } |
el15mh | 0:b32f6570a26d | 145 | |
el15mh | 0:b32f6570a26d | 146 | void Menu::options() |
el15mh | 0:b32f6570a26d | 147 | { |
el15mh | 0:b32f6570a26d | 148 | int exit = 0; |
el15mh | 0:b32f6570a26d | 149 | int selected = 0; |
el15mh | 0:b32f6570a26d | 150 | |
el15mh | 0:b32f6570a26d | 151 | while(exit == 0) { |
el15mh | 0:b32f6570a26d | 152 | |
el15mh | 0:b32f6570a26d | 153 | // printf("While loop 1 \n"); |
el15mh | 0:b32f6570a26d | 154 | // printf("Selected = %i \n", selected); |
el15mh | 0:b32f6570a26d | 155 | switch (selected) { |
el15mh | 0:b32f6570a26d | 156 | |
el15mh | 0:b32f6570a26d | 157 | case 1: |
el15mh | 0:b32f6570a26d | 158 | |
el15mh | 0:b32f6570a26d | 159 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 160 | // displays options page with indicator on first |
el15mh | 0:b32f6570a26d | 161 | lcd.printString("Game Options:", 0, 0); |
el15mh | 0:b32f6570a26d | 162 | lcd.printString(">Difficulty", 0, 2); |
el15mh | 0:b32f6570a26d | 163 | lcd.printString(" Ball Colour", 0, 3); |
el15mh | 0:b32f6570a26d | 164 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 165 | |
el15mh | 0:b32f6570a26d | 166 | if (pad.check_event(Gamepad::A_PRESSED) || |
el15mh | 0:b32f6570a26d | 167 | pad.check_event(Gamepad::JOY_PRESSED)){ |
el15mh | 0:b32f6570a26d | 168 | |
el15mh | 0:b32f6570a26d | 169 | difficultyOptions(); |
el15mh | 0:b32f6570a26d | 170 | } |
el15mh | 0:b32f6570a26d | 171 | |
el15mh | 0:b32f6570a26d | 172 | wait_ms(250); |
el15mh | 0:b32f6570a26d | 173 | |
el15mh | 0:b32f6570a26d | 174 | break; |
el15mh | 0:b32f6570a26d | 175 | |
el15mh | 0:b32f6570a26d | 176 | case 2: |
el15mh | 0:b32f6570a26d | 177 | |
el15mh | 0:b32f6570a26d | 178 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 179 | // displays options page with indicator on second |
el15mh | 0:b32f6570a26d | 180 | lcd.printString("Game Options:", 0, 0); |
el15mh | 0:b32f6570a26d | 181 | lcd.printString(" Difficulty", 0, 2); |
el15mh | 0:b32f6570a26d | 182 | lcd.printString(">Ball Colour", 0, 3); |
el15mh | 0:b32f6570a26d | 183 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 184 | |
el15mh | 0:b32f6570a26d | 185 | // if second option selected |
el15mh | 0:b32f6570a26d | 186 | if (pad.check_event(Gamepad::A_PRESSED) || |
el15mh | 0:b32f6570a26d | 187 | pad.check_event(Gamepad::JOY_PRESSED)){ |
el15mh | 0:b32f6570a26d | 188 | |
el15mh | 0:b32f6570a26d | 189 | colourOptions(); |
el15mh | 0:b32f6570a26d | 190 | } |
el15mh | 0:b32f6570a26d | 191 | |
el15mh | 0:b32f6570a26d | 192 | wait_ms(250); |
el15mh | 0:b32f6570a26d | 193 | |
el15mh | 0:b32f6570a26d | 194 | break; |
el15mh | 0:b32f6570a26d | 195 | |
el15mh | 0:b32f6570a26d | 196 | default: |
el15mh | 0:b32f6570a26d | 197 | |
el15mh | 0:b32f6570a26d | 198 | selected = 1; |
el15mh | 0:b32f6570a26d | 199 | |
el15mh | 0:b32f6570a26d | 200 | break; |
el15mh | 0:b32f6570a26d | 201 | } |
el15mh | 0:b32f6570a26d | 202 | |
el15mh | 0:b32f6570a26d | 203 | char d = pad.get_direction(); |
el15mh | 0:b32f6570a26d | 204 | |
el15mh | 0:b32f6570a26d | 205 | if ((d == NW) || |
el15mh | 0:b32f6570a26d | 206 | (d == N) || |
el15mh | 0:b32f6570a26d | 207 | (d == NE)){ |
el15mh | 0:b32f6570a26d | 208 | |
el15mh | 0:b32f6570a26d | 209 | selected -= 1; |
el15mh | 0:b32f6570a26d | 210 | } |
el15mh | 0:b32f6570a26d | 211 | |
el15mh | 0:b32f6570a26d | 212 | if ((d == SW) || |
el15mh | 0:b32f6570a26d | 213 | (d == S) || |
el15mh | 0:b32f6570a26d | 214 | (d == SE)){ |
el15mh | 0:b32f6570a26d | 215 | |
el15mh | 0:b32f6570a26d | 216 | selected += 1; |
el15mh | 0:b32f6570a26d | 217 | } |
el15mh | 0:b32f6570a26d | 218 | |
el15mh | 0:b32f6570a26d | 219 | if (pad.check_event(Gamepad::Y_PRESSED)){ |
el15mh | 0:b32f6570a26d | 220 | |
el15mh | 0:b32f6570a26d | 221 | selected -= 1; |
el15mh | 0:b32f6570a26d | 222 | } |
el15mh | 0:b32f6570a26d | 223 | |
el15mh | 0:b32f6570a26d | 224 | if (pad.check_event(Gamepad::X_PRESSED)){ |
el15mh | 0:b32f6570a26d | 225 | |
el15mh | 0:b32f6570a26d | 226 | selected += 1; |
el15mh | 0:b32f6570a26d | 227 | } |
el15mh | 0:b32f6570a26d | 228 | |
el15mh | 0:b32f6570a26d | 229 | if (pad.check_event(Gamepad::BACK_PRESSED)){ |
el15mh | 0:b32f6570a26d | 230 | |
el15mh | 0:b32f6570a26d | 231 | exit = 1; |
el15mh | 0:b32f6570a26d | 232 | } |
el15mh | 0:b32f6570a26d | 233 | } |
el15mh | 0:b32f6570a26d | 234 | } |
el15mh | 0:b32f6570a26d | 235 | |
el15mh | 0:b32f6570a26d | 236 | void lcdSettings() |
el15mh | 0:b32f6570a26d | 237 | { |
el15mh | 0:b32f6570a26d | 238 | int exit = 0; |
el15mh | 0:b32f6570a26d | 239 | int selected = 0; |
el15mh | 0:b32f6570a26d | 240 | |
el15mh | 0:b32f6570a26d | 241 | while(exit == 0) { |
el15mh | 0:b32f6570a26d | 242 | |
el15mh | 0:b32f6570a26d | 243 | // printf("While loop 1 \n"); |
el15mh | 0:b32f6570a26d | 244 | // printf("Selected = %i \n", selected); |
el15mh | 0:b32f6570a26d | 245 | switch (selected) { |
el15mh | 0:b32f6570a26d | 246 | |
el15mh | 0:b32f6570a26d | 247 | case 1: |
el15mh | 0:b32f6570a26d | 248 | |
el15mh | 0:b32f6570a26d | 249 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 250 | // displays options page with indicator on first |
el15mh | 0:b32f6570a26d | 251 | lcd.printString("LCD Settings:", 0, 0); |
el15mh | 0:b32f6570a26d | 252 | lcd.printString(">Brightness", 0, 2); |
el15mh | 0:b32f6570a26d | 253 | lcd.printString(" Invert Colour", 0, 3); |
el15mh | 0:b32f6570a26d | 254 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 255 | |
el15mh | 0:b32f6570a26d | 256 | if (pad.check_event(Gamepad::A_PRESSED) || |
el15mh | 0:b32f6570a26d | 257 | pad.check_event(Gamepad::JOY_PRESSED)){ |
el15mh | 0:b32f6570a26d | 258 | |
el15mh | 0:b32f6570a26d | 259 | lcdBackgroundColour(); |
el15mh | 0:b32f6570a26d | 260 | } |
el15mh | 0:b32f6570a26d | 261 | |
el15mh | 0:b32f6570a26d | 262 | wait_ms(250); |
el15mh | 0:b32f6570a26d | 263 | |
el15mh | 0:b32f6570a26d | 264 | break; |
el15mh | 0:b32f6570a26d | 265 | |
el15mh | 0:b32f6570a26d | 266 | case 2: |
el15mh | 0:b32f6570a26d | 267 | |
el15mh | 0:b32f6570a26d | 268 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 269 | // displays options page with indicator on second |
el15mh | 0:b32f6570a26d | 270 | lcd.printString("LCD Settings:", 0, 0); |
el15mh | 0:b32f6570a26d | 271 | lcd.printString(" Brightness", 0, 2); |
el15mh | 0:b32f6570a26d | 272 | lcd.printString(">Invert Colour", 0, 3); |
el15mh | 0:b32f6570a26d | 273 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 274 | |
el15mh | 0:b32f6570a26d | 275 | |
el15mh | 0:b32f6570a26d | 276 | // if second option selected |
el15mh | 0:b32f6570a26d | 277 | if (pad.check_event(Gamepad::A_PRESSED) || |
el15mh | 0:b32f6570a26d | 278 | pad.check_event(Gamepad::JOY_PRESSED)){ |
el15mh | 0:b32f6570a26d | 279 | |
el15mh | 0:b32f6570a26d | 280 | lcdInverseColour(); |
el15mh | 0:b32f6570a26d | 281 | } |
el15mh | 0:b32f6570a26d | 282 | |
el15mh | 0:b32f6570a26d | 283 | wait_ms(250); |
el15mh | 0:b32f6570a26d | 284 | |
el15mh | 0:b32f6570a26d | 285 | break; |
el15mh | 0:b32f6570a26d | 286 | |
el15mh | 0:b32f6570a26d | 287 | default: |
el15mh | 0:b32f6570a26d | 288 | |
el15mh | 0:b32f6570a26d | 289 | selected = 1; |
el15mh | 0:b32f6570a26d | 290 | |
el15mh | 0:b32f6570a26d | 291 | break; |
el15mh | 0:b32f6570a26d | 292 | } |
el15mh | 0:b32f6570a26d | 293 | |
el15mh | 0:b32f6570a26d | 294 | char d = pad.get_direction(); |
el15mh | 0:b32f6570a26d | 295 | |
el15mh | 0:b32f6570a26d | 296 | if ((d == NW) || |
el15mh | 0:b32f6570a26d | 297 | (d == N) || |
el15mh | 0:b32f6570a26d | 298 | (d == NE)){ |
el15mh | 0:b32f6570a26d | 299 | |
el15mh | 0:b32f6570a26d | 300 | selected -= 1; |
el15mh | 0:b32f6570a26d | 301 | } |
el15mh | 0:b32f6570a26d | 302 | |
el15mh | 0:b32f6570a26d | 303 | if ((d == SW) || |
el15mh | 0:b32f6570a26d | 304 | (d == S) || |
el15mh | 0:b32f6570a26d | 305 | (d == SE)){ |
el15mh | 0:b32f6570a26d | 306 | |
el15mh | 0:b32f6570a26d | 307 | selected += 1; |
el15mh | 0:b32f6570a26d | 308 | } |
el15mh | 0:b32f6570a26d | 309 | |
el15mh | 0:b32f6570a26d | 310 | if (pad.check_event(Gamepad::Y_PRESSED)){ |
el15mh | 0:b32f6570a26d | 311 | |
el15mh | 0:b32f6570a26d | 312 | selected -= 1; |
el15mh | 0:b32f6570a26d | 313 | } |
el15mh | 0:b32f6570a26d | 314 | |
el15mh | 0:b32f6570a26d | 315 | if (pad.check_event(Gamepad::X_PRESSED)){ |
el15mh | 0:b32f6570a26d | 316 | |
el15mh | 0:b32f6570a26d | 317 | selected += 1; |
el15mh | 0:b32f6570a26d | 318 | } |
el15mh | 0:b32f6570a26d | 319 | |
el15mh | 0:b32f6570a26d | 320 | if (pad.check_event(Gamepad::BACK_PRESSED)){ |
el15mh | 0:b32f6570a26d | 321 | |
el15mh | 0:b32f6570a26d | 322 | exit = 1; |
el15mh | 0:b32f6570a26d | 323 | } |
el15mh | 0:b32f6570a26d | 324 | |
el15mh | 0:b32f6570a26d | 325 | } |
el15mh | 0:b32f6570a26d | 326 | |
el15mh | 0:b32f6570a26d | 327 | |
el15mh | 0:b32f6570a26d | 328 | } |
el15mh | 0:b32f6570a26d | 329 | |
el15mh | 0:b32f6570a26d | 330 | void soundSettings() |
el15mh | 0:b32f6570a26d | 331 | { |
el15mh | 0:b32f6570a26d | 332 | |
el15mh | 0:b32f6570a26d | 333 | int exit = 0; |
el15mh | 0:b32f6570a26d | 334 | // pad.tone(750.0,0.1); |
el15mh | 0:b32f6570a26d | 335 | |
el15mh | 0:b32f6570a26d | 336 | while (exit == 0){ |
el15mh | 0:b32f6570a26d | 337 | |
el15mh | 0:b32f6570a26d | 338 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 339 | lcd.printString("Sound settings", 0, 2); |
el15mh | 0:b32f6570a26d | 340 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 341 | |
el15mh | 0:b32f6570a26d | 342 | if(pad.check_event(Gamepad::BACK_PRESSED)){ |
el15mh | 0:b32f6570a26d | 343 | |
el15mh | 0:b32f6570a26d | 344 | exit = 1; |
el15mh | 0:b32f6570a26d | 345 | } |
el15mh | 0:b32f6570a26d | 346 | } |
el15mh | 0:b32f6570a26d | 347 | |
el15mh | 0:b32f6570a26d | 348 | } |
el15mh | 0:b32f6570a26d | 349 | |
el15mh | 0:b32f6570a26d | 350 | void difficultyOptions() |
el15mh | 0:b32f6570a26d | 351 | { |
el15mh | 0:b32f6570a26d | 352 | int selected = 0; |
el15mh | 0:b32f6570a26d | 353 | int exit = 0; |
el15mh | 0:b32f6570a26d | 354 | |
el15mh | 0:b32f6570a26d | 355 | while(exit == 0){ |
el15mh | 0:b32f6570a26d | 356 | |
el15mh | 0:b32f6570a26d | 357 | switch(selected){ |
el15mh | 0:b32f6570a26d | 358 | |
el15mh | 0:b32f6570a26d | 359 | case 1: |
el15mh | 0:b32f6570a26d | 360 | |
el15mh | 0:b32f6570a26d | 361 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 362 | lcd.printString("Difficulty: ", 0, 0); |
el15mh | 0:b32f6570a26d | 363 | lcd.printString(">Easy", 0, 2); |
el15mh | 0:b32f6570a26d | 364 | lcd.printString(" Hard", 0, 3); |
el15mh | 0:b32f6570a26d | 365 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 366 | |
el15mh | 0:b32f6570a26d | 367 | if (pad.check_event(Gamepad::A_PRESSED) || |
el15mh | 0:b32f6570a26d | 368 | pad.check_event(Gamepad::JOY_PRESSED)){ |
el15mh | 0:b32f6570a26d | 369 | |
el15mh | 0:b32f6570a26d | 370 | // maze.mazeIndex = 0; |
el15mh | 0:b32f6570a26d | 371 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 372 | lcd.printString("Easy mode", 0, 1); |
el15mh | 0:b32f6570a26d | 373 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 374 | wait(2); |
el15mh | 0:b32f6570a26d | 375 | |
el15mh | 0:b32f6570a26d | 376 | exit = 1; |
el15mh | 0:b32f6570a26d | 377 | } |
el15mh | 0:b32f6570a26d | 378 | |
el15mh | 0:b32f6570a26d | 379 | break; |
el15mh | 0:b32f6570a26d | 380 | |
el15mh | 0:b32f6570a26d | 381 | case 2: |
el15mh | 0:b32f6570a26d | 382 | |
el15mh | 0:b32f6570a26d | 383 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 384 | lcd.printString("Difficulty: ", 0, 0); |
el15mh | 0:b32f6570a26d | 385 | lcd.printString(" Easy", 0, 2); |
el15mh | 0:b32f6570a26d | 386 | lcd.printString(">Hard", 0, 3); |
el15mh | 0:b32f6570a26d | 387 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 388 | |
el15mh | 0:b32f6570a26d | 389 | if (pad.check_event(Gamepad::A_PRESSED) || |
el15mh | 0:b32f6570a26d | 390 | pad.check_event(Gamepad::JOY_PRESSED)){ |
el15mh | 0:b32f6570a26d | 391 | |
el15mh | 0:b32f6570a26d | 392 | // maze.mazeIndex = 1; |
el15mh | 0:b32f6570a26d | 393 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 394 | lcd.printString("Hard mode", 0, 1); |
el15mh | 0:b32f6570a26d | 395 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 396 | wait(2); |
el15mh | 0:b32f6570a26d | 397 | |
el15mh | 0:b32f6570a26d | 398 | exit = 1; |
el15mh | 0:b32f6570a26d | 399 | } |
el15mh | 0:b32f6570a26d | 400 | |
el15mh | 0:b32f6570a26d | 401 | break; |
el15mh | 0:b32f6570a26d | 402 | |
el15mh | 0:b32f6570a26d | 403 | default: |
el15mh | 0:b32f6570a26d | 404 | |
el15mh | 0:b32f6570a26d | 405 | selected = 1; |
el15mh | 0:b32f6570a26d | 406 | |
el15mh | 0:b32f6570a26d | 407 | break; |
el15mh | 0:b32f6570a26d | 408 | |
el15mh | 0:b32f6570a26d | 409 | } |
el15mh | 0:b32f6570a26d | 410 | char d = pad.get_direction(); |
el15mh | 0:b32f6570a26d | 411 | |
el15mh | 0:b32f6570a26d | 412 | if ((d == NW) || |
el15mh | 0:b32f6570a26d | 413 | (d == N) || |
el15mh | 0:b32f6570a26d | 414 | (d == NE)){ |
el15mh | 0:b32f6570a26d | 415 | |
el15mh | 0:b32f6570a26d | 416 | selected -= 1; |
el15mh | 0:b32f6570a26d | 417 | } |
el15mh | 0:b32f6570a26d | 418 | |
el15mh | 0:b32f6570a26d | 419 | if ((d == SW) || |
el15mh | 0:b32f6570a26d | 420 | (d == S) || |
el15mh | 0:b32f6570a26d | 421 | (d == SE)){ |
el15mh | 0:b32f6570a26d | 422 | |
el15mh | 0:b32f6570a26d | 423 | selected += 1; |
el15mh | 0:b32f6570a26d | 424 | } |
el15mh | 0:b32f6570a26d | 425 | |
el15mh | 0:b32f6570a26d | 426 | |
el15mh | 0:b32f6570a26d | 427 | if (pad.check_event(Gamepad::BACK_PRESSED)){ |
el15mh | 0:b32f6570a26d | 428 | |
el15mh | 0:b32f6570a26d | 429 | exit = 1; |
el15mh | 0:b32f6570a26d | 430 | } |
el15mh | 0:b32f6570a26d | 431 | |
el15mh | 0:b32f6570a26d | 432 | } |
el15mh | 0:b32f6570a26d | 433 | |
el15mh | 0:b32f6570a26d | 434 | |
el15mh | 0:b32f6570a26d | 435 | } |
el15mh | 0:b32f6570a26d | 436 | |
el15mh | 0:b32f6570a26d | 437 | void lcdColourOptions() |
el15mh | 0:b32f6570a26d | 438 | { |
el15mh | 0:b32f6570a26d | 439 | int selected = 0; |
el15mh | 0:b32f6570a26d | 440 | int exit = 0; |
el15mh | 0:b32f6570a26d | 441 | while(exit == 0){ |
el15mh | 0:b32f6570a26d | 442 | |
el15mh | 0:b32f6570a26d | 443 | switch(selected){ |
el15mh | 0:b32f6570a26d | 444 | |
el15mh | 0:b32f6570a26d | 445 | case 1: |
el15mh | 0:b32f6570a26d | 446 | |
el15mh | 0:b32f6570a26d | 447 | // printf("case 2.1"); |
el15mh | 0:b32f6570a26d | 448 | |
el15mh | 0:b32f6570a26d | 449 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 450 | lcd.printString("Ball colour: ", 0, 0); |
el15mh | 0:b32f6570a26d | 451 | lcd.printString(">Transparent", 0, 2); |
el15mh | 0:b32f6570a26d | 452 | lcd.printString(" Solid", 0, 3); |
el15mh | 0:b32f6570a26d | 453 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 454 | |
el15mh | 0:b32f6570a26d | 455 | if (pad.check_event(Gamepad::A_PRESSED) || |
el15mh | 0:b32f6570a26d | 456 | pad.check_event(Gamepad::JOY_PRESSED)){ |
el15mh | 0:b32f6570a26d | 457 | |
el15mh | 0:b32f6570a26d | 458 | // ball.ballColour = 0; |
el15mh | 0:b32f6570a26d | 459 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 460 | lcd.printString("Transparent", 0, 1); |
el15mh | 0:b32f6570a26d | 461 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 462 | wait(2); |
el15mh | 0:b32f6570a26d | 463 | |
el15mh | 0:b32f6570a26d | 464 | exit = 1; |
el15mh | 0:b32f6570a26d | 465 | } |
el15mh | 0:b32f6570a26d | 466 | |
el15mh | 0:b32f6570a26d | 467 | break; |
el15mh | 0:b32f6570a26d | 468 | |
el15mh | 0:b32f6570a26d | 469 | case 2: |
el15mh | 0:b32f6570a26d | 470 | |
el15mh | 0:b32f6570a26d | 471 | // printf("case 2.2"); |
el15mh | 0:b32f6570a26d | 472 | |
el15mh | 0:b32f6570a26d | 473 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 474 | lcd.printString("Ball colour: ", 0, 0); |
el15mh | 0:b32f6570a26d | 475 | lcd.printString(" Transparent", 0, 2); |
el15mh | 0:b32f6570a26d | 476 | lcd.printString(">Solid", 0, 3); |
el15mh | 0:b32f6570a26d | 477 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 478 | |
el15mh | 0:b32f6570a26d | 479 | if (pad.check_event(Gamepad::A_PRESSED) || |
el15mh | 0:b32f6570a26d | 480 | pad.check_event(Gamepad::JOY_PRESSED)){ |
el15mh | 0:b32f6570a26d | 481 | |
el15mh | 0:b32f6570a26d | 482 | // ball.ballColour = 1; |
el15mh | 0:b32f6570a26d | 483 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 484 | lcd.printString("Solid", 0, 1); |
el15mh | 0:b32f6570a26d | 485 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 486 | wait(2); |
el15mh | 0:b32f6570a26d | 487 | |
el15mh | 0:b32f6570a26d | 488 | exit = 1; |
el15mh | 0:b32f6570a26d | 489 | } |
el15mh | 0:b32f6570a26d | 490 | |
el15mh | 0:b32f6570a26d | 491 | break; |
el15mh | 0:b32f6570a26d | 492 | |
el15mh | 0:b32f6570a26d | 493 | default: |
el15mh | 0:b32f6570a26d | 494 | |
el15mh | 0:b32f6570a26d | 495 | selected = 1; |
el15mh | 0:b32f6570a26d | 496 | |
el15mh | 0:b32f6570a26d | 497 | break; |
el15mh | 0:b32f6570a26d | 498 | } |
el15mh | 0:b32f6570a26d | 499 | |
el15mh | 0:b32f6570a26d | 500 | char d = pad.get_direction(); |
el15mh | 0:b32f6570a26d | 501 | |
el15mh | 0:b32f6570a26d | 502 | if ((d == NW) || |
el15mh | 0:b32f6570a26d | 503 | (d == N) || |
el15mh | 0:b32f6570a26d | 504 | (d == NE)){ |
el15mh | 0:b32f6570a26d | 505 | |
el15mh | 0:b32f6570a26d | 506 | selected -= 1; |
el15mh | 0:b32f6570a26d | 507 | } |
el15mh | 0:b32f6570a26d | 508 | |
el15mh | 0:b32f6570a26d | 509 | if ((d == SW) || |
el15mh | 0:b32f6570a26d | 510 | (d == S) || |
el15mh | 0:b32f6570a26d | 511 | (d == SE)){ |
el15mh | 0:b32f6570a26d | 512 | |
el15mh | 0:b32f6570a26d | 513 | selected += 1; |
el15mh | 0:b32f6570a26d | 514 | } |
el15mh | 0:b32f6570a26d | 515 | |
el15mh | 0:b32f6570a26d | 516 | if (pad.check_event(Gamepad::BACK_PRESSED)){ |
el15mh | 0:b32f6570a26d | 517 | |
el15mh | 0:b32f6570a26d | 518 | exit = 1; |
el15mh | 0:b32f6570a26d | 519 | } |
el15mh | 0:b32f6570a26d | 520 | } |
el15mh | 0:b32f6570a26d | 521 | |
el15mh | 0:b32f6570a26d | 522 | |
el15mh | 0:b32f6570a26d | 523 | } |
el15mh | 0:b32f6570a26d | 524 | |
el15mh | 0:b32f6570a26d | 525 | void lcdInverseColour() |
el15mh | 0:b32f6570a26d | 526 | { |
el15mh | 0:b32f6570a26d | 527 | int exit = 0; |
el15mh | 0:b32f6570a26d | 528 | |
el15mh | 0:b32f6570a26d | 529 | while (exit == 0) { |
el15mh | 0:b32f6570a26d | 530 | |
el15mh | 0:b32f6570a26d | 531 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 532 | lcd.printString("Press A to", 0, 0); |
el15mh | 0:b32f6570a26d | 533 | lcd.printString("invert colours", 0, 1); |
el15mh | 0:b32f6570a26d | 534 | lcd.printString("Press B to", 0, 3); |
el15mh | 0:b32f6570a26d | 535 | lcd.printString("revert to", 0, 4); |
el15mh | 0:b32f6570a26d | 536 | lcd.printString("normal", 0, 5); |
el15mh | 0:b32f6570a26d | 537 | |
el15mh | 0:b32f6570a26d | 538 | if (pad.check_event(Gamepad::A_PRESSED)){ |
el15mh | 0:b32f6570a26d | 539 | |
el15mh | 0:b32f6570a26d | 540 | lcd.inverseMode(); |
el15mh | 0:b32f6570a26d | 541 | |
el15mh | 0:b32f6570a26d | 542 | } |
el15mh | 0:b32f6570a26d | 543 | |
el15mh | 0:b32f6570a26d | 544 | if (pad.check_event(Gamepad::B_PRESSED)){ |
el15mh | 0:b32f6570a26d | 545 | |
el15mh | 0:b32f6570a26d | 546 | lcd.normalMode(); |
el15mh | 0:b32f6570a26d | 547 | |
el15mh | 0:b32f6570a26d | 548 | } |
el15mh | 0:b32f6570a26d | 549 | |
el15mh | 0:b32f6570a26d | 550 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 551 | |
el15mh | 0:b32f6570a26d | 552 | if (pad.check_event(Gamepad::BACK_PRESSED)){ |
el15mh | 0:b32f6570a26d | 553 | |
el15mh | 0:b32f6570a26d | 554 | exit = 1; |
el15mh | 0:b32f6570a26d | 555 | } |
el15mh | 0:b32f6570a26d | 556 | } |
el15mh | 0:b32f6570a26d | 557 | |
el15mh | 0:b32f6570a26d | 558 | |
el15mh | 0:b32f6570a26d | 559 | } |
el15mh | 0:b32f6570a26d | 560 | |
el15mh | 0:b32f6570a26d | 561 | void lcdBackgroundColour() |
el15mh | 0:b32f6570a26d | 562 | { |
el15mh | 0:b32f6570a26d | 563 | int exit = 0; |
el15mh | 0:b32f6570a26d | 564 | |
el15mh | 0:b32f6570a26d | 565 | while (exit == 0) { |
el15mh | 0:b32f6570a26d | 566 | |
el15mh | 0:b32f6570a26d | 567 | lcd.clear(); |
el15mh | 0:b32f6570a26d | 568 | lcd.printString("BRIGHTNESS", 0, 0); |
el15mh | 0:b32f6570a26d | 569 | lcd.printString("Use DIAL --->", 0, 1); |
el15mh | 0:b32f6570a26d | 570 | lcd.printString("to adjust", 0, 2); |
el15mh | 0:b32f6570a26d | 571 | |
el15mh | 0:b32f6570a26d | 572 | double brightness = pad.read_pot(); // returns value between 0.0 - 1.0 |
el15mh | 0:b32f6570a26d | 573 | |
el15mh | 0:b32f6570a26d | 574 | lcd.setBrightness(brightness); |
el15mh | 0:b32f6570a26d | 575 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 576 | |
el15mh | 0:b32f6570a26d | 577 | int width = brightness * 40; |
el15mh | 0:b32f6570a26d | 578 | |
el15mh | 0:b32f6570a26d | 579 | lcd.drawRect(10, 30, 41, 8, FILL_TRANSPARENT); |
el15mh | 0:b32f6570a26d | 580 | lcd.drawRect(11, 31, width, 6, FILL_BLACK); |
el15mh | 0:b32f6570a26d | 581 | lcd.refresh(); |
el15mh | 0:b32f6570a26d | 582 | |
el15mh | 0:b32f6570a26d | 583 | wait_ms(10); |
el15mh | 0:b32f6570a26d | 584 | |
el15mh | 0:b32f6570a26d | 585 | if (pad.check_event(Gamepad::BACK_PRESSED)){ |
el15mh | 0:b32f6570a26d | 586 | |
el15mh | 0:b32f6570a26d | 587 | exit = 1; |
el15mh | 0:b32f6570a26d | 588 | } |
el15mh | 0:b32f6570a26d | 589 | |
el15mh | 0:b32f6570a26d | 590 | } |
el15mh | 0:b32f6570a26d | 591 | } |
el15mh | 0:b32f6570a26d | 592 |