Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed FXOS8700CQQQ
Menus.cpp
00001 #include "Menus.h" 00002 00003 00004 //default constructor of the class 00005 Menus::Menus(){ 00006 } 00007 00008 //destructor of the class 00009 Menus::~Menus(){ 00010 } 00011 00012 //dispalys the welcome menu 00013 void Menus::welcomeMenu(Gamepad &pad,N5110 &lcd) { 00014 00015 lcd.printString(" Rocket Racer ",0,0); 00016 00017 lcd.drawSprite(25,8,11,9,(int *)enemyMainMenu);//prints sprites on the welcome menu 00018 lcd.drawSprite(45,15,11,9,(int *)enemyMainMenu); 00019 lcd.drawSprite(35,31,11,9,(int *)rocketMainMenu); 00020 lcd.drawLine(20, 10, 20,45,1);//draws lines 00021 lcd.drawLine(22, 10, 22,45,2); 00022 lcd.drawLine(57, 10, 57,45,1); 00023 lcd.drawLine(55, 10, 55,45,2); 00024 00025 pad.leds_on();//turns all leds on 00026 lcd.refresh(); 00027 tone.Play_Welcome_Melody(pad);//plays a melody 00028 wait(1); 00029 00030 } 00031 00032 //dispalys the main menu 00033 void Menus::drawMenu(N5110 &lcd,Gamepad &pad) { 00034 00035 lcd.clear(); 00036 lcd.printString("MAIN MENU", 15, 0); 00037 lcd.drawLine(1, 10,80 ,10,1); 00038 lcd.printString("Play -A", 2, 2); 00039 lcd.printString("Play /acc -Y", 2, 3); 00040 lcd.printString("Instructions-B", 1, 4); 00041 lcd.printString("Credits - X", 1, 5); 00042 pad.leds_off(); 00043 wait(0.1); 00044 pad.leds_on(); 00045 wait(0.1); 00046 lcd.refresh(); 00047 //calls this method to check button press for each item in the menu 00048 check_button_pressed(pad,lcd); 00049 00050 } 00051 00052 //checks if a button pressed and calls the subsequent method 00053 void Menus::check_button_pressed(Gamepad &pad,N5110 &lcd){ 00054 if (pad.check_event(Gamepad::A_PRESSED) == true){//if A presed 00055 pad.leds_off(); 00056 while(pad.check_event(Gamepad::BACK_PRESSED) == false){//loop since back not pressed 00057 Rocket_Race.Game_Loop(lcd,pad);//call the game loop 00058 } 00059 }else if (pad.check_event(Gamepad::B_PRESSED) == true){//if B presed 00060 InstructionsMenu(pad,lcd);//call the instructions menu 00061 if (pad.check_event(Gamepad::BACK_PRESSED) == true){//if BACK presed 00062 drawMenu(lcd,pad);//returns back to the main menu 00063 } 00064 }else if (pad.check_event(Gamepad::Y_PRESSED) == true){//if Y presed 00065 pad.leds_off(); 00066 while(pad.check_event(Gamepad::BACK_PRESSED) == false){//loop since back not pressed 00067 Rocket_Race.Game_Loop_accelerometer(lcd,pad);//call the game loop with accelerometer control 00068 } 00069 }else if (pad.check_event(Gamepad::X_PRESSED) == true){//if X presed 00070 credits(lcd,pad);//call the credits page 00071 if (pad.check_event(Gamepad::BACK_PRESSED) == true){ 00072 drawMenu(lcd,pad);//returns back to the main menu 00073 } 00074 } 00075 } 00076 00077 //displays credits menu 00078 void Menus::credits(N5110 &lcd,Gamepad &pad) { 00079 00080 lcd.clear(); 00081 //prints strings on the lcd 00082 lcd.printString("Game By:", 8, 1); 00083 lcd.printString("Omar Alebiary", 7, 2); 00084 lcd.printString("ID: 201172644", 7, 3); 00085 00086 lcd.printString("< press BACK ", 12, 5); 00087 00088 lcd.refresh(); 00089 wait(0.5); 00090 while ( pad.check_event(Gamepad::BACK_PRESSED) == false){//keep looping since back not pressed 00091 pad.leds_on();//turn all leds on 00092 wait(0.1); 00093 pad.leds_off();//turn all leds off 00094 wait(0.1); 00095 } 00096 00097 } 00098 00099 //displays loading page 00100 void Menus::loading_menu(N5110 &lcd) { 00101 lcd.clear(); 00102 lcd.printString("loading...", 2, 1); 00103 00104 lcd.drawLine(7, 20,12 ,20,1); 00105 lcd.refresh(); 00106 wait(0.6); 00107 lcd.drawLine(7, 20,24 ,20,1); 00108 lcd.refresh(); 00109 wait(0.5); 00110 lcd.drawLine(7, 20,34 ,20,1); 00111 lcd.refresh(); 00112 wait(0.6); 00113 lcd.drawLine(7, 20,44,20,1); 00114 lcd.refresh(); 00115 wait(0.2); 00116 lcd.drawLine(7, 20,65 ,20,1); 00117 lcd.refresh(); 00118 wait(0.2); 00119 } 00120 00121 //displays the second instructionsmenu 00122 void Menus::SecondInstructionsMenu(N5110 &lcd){ 00123 lcd.clear(); 00124 lcd.printString("U can also use",0,0); 00125 lcd.printString("accelormeter",0,1); 00126 lcd.printString("to control ",0,2); 00127 lcd.printString("the rocket ",0,3); 00128 lcd.printString("in play/acc",0,4); 00129 00130 lcd.printString("< press BACK ", 12, 5); 00131 lcd.refresh(); 00132 } 00133 00134 00135 void Menus::InstructionsMenu(Gamepad &pad,N5110 &lcd){ 00136 00137 lcd.clear(); 00138 lcd.printString("How to play:",0,0); 00139 lcd.printString("Use joystick",0,1); 00140 lcd.printString("or L & R",0,2); 00141 lcd.printString("to escape ",0,3); 00142 lcd.printString("enemies.",0,4); 00143 lcd.refresh(); 00144 wait(3); 00145 SecondInstructionsMenu(lcd); 00146 00147 lcd.refresh(); 00148 wait(1); 00149 while ( pad.check_event(Gamepad::BACK_PRESSED) == false){//keep looping since back not pressed 00150 pad.leds_on();//turn all leds on 00151 wait(0.1); 00152 pad.leds_off();//turn all leds off 00153 wait(0.1); 00154 00155 } 00156 } 00157 00158 00159 00160 00161
Generated on Mon Jul 18 2022 07:45:10 by
1.7.2