![](/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:
- 28:39607fb67e88
- Child:
- 29:e660274d8222
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GameMenus/Menus.cpp Wed Apr 24 10:19:07 2019 +0000 @@ -0,0 +1,140 @@ +#include "Menus.h" + + + +Menus::Menus(){ +} + +void Menus::welcomeMenu(Gamepad &pad,N5110 &lcd) { + + lcd.printString(" Rocket Racer ",0,0); + + lcd.drawSprite(25,8,11,9,(int *)enemyMainMenu); + 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(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); + wait(1); + +} + + +void Menus::drawMenu(N5110 &lcd,Gamepad &pad) { + + lcd.clear(); + lcd.printString("MAIN MENU", 15, 0); + lcd.drawLine(1, 10,80 ,10,1); + lcd.printString("Play -A", 2, 2); + lcd.printString("Instructions-B", 1, 3); + lcd.printString("Credits - X", 1, 4); + pad.leds_off(); + wait(0.1); + pad.leds_on(); + wait(0.1); + lcd.refresh(); + + check_button_pressed(pad,lcd); + +} + + +void Menus::check_button_pressed(Gamepad &pad,N5110 &lcd){ + + if (pad.check_event(Gamepad::A_PRESSED) == true){ + pad.leds_off(); + while(1){ + 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::X_PRESSED) == true){ + credits(lcd,pad); + if (pad.check_event(Gamepad::BACK_PRESSED) == true){ + drawMenu(lcd,pad); + } + } + } + + +void Menus::credits(N5110 &lcd,Gamepad &pad) { + + lcd.clear(); + + lcd.printString("Game By:", 8, 1); + lcd.printString("Omar Alebiary", 7, 2); + lcd.printString("ID: 201172644", 7, 3); + + lcd.printString("< press BACK ", 12, 5); + + + lcd.refresh(); + wait(0.5); + while ( pad.check_event(Gamepad::BACK_PRESSED) == false){//keep looping since back not pressed + pad.leds_on();//turn all leds on + wait(0.1); + pad.leds_off();//turn all leds off + wait(0.1); + + } + +} + + +void Menus::loading_menu(N5110 &lcd) { + lcd.clear(); + lcd.printString("loading...", 2, 1); + + lcd.drawLine(7, 20,12 ,20,1); + lcd.refresh(); + wait(0.6); + lcd.drawLine(7, 20,24 ,20,1); + lcd.refresh(); + wait(0.5); + lcd.drawLine(7, 20,34 ,20,1); + lcd.refresh(); + wait(0.6); + lcd.drawLine(7, 20,44,20,1); + lcd.refresh(); + wait(0.2); + lcd.drawLine(7, 20,65 ,20,1); + lcd.refresh(); + wait(0.2); +} + + +void Menus::InstructionsMenu(Gamepad &pad,N5110 &lcd){ + + lcd.clear(); + lcd.printString("How to play:",0,0); + lcd.printString("Use joystick",0,1); + lcd.printString("or L & R",0,2); + lcd.printString("to escape ",0,3); + lcd.printString("enemies.",0,4); + lcd.printString("< press BACK ", 12, 5); + + lcd.refresh(); + wait(0.5); + while ( pad.check_event(Gamepad::BACK_PRESSED) == false){//keep looping since back not pressed + pad.leds_on();//turn all leds on + wait(0.1); + pad.leds_off();//turn all leds off + wait(0.1); + + } +} + + + + + \ No newline at end of file