Mortal Kombat Game ELEC2645
Dependencies: mbed N5110 ShiftReg Joystick
Menu.cpp
- Committer:
- ozy
- Date:
- 2021-04-19
- Revision:
- 3:1d99b6ad4f9e
- Parent:
- 2:1703eb2a68f8
- Child:
- 20:4ca04fd0965a
File content as of revision 3:1d99b6ad4f9e:
#include "Menu.h" #include "mbed.h" // This class is responsible for presenting the GUI of the game Menu::Menu() {} void Menu::draw_logo(N5110 &lcd, int x, int y) { // Mortal Kombat Logo const int logo[17][19] = { { 1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1 }, { 0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0 }, { 0,0,0,0,0,1,0,1,1,1,0,0,0,0,1,0,0,0,0 }, { 0,0,0,0,1,0,1,1,1,1,1,0,0,0,0,1,0,0,0 }, { 0,0,0,1,0,1,1,0,0,1,1,1,1,0,0,0,1,0,0 }, { 0,0,1,0,1,1,1,0,1,1,1,1,1,1,0,0,0,1,0 }, { 0,0,1,0,1,1,1,1,1,1,1,1,0,1,0,0,0,1,0 }, { 0,0,1,0,1,1,1,0,0,0,1,1,1,1,1,0,0,1,0 }, { 0,0,1,0,1,1,1,1,0,0,0,0,0,1,1,1,0,1,0 }, { 0,0,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,1,0 }, { 0,0,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1,0 }, { 0,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,0 }, { 0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0 }, { 0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,1,0,0,0 }, { 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0 }, { 0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0 }, { 1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1 }, }; // draw the MK Logo // (x, y, rows, cols, sprite) lcd.drawSprite(x,y,17,19,(int *)logo); } void Menu::main_menu(N5110 &lcd) { // Printing the first menu screen lcd.printString("MORTAL KOMBAT",3,1); lcd.printString("LEEDS EDITION",3,2); lcd.refresh(); draw_logo(lcd, 30, 28); // draw logo on (30,28) // draw menu frame using the whole dimensions of the screen lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); lcd.refresh(); // refresh the LCD so the pixels appear } void Menu::created_by(N5110 &lcd) { lcd.clear(); lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); lcd.printString("Created by:",2,1); lcd.printString("OSMAN",25,2); lcd.printString("FADL ALI",20,3); lcd.printString("201337691",18,4); lcd.refresh(); } void Menu::A_to_start(N5110 &lcd) { lcd.clear(); lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); lcd.printString(" Press A ",15,2); lcd.printString(" to ",20,3); lcd.printString(" Start! ",15,4); lcd.refresh(); } void Menu::homescreen(N5110 &lcd) { lcd.clear(); lcd.printString(" Press Button ", 0, 0); lcd.printString(" to Select: ", 0, 1); lcd.printString(" A - Play", 0, 3); lcd.printString(" B - Tutorial", 0, 4); lcd.printString(" C - Options", 0, 5); lcd.refresh(); } void Menu::play(N5110 &lcd) { lcd.clear(); lcd.printString("Play", 0, 0); lcd.refresh(); } void Menu::tutorial(N5110 &lcd) { 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::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; } } } // ****************************************************************************************************************************** /* // 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; } */