contains my game for the embedded systems project 2645

Dependencies:   mbed FXOS8700CQQQ

Committer:
OmarAlebiary
Date:
Tue May 07 15:17:21 2019 +0000
Revision:
40:13b8467526d0
Parent:
33:24ef796ff2c8
Final Submission. I have read and agreed with Statement of Academic Integrity

Who changed what in which revision?

UserRevisionLine numberNew contents of line
OmarAlebiary 28:39607fb67e88 1 #include "Menus.h"
OmarAlebiary 28:39607fb67e88 2
OmarAlebiary 28:39607fb67e88 3
OmarAlebiary 33:24ef796ff2c8 4 //default constructor of the class
OmarAlebiary 28:39607fb67e88 5 Menus::Menus(){
OmarAlebiary 28:39607fb67e88 6 }
OmarAlebiary 33:24ef796ff2c8 7
OmarAlebiary 33:24ef796ff2c8 8 //destructor of the class
OmarAlebiary 29:e660274d8222 9 Menus::~Menus(){
OmarAlebiary 29:e660274d8222 10 }
OmarAlebiary 33:24ef796ff2c8 11
OmarAlebiary 33:24ef796ff2c8 12 //dispalys the welcome menu
OmarAlebiary 28:39607fb67e88 13 void Menus::welcomeMenu(Gamepad &pad,N5110 &lcd) {
OmarAlebiary 28:39607fb67e88 14
OmarAlebiary 28:39607fb67e88 15 lcd.printString(" Rocket Racer ",0,0);
OmarAlebiary 28:39607fb67e88 16
OmarAlebiary 33:24ef796ff2c8 17 lcd.drawSprite(25,8,11,9,(int *)enemyMainMenu);//prints sprites on the welcome menu
OmarAlebiary 28:39607fb67e88 18 lcd.drawSprite(45,15,11,9,(int *)enemyMainMenu);
OmarAlebiary 28:39607fb67e88 19 lcd.drawSprite(35,31,11,9,(int *)rocketMainMenu);
OmarAlebiary 33:24ef796ff2c8 20 lcd.drawLine(20, 10, 20,45,1);//draws lines
OmarAlebiary 28:39607fb67e88 21 lcd.drawLine(22, 10, 22,45,2);
OmarAlebiary 28:39607fb67e88 22 lcd.drawLine(57, 10, 57,45,1);
OmarAlebiary 28:39607fb67e88 23 lcd.drawLine(55, 10, 55,45,2);
OmarAlebiary 28:39607fb67e88 24
OmarAlebiary 28:39607fb67e88 25 pad.leds_on();//turns all leds on
OmarAlebiary 28:39607fb67e88 26 lcd.refresh();
OmarAlebiary 33:24ef796ff2c8 27 tone.Play_Welcome_Melody(pad);//plays a melody
OmarAlebiary 28:39607fb67e88 28 wait(1);
OmarAlebiary 28:39607fb67e88 29
OmarAlebiary 28:39607fb67e88 30 }
OmarAlebiary 28:39607fb67e88 31
OmarAlebiary 33:24ef796ff2c8 32 //dispalys the main menu
OmarAlebiary 28:39607fb67e88 33 void Menus::drawMenu(N5110 &lcd,Gamepad &pad) {
OmarAlebiary 28:39607fb67e88 34
OmarAlebiary 28:39607fb67e88 35 lcd.clear();
OmarAlebiary 28:39607fb67e88 36 lcd.printString("MAIN MENU", 15, 0);
OmarAlebiary 28:39607fb67e88 37 lcd.drawLine(1, 10,80 ,10,1);
OmarAlebiary 28:39607fb67e88 38 lcd.printString("Play -A", 2, 2);
OmarAlebiary 30:c5060010a1e6 39 lcd.printString("Play /acc -Y", 2, 3);
OmarAlebiary 30:c5060010a1e6 40 lcd.printString("Instructions-B", 1, 4);
OmarAlebiary 30:c5060010a1e6 41 lcd.printString("Credits - X", 1, 5);
OmarAlebiary 28:39607fb67e88 42 pad.leds_off();
OmarAlebiary 28:39607fb67e88 43 wait(0.1);
OmarAlebiary 28:39607fb67e88 44 pad.leds_on();
OmarAlebiary 28:39607fb67e88 45 wait(0.1);
OmarAlebiary 28:39607fb67e88 46 lcd.refresh();
OmarAlebiary 33:24ef796ff2c8 47 //calls this method to check button press for each item in the menu
OmarAlebiary 28:39607fb67e88 48 check_button_pressed(pad,lcd);
OmarAlebiary 28:39607fb67e88 49
OmarAlebiary 28:39607fb67e88 50 }
OmarAlebiary 28:39607fb67e88 51
OmarAlebiary 33:24ef796ff2c8 52 //checks if a button pressed and calls the subsequent method
OmarAlebiary 30:c5060010a1e6 53 void Menus::check_button_pressed(Gamepad &pad,N5110 &lcd){
OmarAlebiary 33:24ef796ff2c8 54 if (pad.check_event(Gamepad::A_PRESSED) == true){//if A presed
OmarAlebiary 28:39607fb67e88 55 pad.leds_off();
OmarAlebiary 40:13b8467526d0 56 while(pad.check_event(Gamepad::BACK_PRESSED) == false){//loop since back not pressed
OmarAlebiary 40:13b8467526d0 57 Rocket_Race.Game_Loop(lcd,pad);//call the game loop
OmarAlebiary 28:39607fb67e88 58 }
OmarAlebiary 33:24ef796ff2c8 59 }else if (pad.check_event(Gamepad::B_PRESSED) == true){//if B presed
OmarAlebiary 33:24ef796ff2c8 60 InstructionsMenu(pad,lcd);//call the instructions menu
OmarAlebiary 33:24ef796ff2c8 61 if (pad.check_event(Gamepad::BACK_PRESSED) == true){//if BACK presed
OmarAlebiary 33:24ef796ff2c8 62 drawMenu(lcd,pad);//returns back to the main menu
OmarAlebiary 33:24ef796ff2c8 63 }
OmarAlebiary 33:24ef796ff2c8 64 }else if (pad.check_event(Gamepad::Y_PRESSED) == true){//if Y presed
OmarAlebiary 30:c5060010a1e6 65 pad.leds_off();
OmarAlebiary 40:13b8467526d0 66 while(pad.check_event(Gamepad::BACK_PRESSED) == false){//loop since back not pressed
OmarAlebiary 40:13b8467526d0 67 Rocket_Race.Game_Loop_accelerometer(lcd,pad);//call the game loop with accelerometer control
OmarAlebiary 33:24ef796ff2c8 68 }
OmarAlebiary 33:24ef796ff2c8 69 }else if (pad.check_event(Gamepad::X_PRESSED) == true){//if X presed
OmarAlebiary 33:24ef796ff2c8 70 credits(lcd,pad);//call the credits page
OmarAlebiary 28:39607fb67e88 71 if (pad.check_event(Gamepad::BACK_PRESSED) == true){
OmarAlebiary 33:24ef796ff2c8 72 drawMenu(lcd,pad);//returns back to the main menu
OmarAlebiary 33:24ef796ff2c8 73 }
OmarAlebiary 33:24ef796ff2c8 74 }
OmarAlebiary 33:24ef796ff2c8 75 }
OmarAlebiary 28:39607fb67e88 76
OmarAlebiary 33:24ef796ff2c8 77 //displays credits menu
OmarAlebiary 28:39607fb67e88 78 void Menus::credits(N5110 &lcd,Gamepad &pad) {
OmarAlebiary 28:39607fb67e88 79
OmarAlebiary 28:39607fb67e88 80 lcd.clear();
OmarAlebiary 33:24ef796ff2c8 81 //prints strings on the lcd
OmarAlebiary 28:39607fb67e88 82 lcd.printString("Game By:", 8, 1);
OmarAlebiary 28:39607fb67e88 83 lcd.printString("Omar Alebiary", 7, 2);
OmarAlebiary 28:39607fb67e88 84 lcd.printString("ID: 201172644", 7, 3);
OmarAlebiary 28:39607fb67e88 85
OmarAlebiary 28:39607fb67e88 86 lcd.printString("< press BACK ", 12, 5);
OmarAlebiary 28:39607fb67e88 87
OmarAlebiary 28:39607fb67e88 88 lcd.refresh();
OmarAlebiary 28:39607fb67e88 89 wait(0.5);
OmarAlebiary 28:39607fb67e88 90 while ( pad.check_event(Gamepad::BACK_PRESSED) == false){//keep looping since back not pressed
OmarAlebiary 28:39607fb67e88 91 pad.leds_on();//turn all leds on
OmarAlebiary 28:39607fb67e88 92 wait(0.1);
OmarAlebiary 28:39607fb67e88 93 pad.leds_off();//turn all leds off
OmarAlebiary 30:c5060010a1e6 94 wait(0.1);
OmarAlebiary 28:39607fb67e88 95 }
OmarAlebiary 28:39607fb67e88 96
OmarAlebiary 28:39607fb67e88 97 }
OmarAlebiary 28:39607fb67e88 98
OmarAlebiary 33:24ef796ff2c8 99 //displays loading page
OmarAlebiary 28:39607fb67e88 100 void Menus::loading_menu(N5110 &lcd) {
OmarAlebiary 28:39607fb67e88 101 lcd.clear();
OmarAlebiary 28:39607fb67e88 102 lcd.printString("loading...", 2, 1);
OmarAlebiary 28:39607fb67e88 103
OmarAlebiary 28:39607fb67e88 104 lcd.drawLine(7, 20,12 ,20,1);
OmarAlebiary 28:39607fb67e88 105 lcd.refresh();
OmarAlebiary 28:39607fb67e88 106 wait(0.6);
OmarAlebiary 28:39607fb67e88 107 lcd.drawLine(7, 20,24 ,20,1);
OmarAlebiary 28:39607fb67e88 108 lcd.refresh();
OmarAlebiary 28:39607fb67e88 109 wait(0.5);
OmarAlebiary 28:39607fb67e88 110 lcd.drawLine(7, 20,34 ,20,1);
OmarAlebiary 28:39607fb67e88 111 lcd.refresh();
OmarAlebiary 28:39607fb67e88 112 wait(0.6);
OmarAlebiary 28:39607fb67e88 113 lcd.drawLine(7, 20,44,20,1);
OmarAlebiary 28:39607fb67e88 114 lcd.refresh();
OmarAlebiary 28:39607fb67e88 115 wait(0.2);
OmarAlebiary 28:39607fb67e88 116 lcd.drawLine(7, 20,65 ,20,1);
OmarAlebiary 28:39607fb67e88 117 lcd.refresh();
OmarAlebiary 28:39607fb67e88 118 wait(0.2);
OmarAlebiary 28:39607fb67e88 119 }
OmarAlebiary 28:39607fb67e88 120
OmarAlebiary 33:24ef796ff2c8 121 //displays the second instructionsmenu
OmarAlebiary 31:4d4a9d78cae5 122 void Menus::SecondInstructionsMenu(N5110 &lcd){
OmarAlebiary 31:4d4a9d78cae5 123 lcd.clear();
OmarAlebiary 31:4d4a9d78cae5 124 lcd.printString("U can also use",0,0);
OmarAlebiary 31:4d4a9d78cae5 125 lcd.printString("accelormeter",0,1);
OmarAlebiary 31:4d4a9d78cae5 126 lcd.printString("to control ",0,2);
OmarAlebiary 31:4d4a9d78cae5 127 lcd.printString("the rocket ",0,3);
OmarAlebiary 40:13b8467526d0 128 lcd.printString("in play/acc",0,4);
OmarAlebiary 31:4d4a9d78cae5 129
OmarAlebiary 31:4d4a9d78cae5 130 lcd.printString("< press BACK ", 12, 5);
OmarAlebiary 31:4d4a9d78cae5 131 lcd.refresh();
OmarAlebiary 31:4d4a9d78cae5 132 }
OmarAlebiary 33:24ef796ff2c8 133
OmarAlebiary 31:4d4a9d78cae5 134
OmarAlebiary 28:39607fb67e88 135 void Menus::InstructionsMenu(Gamepad &pad,N5110 &lcd){
OmarAlebiary 28:39607fb67e88 136
OmarAlebiary 28:39607fb67e88 137 lcd.clear();
OmarAlebiary 28:39607fb67e88 138 lcd.printString("How to play:",0,0);
OmarAlebiary 28:39607fb67e88 139 lcd.printString("Use joystick",0,1);
OmarAlebiary 28:39607fb67e88 140 lcd.printString("or L & R",0,2);
OmarAlebiary 28:39607fb67e88 141 lcd.printString("to escape ",0,3);
OmarAlebiary 28:39607fb67e88 142 lcd.printString("enemies.",0,4);
OmarAlebiary 31:4d4a9d78cae5 143 lcd.refresh();
OmarAlebiary 31:4d4a9d78cae5 144 wait(3);
OmarAlebiary 31:4d4a9d78cae5 145 SecondInstructionsMenu(lcd);
OmarAlebiary 31:4d4a9d78cae5 146
OmarAlebiary 28:39607fb67e88 147 lcd.refresh();
OmarAlebiary 31:4d4a9d78cae5 148 wait(1);
OmarAlebiary 28:39607fb67e88 149 while ( pad.check_event(Gamepad::BACK_PRESSED) == false){//keep looping since back not pressed
OmarAlebiary 28:39607fb67e88 150 pad.leds_on();//turn all leds on
OmarAlebiary 28:39607fb67e88 151 wait(0.1);
OmarAlebiary 28:39607fb67e88 152 pad.leds_off();//turn all leds off
OmarAlebiary 28:39607fb67e88 153 wait(0.1);
OmarAlebiary 28:39607fb67e88 154
OmarAlebiary 32:e5d997d2ed79 155 }
OmarAlebiary 28:39607fb67e88 156 }
OmarAlebiary 28:39607fb67e88 157
OmarAlebiary 28:39607fb67e88 158
OmarAlebiary 28:39607fb67e88 159
OmarAlebiary 28:39607fb67e88 160
OmarAlebiary 28:39607fb67e88 161