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