![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
contains my game for the embedded systems project 2645
Dependencies: mbed FXOS8700CQQQ
Diff: GameMenus/Menus.cpp
- Revision:
- 33:24ef796ff2c8
- Parent:
- 32:e5d997d2ed79
- Child:
- 40:13b8467526d0
diff -r e5d997d2ed79 -r 24ef796ff2c8 GameMenus/Menus.cpp --- a/GameMenus/Menus.cpp Mon Apr 29 17:34:37 2019 +0000 +++ b/GameMenus/Menus.cpp Fri May 03 00:27:52 2019 +0000 @@ -1,31 +1,35 @@ #include "Menus.h" - +//default constructor of the class Menus::Menus(){ } + +//destructor of the class Menus::~Menus(){ } + +//dispalys the welcome menu void Menus::welcomeMenu(Gamepad &pad,N5110 &lcd) { lcd.printString(" Rocket Racer ",0,0); - lcd.drawSprite(25,8,11,9,(int *)enemyMainMenu); + lcd.drawSprite(25,8,11,9,(int *)enemyMainMenu);//prints sprites on the welcome menu lcd.drawSprite(45,15,11,9,(int *)enemyMainMenu); lcd.drawSprite(35,31,11,9,(int *)rocketMainMenu); - lcd.drawLine(20, 10, 20,45,1); + lcd.drawLine(20, 10, 20,45,1);//draws lines lcd.drawLine(22, 10, 22,45,2); lcd.drawLine(57, 10, 57,45,1); lcd.drawLine(55, 10, 55,45,2); pad.leds_on();//turns all leds on lcd.refresh(); - tone.Play_Welcome_Melody(pad); + tone.Play_Welcome_Melody(pad);//plays a melody wait(1); } - +//dispalys the main menu void Menus::drawMenu(N5110 &lcd,Gamepad &pad) { lcd.clear(); @@ -40,41 +44,41 @@ pad.leds_on(); wait(0.1); lcd.refresh(); - + //calls this method to check button press for each item in the menu check_button_pressed(pad,lcd); } - +//checks if a button pressed and calls the subsequent method void Menus::check_button_pressed(Gamepad &pad,N5110 &lcd){ - if (pad.check_event(Gamepad::A_PRESSED) == true){ + if (pad.check_event(Gamepad::A_PRESSED) == true){//if A presed pad.leds_off(); - while(1){ + while(1){//call the game loop Rocket_Race.Game_Loop(lcd,pad); } - }else if (pad.check_event(Gamepad::B_PRESSED) == true){ - InstructionsMenu(pad,lcd); - if (pad.check_event(Gamepad::BACK_PRESSED) == true){ - drawMenu(lcd,pad); - } - }else if (pad.check_event(Gamepad::Y_PRESSED) == true){ + }else if (pad.check_event(Gamepad::B_PRESSED) == true){//if B presed + InstructionsMenu(pad,lcd);//call the instructions menu + if (pad.check_event(Gamepad::BACK_PRESSED) == true){//if BACK presed + drawMenu(lcd,pad);//returns back to the main menu + } + }else if (pad.check_event(Gamepad::Y_PRESSED) == true){//if Y presed pad.leds_off(); - while(1){ + while(1){//call the game loop with accelerometer control Rocket_Race.Game_Loop_accelerometer(lcd,pad); - } - }else if (pad.check_event(Gamepad::X_PRESSED) == true){ - credits(lcd,pad); + } + }else if (pad.check_event(Gamepad::X_PRESSED) == true){//if X presed + credits(lcd,pad);//call the credits page if (pad.check_event(Gamepad::BACK_PRESSED) == true){ - drawMenu(lcd,pad); - } - } - } + drawMenu(lcd,pad);//returns back to the main menu + } + } +} - +//displays credits menu void Menus::credits(N5110 &lcd,Gamepad &pad) { lcd.clear(); - + //prints strings on the lcd lcd.printString("Game By:", 8, 1); lcd.printString("Omar Alebiary", 7, 2); lcd.printString("ID: 201172644", 7, 3); @@ -92,7 +96,7 @@ } - +//displays loading page void Menus::loading_menu(N5110 &lcd) { lcd.clear(); lcd.printString("loading...", 2, 1); @@ -114,6 +118,7 @@ wait(0.2); } +//displays the second instructionsmenu void Menus::SecondInstructionsMenu(N5110 &lcd){ lcd.clear(); lcd.printString("U can also use",0,0); @@ -124,6 +129,7 @@ lcd.printString("< press BACK ", 12, 5); lcd.refresh(); } + void Menus::InstructionsMenu(Gamepad &pad,N5110 &lcd){