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.
Diff: Menu.cpp
- Revision:
- 0:b32f6570a26d
- Child:
- 1:21b7a5edb9c2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Menu.cpp Sun Apr 02 13:13:29 2017 +0000 @@ -0,0 +1,592 @@ +/* + +@file Menu.cpp + +(c) Max Houghton 02.14.17 +Roller Maze Project, ELEC2645, Univeristy of Leeds + +*/ + +#include "Menu.h" + +// constructor function used when object is initialised +Menu::Menu() +{ + +} + +// destructor function +Menu::~Menu() +{ + +} + +void Menu::main() +{ + int selected = 0; + + while(1) { + + // lcd.printString("Testing", 0, 2); + switch (selected) { + + case 1: + + lcd.clear(); + lcd.printString(">Play game", 0, 0); + lcd.printString(" Game options", 0, 1); + lcd.printString(" LCD settings", 0, 2); + lcd.printString(" Sound", 0, 3); + + lcd.refresh(); + + // either clicking joystick or pressing A selects function + if (pad.check_event(Gamepad::A_PRESSED) || + pad.check_event(Gamepad::JOY_PRESSED)){ + + play(); // call the game function + } + + wait_ms(250); // 1s propogation delay + + break; + + case 2: + + lcd.clear(); + lcd.printString(" Play game", 0, 0); + lcd.printString(">Game options", 0, 1); + lcd.printString(" LCD settings", 0, 2); + lcd.printString(" Sound", 0, 3); + + lcd.refresh(); + + + if (pad.check_event(Gamepad::A_PRESSED) || + pad.check_event(Gamepad::JOY_PRESSED)){ + + options(); + } + + wait_ms(250); // 1s propogation delay + + break; + + case 3: + + lcd.clear(); + lcd.printString(" Play game", 0, 0); + lcd.printString(" Game options", 0, 1); + lcd.printString(">LCD settings", 0, 2); + lcd.printString(" Sound", 0, 3); + + lcd.refresh(); + + + if (pad.check_event(Gamepad::A_PRESSED) || + pad.check_event(Gamepad::JOY_PRESSED)){ + + lcdSettings(); + } + + wait_ms(250); // 1s propogation delay + + break; + + case 4: + + lcd.clear(); + lcd.printString(" Play game", 0, 0); + lcd.printString(" Game options", 0, 1); + lcd.printString(" LCD settings", 0, 2); + lcd.printString(">Sound", 0, 3); + + lcd.refresh(); + + + if (pad.check_event(Gamepad::A_PRESSED) || + pad.check_event(Gamepad::JOY_PRESSED)){ + + soundSettings(); + } + + wait_ms(250); // 1s propogation delay + + break; + + default: + + selected = 1; + + break; + } + + char d = pad.get_direction(); + + if ((d == NW) || + (d == N) || + (d == NE)){ + + selected -= 1; + } + + if ((d == SW) || + (d == S) || + (d == SE)){ + + selected += 1; + } + + // printf("Joystick position = %c \n", d); + // printf("Selected = %i \n", selected); + + } +} + +void Menu::options() +{ + int exit = 0; + int selected = 0; + + while(exit == 0) { + + // printf("While loop 1 \n"); + // printf("Selected = %i \n", selected); + switch (selected) { + + case 1: + + lcd.clear(); + // displays options page with indicator on first + lcd.printString("Game Options:", 0, 0); + lcd.printString(">Difficulty", 0, 2); + lcd.printString(" Ball Colour", 0, 3); + lcd.refresh(); + + if (pad.check_event(Gamepad::A_PRESSED) || + pad.check_event(Gamepad::JOY_PRESSED)){ + + difficultyOptions(); + } + + wait_ms(250); + + break; + + case 2: + + lcd.clear(); + // displays options page with indicator on second + lcd.printString("Game Options:", 0, 0); + lcd.printString(" Difficulty", 0, 2); + lcd.printString(">Ball Colour", 0, 3); + lcd.refresh(); + + // if second option selected + if (pad.check_event(Gamepad::A_PRESSED) || + pad.check_event(Gamepad::JOY_PRESSED)){ + + colourOptions(); + } + + wait_ms(250); + + break; + + default: + + selected = 1; + + break; + } + + char d = pad.get_direction(); + + if ((d == NW) || + (d == N) || + (d == NE)){ + + selected -= 1; + } + + if ((d == SW) || + (d == S) || + (d == SE)){ + + selected += 1; + } + + if (pad.check_event(Gamepad::Y_PRESSED)){ + + selected -= 1; + } + + if (pad.check_event(Gamepad::X_PRESSED)){ + + selected += 1; + } + + if (pad.check_event(Gamepad::BACK_PRESSED)){ + + exit = 1; + } + } +} + +void lcdSettings() +{ + int exit = 0; + int selected = 0; + + while(exit == 0) { + + // printf("While loop 1 \n"); + // printf("Selected = %i \n", selected); + switch (selected) { + + case 1: + + lcd.clear(); + // displays options page with indicator on first + lcd.printString("LCD Settings:", 0, 0); + lcd.printString(">Brightness", 0, 2); + lcd.printString(" Invert Colour", 0, 3); + lcd.refresh(); + + if (pad.check_event(Gamepad::A_PRESSED) || + pad.check_event(Gamepad::JOY_PRESSED)){ + + lcdBackgroundColour(); + } + + wait_ms(250); + + break; + + case 2: + + lcd.clear(); + // displays options page with indicator on second + lcd.printString("LCD Settings:", 0, 0); + lcd.printString(" Brightness", 0, 2); + lcd.printString(">Invert Colour", 0, 3); + lcd.refresh(); + + + // if second option selected + if (pad.check_event(Gamepad::A_PRESSED) || + pad.check_event(Gamepad::JOY_PRESSED)){ + + lcdInverseColour(); + } + + wait_ms(250); + + break; + + default: + + selected = 1; + + break; + } + + char d = pad.get_direction(); + + if ((d == NW) || + (d == N) || + (d == NE)){ + + selected -= 1; + } + + if ((d == SW) || + (d == S) || + (d == SE)){ + + selected += 1; + } + + if (pad.check_event(Gamepad::Y_PRESSED)){ + + selected -= 1; + } + + if (pad.check_event(Gamepad::X_PRESSED)){ + + selected += 1; + } + + if (pad.check_event(Gamepad::BACK_PRESSED)){ + + exit = 1; + } + + } + + +} + +void soundSettings() +{ + + int exit = 0; + // pad.tone(750.0,0.1); + + while (exit == 0){ + + lcd.clear(); + lcd.printString("Sound settings", 0, 2); + lcd.refresh(); + + if(pad.check_event(Gamepad::BACK_PRESSED)){ + + exit = 1; + } + } + +} + +void difficultyOptions() +{ + int selected = 0; + int exit = 0; + + while(exit == 0){ + + switch(selected){ + + case 1: + + lcd.clear(); + lcd.printString("Difficulty: ", 0, 0); + lcd.printString(">Easy", 0, 2); + lcd.printString(" Hard", 0, 3); + lcd.refresh(); + + if (pad.check_event(Gamepad::A_PRESSED) || + pad.check_event(Gamepad::JOY_PRESSED)){ + + // maze.mazeIndex = 0; + lcd.clear(); + lcd.printString("Easy mode", 0, 1); + lcd.refresh(); + wait(2); + + exit = 1; + } + + break; + + case 2: + + lcd.clear(); + lcd.printString("Difficulty: ", 0, 0); + lcd.printString(" Easy", 0, 2); + lcd.printString(">Hard", 0, 3); + lcd.refresh(); + + if (pad.check_event(Gamepad::A_PRESSED) || + pad.check_event(Gamepad::JOY_PRESSED)){ + + // maze.mazeIndex = 1; + lcd.clear(); + lcd.printString("Hard mode", 0, 1); + lcd.refresh(); + wait(2); + + exit = 1; + } + + break; + + default: + + selected = 1; + + break; + + } + char d = pad.get_direction(); + + if ((d == NW) || + (d == N) || + (d == NE)){ + + selected -= 1; + } + + if ((d == SW) || + (d == S) || + (d == SE)){ + + selected += 1; + } + + + if (pad.check_event(Gamepad::BACK_PRESSED)){ + + exit = 1; + } + + } + + +} + +void lcdColourOptions() +{ + int selected = 0; + int exit = 0; + while(exit == 0){ + + switch(selected){ + + case 1: + + // printf("case 2.1"); + + lcd.clear(); + lcd.printString("Ball colour: ", 0, 0); + lcd.printString(">Transparent", 0, 2); + lcd.printString(" Solid", 0, 3); + lcd.refresh(); + + if (pad.check_event(Gamepad::A_PRESSED) || + pad.check_event(Gamepad::JOY_PRESSED)){ + + // ball.ballColour = 0; + lcd.clear(); + lcd.printString("Transparent", 0, 1); + lcd.refresh(); + wait(2); + + exit = 1; + } + + break; + + case 2: + + // printf("case 2.2"); + + lcd.clear(); + lcd.printString("Ball colour: ", 0, 0); + lcd.printString(" Transparent", 0, 2); + lcd.printString(">Solid", 0, 3); + lcd.refresh(); + + if (pad.check_event(Gamepad::A_PRESSED) || + pad.check_event(Gamepad::JOY_PRESSED)){ + + // ball.ballColour = 1; + lcd.clear(); + lcd.printString("Solid", 0, 1); + lcd.refresh(); + wait(2); + + exit = 1; + } + + break; + + default: + + selected = 1; + + break; + } + + char d = pad.get_direction(); + + if ((d == NW) || + (d == N) || + (d == NE)){ + + selected -= 1; + } + + if ((d == SW) || + (d == S) || + (d == SE)){ + + selected += 1; + } + + if (pad.check_event(Gamepad::BACK_PRESSED)){ + + exit = 1; + } + } + + +} + +void lcdInverseColour() +{ + int exit = 0; + + while (exit == 0) { + + lcd.clear(); + lcd.printString("Press A to", 0, 0); + lcd.printString("invert colours", 0, 1); + lcd.printString("Press B to", 0, 3); + lcd.printString("revert to", 0, 4); + lcd.printString("normal", 0, 5); + + if (pad.check_event(Gamepad::A_PRESSED)){ + + lcd.inverseMode(); + + } + + if (pad.check_event(Gamepad::B_PRESSED)){ + + lcd.normalMode(); + + } + + lcd.refresh(); + + if (pad.check_event(Gamepad::BACK_PRESSED)){ + + exit = 1; + } + } + + +} + +void lcdBackgroundColour() +{ + int exit = 0; + + while (exit == 0) { + + lcd.clear(); + lcd.printString("BRIGHTNESS", 0, 0); + lcd.printString("Use DIAL --->", 0, 1); + lcd.printString("to adjust", 0, 2); + + double brightness = pad.read_pot(); // returns value between 0.0 - 1.0 + + lcd.setBrightness(brightness); + lcd.refresh(); + + int width = brightness * 40; + + lcd.drawRect(10, 30, 41, 8, FILL_TRANSPARENT); + lcd.drawRect(11, 31, width, 6, FILL_BLACK); + lcd.refresh(); + + wait_ms(10); + + if (pad.check_event(Gamepad::BACK_PRESSED)){ + + exit = 1; + } + + } +} +