Mortal Kombat Game ELEC2645
Dependencies: mbed N5110 ShiftReg Joystick
Menu.cpp@20:4ca04fd0965a, 2021-05-07 (annotated)
- Committer:
- ozy
- Date:
- Fri May 07 16:58:36 2021 +0000
- Revision:
- 20:4ca04fd0965a
- Parent:
- 3:1d99b6ad4f9e
- Child:
- 21:fad1c9f010d1
Before changing to seamless version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ozy | 0:99b49fd71085 | 1 | #include "Menu.h" |
ozy | 0:99b49fd71085 | 2 | #include "mbed.h" |
ozy | 0:99b49fd71085 | 3 | |
ozy | 0:99b49fd71085 | 4 | // This class is responsible for presenting the GUI of the game |
ozy | 0:99b49fd71085 | 5 | Menu::Menu() {} |
ozy | 0:99b49fd71085 | 6 | |
ozy | 20:4ca04fd0965a | 7 | void Menu::menu_render(N5110 &lcd) { |
ozy | 20:4ca04fd0965a | 8 | main_menu(lcd); |
ozy | 20:4ca04fd0965a | 9 | wait(3.0f); |
ozy | 20:4ca04fd0965a | 10 | created_by(lcd); |
ozy | 20:4ca04fd0965a | 11 | wait(3.0f); |
ozy | 20:4ca04fd0965a | 12 | homescreen(lcd); |
ozy | 20:4ca04fd0965a | 13 | wait(3.0f); |
ozy | 20:4ca04fd0965a | 14 | lcd.refresh(); |
ozy | 20:4ca04fd0965a | 15 | } |
ozy | 20:4ca04fd0965a | 16 | |
ozy | 20:4ca04fd0965a | 17 | void Menu::homescreen_select(int user_input, N5110 &lcd, DigitalIn &buttonA, DigitalIn &buttonB, DigitalIn &buttonC, DigitalIn &buttonD) { |
ozy | 20:4ca04fd0965a | 18 | user_input = get_user_input(buttonA, buttonB, buttonC, buttonD); |
ozy | 20:4ca04fd0965a | 19 | switch(user_input) { |
ozy | 20:4ca04fd0965a | 20 | case 1: |
ozy | 20:4ca04fd0965a | 21 | play(lcd); |
ozy | 20:4ca04fd0965a | 22 | user_input = 0; |
ozy | 20:4ca04fd0965a | 23 | break; |
ozy | 20:4ca04fd0965a | 24 | case 2: |
ozy | 20:4ca04fd0965a | 25 | tutorial(lcd); |
ozy | 20:4ca04fd0965a | 26 | user_input = 0; |
ozy | 20:4ca04fd0965a | 27 | break; |
ozy | 20:4ca04fd0965a | 28 | case 3: |
ozy | 20:4ca04fd0965a | 29 | options_menu(lcd, buttonA, buttonB, buttonC, buttonD); |
ozy | 20:4ca04fd0965a | 30 | user_input = 0; |
ozy | 20:4ca04fd0965a | 31 | break; |
ozy | 20:4ca04fd0965a | 32 | default: |
ozy | 20:4ca04fd0965a | 33 | homescreen(lcd); |
ozy | 20:4ca04fd0965a | 34 | user_input = 0; |
ozy | 20:4ca04fd0965a | 35 | break; |
ozy | 20:4ca04fd0965a | 36 | } |
ozy | 20:4ca04fd0965a | 37 | } |
ozy | 20:4ca04fd0965a | 38 | |
ozy | 0:99b49fd71085 | 39 | void Menu::draw_logo(N5110 &lcd, int x, int y) { |
ozy | 0:99b49fd71085 | 40 | // Mortal Kombat Logo |
ozy | 0:99b49fd71085 | 41 | const int logo[17][19] = { |
ozy | 0:99b49fd71085 | 42 | { 1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1 }, |
ozy | 0:99b49fd71085 | 43 | { 0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0 }, |
ozy | 0:99b49fd71085 | 44 | { 0,0,0,0,0,1,0,1,1,1,0,0,0,0,1,0,0,0,0 }, |
ozy | 0:99b49fd71085 | 45 | { 0,0,0,0,1,0,1,1,1,1,1,0,0,0,0,1,0,0,0 }, |
ozy | 0:99b49fd71085 | 46 | { 0,0,0,1,0,1,1,0,0,1,1,1,1,0,0,0,1,0,0 }, |
ozy | 0:99b49fd71085 | 47 | { 0,0,1,0,1,1,1,0,1,1,1,1,1,1,0,0,0,1,0 }, |
ozy | 0:99b49fd71085 | 48 | { 0,0,1,0,1,1,1,1,1,1,1,1,0,1,0,0,0,1,0 }, |
ozy | 0:99b49fd71085 | 49 | { 0,0,1,0,1,1,1,0,0,0,1,1,1,1,1,0,0,1,0 }, |
ozy | 0:99b49fd71085 | 50 | { 0,0,1,0,1,1,1,1,0,0,0,0,0,1,1,1,0,1,0 }, |
ozy | 0:99b49fd71085 | 51 | { 0,0,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,1,0 }, |
ozy | 0:99b49fd71085 | 52 | { 0,0,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1,0 }, |
ozy | 0:99b49fd71085 | 53 | { 0,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,0 }, |
ozy | 0:99b49fd71085 | 54 | { 0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0 }, |
ozy | 0:99b49fd71085 | 55 | { 0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,1,0,0,0 }, |
ozy | 0:99b49fd71085 | 56 | { 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0 }, |
ozy | 0:99b49fd71085 | 57 | { 0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0 }, |
ozy | 0:99b49fd71085 | 58 | { 1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1 }, |
ozy | 0:99b49fd71085 | 59 | }; |
ozy | 0:99b49fd71085 | 60 | // draw the MK Logo |
ozy | 0:99b49fd71085 | 61 | // (x, y, rows, cols, sprite) |
ozy | 0:99b49fd71085 | 62 | lcd.drawSprite(x,y,17,19,(int *)logo); |
ozy | 0:99b49fd71085 | 63 | } |
ozy | 0:99b49fd71085 | 64 | |
ozy | 0:99b49fd71085 | 65 | void Menu::main_menu(N5110 &lcd) { |
ozy | 0:99b49fd71085 | 66 | // Printing the first menu screen |
ozy | 0:99b49fd71085 | 67 | lcd.printString("MORTAL KOMBAT",3,1); |
ozy | 0:99b49fd71085 | 68 | lcd.printString("LEEDS EDITION",3,2); |
ozy | 0:99b49fd71085 | 69 | lcd.refresh(); |
ozy | 0:99b49fd71085 | 70 | draw_logo(lcd, 30, 28); // draw logo on (30,28) |
ozy | 0:99b49fd71085 | 71 | // draw menu frame using the whole dimensions of the screen |
ozy | 0:99b49fd71085 | 72 | lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); |
ozy | 0:99b49fd71085 | 73 | lcd.refresh(); // refresh the LCD so the pixels appear |
ozy | 0:99b49fd71085 | 74 | } |
ozy | 0:99b49fd71085 | 75 | |
ozy | 0:99b49fd71085 | 76 | void Menu::created_by(N5110 &lcd) { |
ozy | 0:99b49fd71085 | 77 | lcd.clear(); |
ozy | 0:99b49fd71085 | 78 | lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); |
ozy | 0:99b49fd71085 | 79 | lcd.printString("Created by:",2,1); |
ozy | 0:99b49fd71085 | 80 | lcd.printString("OSMAN",25,2); |
ozy | 0:99b49fd71085 | 81 | lcd.printString("FADL ALI",20,3); |
ozy | 0:99b49fd71085 | 82 | lcd.printString("201337691",18,4); |
ozy | 0:99b49fd71085 | 83 | lcd.refresh(); |
ozy | 0:99b49fd71085 | 84 | } |
ozy | 0:99b49fd71085 | 85 | void Menu::A_to_start(N5110 &lcd) { |
ozy | 0:99b49fd71085 | 86 | lcd.clear(); |
ozy | 0:99b49fd71085 | 87 | lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); |
ozy | 0:99b49fd71085 | 88 | lcd.printString(" Press A ",15,2); |
ozy | 0:99b49fd71085 | 89 | lcd.printString(" to ",20,3); |
ozy | 0:99b49fd71085 | 90 | lcd.printString(" Start! ",15,4); |
ozy | 0:99b49fd71085 | 91 | lcd.refresh(); |
ozy | 0:99b49fd71085 | 92 | } |
ozy | 0:99b49fd71085 | 93 | |
ozy | 0:99b49fd71085 | 94 | void Menu::homescreen(N5110 &lcd) { |
ozy | 0:99b49fd71085 | 95 | lcd.clear(); |
ozy | 0:99b49fd71085 | 96 | lcd.printString(" Press Button ", 0, 0); |
ozy | 0:99b49fd71085 | 97 | lcd.printString(" to Select: ", 0, 1); |
ozy | 0:99b49fd71085 | 98 | lcd.printString(" A - Play", 0, 3); |
ozy | 0:99b49fd71085 | 99 | lcd.printString(" B - Tutorial", 0, 4); |
ozy | 0:99b49fd71085 | 100 | lcd.printString(" C - Options", 0, 5); |
ozy | 0:99b49fd71085 | 101 | lcd.refresh(); |
ozy | 0:99b49fd71085 | 102 | } |
ozy | 0:99b49fd71085 | 103 | |
ozy | 0:99b49fd71085 | 104 | void Menu::play(N5110 &lcd) { |
ozy | 1:3bdadf6f6dbd | 105 | lcd.clear(); |
ozy | 0:99b49fd71085 | 106 | lcd.printString("Play", 0, 0); |
ozy | 1:3bdadf6f6dbd | 107 | lcd.refresh(); |
ozy | 0:99b49fd71085 | 108 | } |
ozy | 0:99b49fd71085 | 109 | |
ozy | 0:99b49fd71085 | 110 | void Menu::tutorial(N5110 &lcd) { |
ozy | 1:3bdadf6f6dbd | 111 | lcd.clear(); |
ozy | 1:3bdadf6f6dbd | 112 | lcd.printString("Tutorial", 0, 0); // mention that to select in-game options, you can click the joystick? |
ozy | 1:3bdadf6f6dbd | 113 | lcd.refresh(); |
ozy | 1:3bdadf6f6dbd | 114 | } |
ozy | 1:3bdadf6f6dbd | 115 | |
ozy | 20:4ca04fd0965a | 116 | void Menu::options_menu(N5110 &lcd, DigitalIn &buttonA, DigitalIn &buttonB, DigitalIn &buttonC, DigitalIn &buttonD) { |
ozy | 1:3bdadf6f6dbd | 117 | lcd.clear(); |
ozy | 1:3bdadf6f6dbd | 118 | lcd.printString("Select Option: ", 0, 0); |
ozy | 1:3bdadf6f6dbd | 119 | lcd.printString("A-Sound ON/OFF", 0, 2); |
ozy | 1:3bdadf6f6dbd | 120 | lcd.printString("B-Brightness", 0, 3); |
ozy | 1:3bdadf6f6dbd | 121 | lcd.printString("C-Go back", 0, 4); |
ozy | 1:3bdadf6f6dbd | 122 | |
ozy | 1:3bdadf6f6dbd | 123 | lcd.refresh(); |
ozy | 0:99b49fd71085 | 124 | } |
ozy | 0:99b49fd71085 | 125 | |
ozy | 20:4ca04fd0965a | 126 | int Menu::get_user_input(DigitalIn &buttonA, DigitalIn &buttonB, DigitalIn &buttonC, DigitalIn &buttonD) { |
ozy | 20:4ca04fd0965a | 127 | if (buttonA.read() == 1) { |
ozy | 20:4ca04fd0965a | 128 | user_input = 1; // A = 1 |
ozy | 20:4ca04fd0965a | 129 | printf("User input = %i\n", user_input); |
ozy | 20:4ca04fd0965a | 130 | } |
ozy | 20:4ca04fd0965a | 131 | else if (buttonB.read() == 1) { |
ozy | 20:4ca04fd0965a | 132 | user_input = 2; // B = 2 |
ozy | 20:4ca04fd0965a | 133 | printf("User input = %i\n", user_input); |
ozy | 1:3bdadf6f6dbd | 134 | } |
ozy | 20:4ca04fd0965a | 135 | else if (buttonC.read() == 1) { |
ozy | 20:4ca04fd0965a | 136 | user_input = 3; // C = 3 |
ozy | 20:4ca04fd0965a | 137 | printf("User input = %i\n", user_input); |
ozy | 20:4ca04fd0965a | 138 | } |
ozy | 20:4ca04fd0965a | 139 | else if (buttonD.read() == 1) { |
ozy | 20:4ca04fd0965a | 140 | user_input = 4; // D = 4 |
ozy | 20:4ca04fd0965a | 141 | printf("User input = %i\n", user_input); |
ozy | 20:4ca04fd0965a | 142 | } |
ozy | 20:4ca04fd0965a | 143 | else { |
ozy | 20:4ca04fd0965a | 144 | user_input = 0; |
ozy | 20:4ca04fd0965a | 145 | printf("User input = %i\n", user_input); |
ozy | 20:4ca04fd0965a | 146 | } |
ozy | 20:4ca04fd0965a | 147 | return user_input; |
ozy | 0:99b49fd71085 | 148 | } |
ozy | 1:3bdadf6f6dbd | 149 | |
ozy | 1:3bdadf6f6dbd | 150 | |
ozy | 1:3bdadf6f6dbd | 151 | |
ozy | 20:4ca04fd0965a | 152 |