![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Mortal Kombat Game ELEC2645
Dependencies: mbed N5110 ShiftReg Joystick
Diff: Menu.cpp
- Revision:
- 1:3bdadf6f6dbd
- Parent:
- 0:99b49fd71085
- Child:
- 2:1703eb2a68f8
diff -r 99b49fd71085 -r 3bdadf6f6dbd Menu.cpp --- a/Menu.cpp Tue Apr 13 10:06:02 2021 +0000 +++ b/Menu.cpp Sat Apr 17 11:38:39 2021 +0000 @@ -62,8 +62,6 @@ void Menu::homescreen(N5110 &lcd) { lcd.clear(); - // lcd.drawLine(0,46,0,0,1); - // lcd.drawLine(84,0,84,46,1); lcd.printString(" Press Button ", 0, 0); lcd.printString(" to Select: ", 0, 1); lcd.printString(" A - Play", 0, 3); @@ -73,31 +71,117 @@ } void Menu::play(N5110 &lcd) { + lcd.clear(); lcd.printString("Play", 0, 0); + lcd.refresh(); } void Menu::tutorial(N5110 &lcd) { - lcd.printString("Tutorial", 0, 0); + lcd.clear(); + lcd.printString("Tutorial", 0, 0); // mention that to select in-game options, you can click the joystick? + lcd.refresh(); +} + +void Menu::options_menu(N5110 &lcd, DigitalIn &buttonA, DigitalIn &buttonB, DigitalIn &buttonC) { + lcd.clear(); + lcd.printString("Select Option: ", 0, 0); + lcd.printString("A-Sound ON/OFF", 0, 2); + lcd.printString("B-Brightness", 0, 3); + lcd.printString("C-Go back", 0, 4); + /* + while (1) { + if (buttonA.read() == 1) { + lcd.printString(" Sound turned ON!", 0, 3); // Note: add code for sound ON/OFF after making sound library! + break; + } + if (buttonB.read() == 1) { + lcd.printString("Set Brightness to: ", 0, 0); + lcd.printString(" A - High", 0, 3); + lcd.printString(" B - Medium", 0, 4); + lcd.printString(" C - Low", 0, 5); + if (buttonA.read() == 1) {lcd.setBrightness(0.2);} + if (buttonB.read() == 1) {lcd.setBrightness(0.5);} + if (buttonC.read() == 1) {lcd.setBrightness(0.8);} + break; + } + if (buttonC.read() == 1) { + homescreen(lcd); + break; + } + */ + + lcd.refresh(); } -void Menu::options_menu(N5110 &lcd) { - lcd.printString("Options", 0, 0); +void Menu::menu_selection(N5110 &lcd, DigitalIn &buttonA, DigitalIn &buttonB, DigitalIn &buttonC, DigitalIn &buttonD) { + // this function takes the user input and selects the relevant menu item + + while (1) { + /* + int user_input = get_user_input(int input, buttonA, buttonB, buttonC, buttonD); + if (user_input == 1) { + play(lcd); + break; + } + if (user_input == 2) { + tutorial(lcd); + break; + } + if (user_input == 3) { + options_menu(lcd, buttonA, buttonB, buttonC); + break; + } + if (user_input == 4) { + homescreen(lcd); + break; // Note for possible mistakes: address-of operator or int input in this function + } + */ + // working code + if (buttonA.read() == 1) { // we use if statement instead of while loop so that button input do not interfere with the next menu, only this one! + play(lcd); + break; + } + if (buttonB.read() == 1) { + tutorial(lcd); + break; + } + if (buttonC.read() == 1) { + options_menu(lcd, buttonA, buttonB, buttonC); + break; + } + if (buttonD.read() == 1) { // user can click button D to return to main menu + homescreen(lcd); + continue; + } + } } + +// ****************************************************************************************************************************** /* -void Menu::select_item(char button) { // using case switching for each screen - switch (button) { - case 'A': - play(lcd); - break; - case 'B': - tutorial(lcd); - break; - case 'C': - options_menu(lcd); - break; - default: - homescreen(lcd); - break; - } +// function - gets user input from buttons A B C D +int Menu::get_user_input(int &input, DigitalIn &buttonA, DigitalIn &buttonB, DigitalIn &buttonC, DigitalIn &buttonD) { + // we use address-of operator for int input to pass the actual reference for the input value not just a copy of it + while (1) { + if (buttonA.read() == 1) { + input = 1; + break; + } + if (buttonB.read() == 1) { + input = 2; + break; + } + if (buttonC.read() == 1) { + input = 3; + break; + } + if (buttonD.read() == 1) { + input = 4; + break; + } + } + printf("input is %i", input); + return input; } */ + +