![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
contains my game for the embedded systems project 2645
Dependencies: mbed FXOS8700CQQQ
GameMenus/Menus.cpp@29:e660274d8222, 2019-04-25 (annotated)
- Committer:
- OmarAlebiary
- Date:
- Thu Apr 25 10:44:53 2019 +0000
- Revision:
- 29:e660274d8222
- Parent:
- 28:39607fb67e88
- Child:
- 30:c5060010a1e6
added doxygen comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
OmarAlebiary | 28:39607fb67e88 | 1 | #include "Menus.h" |
OmarAlebiary | 28:39607fb67e88 | 2 | |
OmarAlebiary | 28:39607fb67e88 | 3 | |
OmarAlebiary | 28:39607fb67e88 | 4 | |
OmarAlebiary | 28:39607fb67e88 | 5 | Menus::Menus(){ |
OmarAlebiary | 28:39607fb67e88 | 6 | } |
OmarAlebiary | 29:e660274d8222 | 7 | Menus::~Menus(){ |
OmarAlebiary | 29:e660274d8222 | 8 | } |
OmarAlebiary | 28:39607fb67e88 | 9 | void Menus::welcomeMenu(Gamepad &pad,N5110 &lcd) { |
OmarAlebiary | 28:39607fb67e88 | 10 | |
OmarAlebiary | 28:39607fb67e88 | 11 | lcd.printString(" Rocket Racer ",0,0); |
OmarAlebiary | 28:39607fb67e88 | 12 | |
OmarAlebiary | 28:39607fb67e88 | 13 | lcd.drawSprite(25,8,11,9,(int *)enemyMainMenu); |
OmarAlebiary | 28:39607fb67e88 | 14 | lcd.drawSprite(45,15,11,9,(int *)enemyMainMenu); |
OmarAlebiary | 28:39607fb67e88 | 15 | lcd.drawSprite(35,31,11,9,(int *)rocketMainMenu); |
OmarAlebiary | 28:39607fb67e88 | 16 | lcd.drawLine(20, 10, 20,45,1); |
OmarAlebiary | 28:39607fb67e88 | 17 | lcd.drawLine(22, 10, 22,45,2); |
OmarAlebiary | 28:39607fb67e88 | 18 | lcd.drawLine(57, 10, 57,45,1); |
OmarAlebiary | 28:39607fb67e88 | 19 | lcd.drawLine(55, 10, 55,45,2); |
OmarAlebiary | 28:39607fb67e88 | 20 | |
OmarAlebiary | 28:39607fb67e88 | 21 | pad.leds_on();//turns all leds on |
OmarAlebiary | 28:39607fb67e88 | 22 | lcd.refresh(); |
OmarAlebiary | 28:39607fb67e88 | 23 | tone.Play_Welcome_Melody(pad); |
OmarAlebiary | 28:39607fb67e88 | 24 | wait(1); |
OmarAlebiary | 28:39607fb67e88 | 25 | |
OmarAlebiary | 28:39607fb67e88 | 26 | } |
OmarAlebiary | 28:39607fb67e88 | 27 | |
OmarAlebiary | 28:39607fb67e88 | 28 | |
OmarAlebiary | 28:39607fb67e88 | 29 | void Menus::drawMenu(N5110 &lcd,Gamepad &pad) { |
OmarAlebiary | 28:39607fb67e88 | 30 | |
OmarAlebiary | 28:39607fb67e88 | 31 | lcd.clear(); |
OmarAlebiary | 28:39607fb67e88 | 32 | lcd.printString("MAIN MENU", 15, 0); |
OmarAlebiary | 28:39607fb67e88 | 33 | lcd.drawLine(1, 10,80 ,10,1); |
OmarAlebiary | 28:39607fb67e88 | 34 | lcd.printString("Play -A", 2, 2); |
OmarAlebiary | 28:39607fb67e88 | 35 | lcd.printString("Instructions-B", 1, 3); |
OmarAlebiary | 28:39607fb67e88 | 36 | lcd.printString("Credits - X", 1, 4); |
OmarAlebiary | 28:39607fb67e88 | 37 | pad.leds_off(); |
OmarAlebiary | 28:39607fb67e88 | 38 | wait(0.1); |
OmarAlebiary | 28:39607fb67e88 | 39 | pad.leds_on(); |
OmarAlebiary | 28:39607fb67e88 | 40 | wait(0.1); |
OmarAlebiary | 28:39607fb67e88 | 41 | lcd.refresh(); |
OmarAlebiary | 28:39607fb67e88 | 42 | |
OmarAlebiary | 28:39607fb67e88 | 43 | check_button_pressed(pad,lcd); |
OmarAlebiary | 28:39607fb67e88 | 44 | |
OmarAlebiary | 28:39607fb67e88 | 45 | } |
OmarAlebiary | 28:39607fb67e88 | 46 | |
OmarAlebiary | 28:39607fb67e88 | 47 | |
OmarAlebiary | 28:39607fb67e88 | 48 | void Menus::check_button_pressed(Gamepad &pad,N5110 &lcd){ |
OmarAlebiary | 28:39607fb67e88 | 49 | |
OmarAlebiary | 28:39607fb67e88 | 50 | if (pad.check_event(Gamepad::A_PRESSED) == true){ |
OmarAlebiary | 28:39607fb67e88 | 51 | pad.leds_off(); |
OmarAlebiary | 28:39607fb67e88 | 52 | while(1){ |
OmarAlebiary | 28:39607fb67e88 | 53 | Rocket_Race.Game_Loop(lcd,pad); |
OmarAlebiary | 28:39607fb67e88 | 54 | } |
OmarAlebiary | 28:39607fb67e88 | 55 | } |
OmarAlebiary | 28:39607fb67e88 | 56 | else if (pad.check_event(Gamepad::B_PRESSED) == true){ |
OmarAlebiary | 28:39607fb67e88 | 57 | InstructionsMenu(pad,lcd); |
OmarAlebiary | 28:39607fb67e88 | 58 | if (pad.check_event(Gamepad::BACK_PRESSED) == true){ |
OmarAlebiary | 28:39607fb67e88 | 59 | drawMenu(lcd,pad); |
OmarAlebiary | 28:39607fb67e88 | 60 | } |
OmarAlebiary | 28:39607fb67e88 | 61 | } |
OmarAlebiary | 28:39607fb67e88 | 62 | else if (pad.check_event(Gamepad::X_PRESSED) == true){ |
OmarAlebiary | 28:39607fb67e88 | 63 | credits(lcd,pad); |
OmarAlebiary | 28:39607fb67e88 | 64 | if (pad.check_event(Gamepad::BACK_PRESSED) == true){ |
OmarAlebiary | 28:39607fb67e88 | 65 | drawMenu(lcd,pad); |
OmarAlebiary | 28:39607fb67e88 | 66 | } |
OmarAlebiary | 28:39607fb67e88 | 67 | } |
OmarAlebiary | 28:39607fb67e88 | 68 | } |
OmarAlebiary | 28:39607fb67e88 | 69 | |
OmarAlebiary | 28:39607fb67e88 | 70 | |
OmarAlebiary | 28:39607fb67e88 | 71 | void Menus::credits(N5110 &lcd,Gamepad &pad) { |
OmarAlebiary | 28:39607fb67e88 | 72 | |
OmarAlebiary | 28:39607fb67e88 | 73 | lcd.clear(); |
OmarAlebiary | 28:39607fb67e88 | 74 | |
OmarAlebiary | 28:39607fb67e88 | 75 | lcd.printString("Game By:", 8, 1); |
OmarAlebiary | 28:39607fb67e88 | 76 | lcd.printString("Omar Alebiary", 7, 2); |
OmarAlebiary | 28:39607fb67e88 | 77 | lcd.printString("ID: 201172644", 7, 3); |
OmarAlebiary | 28:39607fb67e88 | 78 | |
OmarAlebiary | 28:39607fb67e88 | 79 | lcd.printString("< press BACK ", 12, 5); |
OmarAlebiary | 28:39607fb67e88 | 80 | |
OmarAlebiary | 28:39607fb67e88 | 81 | |
OmarAlebiary | 28:39607fb67e88 | 82 | lcd.refresh(); |
OmarAlebiary | 28:39607fb67e88 | 83 | wait(0.5); |
OmarAlebiary | 28:39607fb67e88 | 84 | while ( pad.check_event(Gamepad::BACK_PRESSED) == false){//keep looping since back not pressed |
OmarAlebiary | 28:39607fb67e88 | 85 | pad.leds_on();//turn all leds on |
OmarAlebiary | 28:39607fb67e88 | 86 | wait(0.1); |
OmarAlebiary | 28:39607fb67e88 | 87 | pad.leds_off();//turn all leds off |
OmarAlebiary | 28:39607fb67e88 | 88 | wait(0.1); |
OmarAlebiary | 28:39607fb67e88 | 89 | |
OmarAlebiary | 28:39607fb67e88 | 90 | } |
OmarAlebiary | 28:39607fb67e88 | 91 | |
OmarAlebiary | 28:39607fb67e88 | 92 | } |
OmarAlebiary | 28:39607fb67e88 | 93 | |
OmarAlebiary | 28:39607fb67e88 | 94 | |
OmarAlebiary | 28:39607fb67e88 | 95 | void Menus::loading_menu(N5110 &lcd) { |
OmarAlebiary | 28:39607fb67e88 | 96 | lcd.clear(); |
OmarAlebiary | 28:39607fb67e88 | 97 | lcd.printString("loading...", 2, 1); |
OmarAlebiary | 28:39607fb67e88 | 98 | |
OmarAlebiary | 28:39607fb67e88 | 99 | lcd.drawLine(7, 20,12 ,20,1); |
OmarAlebiary | 28:39607fb67e88 | 100 | lcd.refresh(); |
OmarAlebiary | 28:39607fb67e88 | 101 | wait(0.6); |
OmarAlebiary | 28:39607fb67e88 | 102 | lcd.drawLine(7, 20,24 ,20,1); |
OmarAlebiary | 28:39607fb67e88 | 103 | lcd.refresh(); |
OmarAlebiary | 28:39607fb67e88 | 104 | wait(0.5); |
OmarAlebiary | 28:39607fb67e88 | 105 | lcd.drawLine(7, 20,34 ,20,1); |
OmarAlebiary | 28:39607fb67e88 | 106 | lcd.refresh(); |
OmarAlebiary | 28:39607fb67e88 | 107 | wait(0.6); |
OmarAlebiary | 28:39607fb67e88 | 108 | lcd.drawLine(7, 20,44,20,1); |
OmarAlebiary | 28:39607fb67e88 | 109 | lcd.refresh(); |
OmarAlebiary | 28:39607fb67e88 | 110 | wait(0.2); |
OmarAlebiary | 28:39607fb67e88 | 111 | lcd.drawLine(7, 20,65 ,20,1); |
OmarAlebiary | 28:39607fb67e88 | 112 | lcd.refresh(); |
OmarAlebiary | 28:39607fb67e88 | 113 | wait(0.2); |
OmarAlebiary | 28:39607fb67e88 | 114 | } |
OmarAlebiary | 28:39607fb67e88 | 115 | |
OmarAlebiary | 28:39607fb67e88 | 116 | |
OmarAlebiary | 28:39607fb67e88 | 117 | void Menus::InstructionsMenu(Gamepad &pad,N5110 &lcd){ |
OmarAlebiary | 28:39607fb67e88 | 118 | |
OmarAlebiary | 28:39607fb67e88 | 119 | lcd.clear(); |
OmarAlebiary | 28:39607fb67e88 | 120 | lcd.printString("How to play:",0,0); |
OmarAlebiary | 28:39607fb67e88 | 121 | lcd.printString("Use joystick",0,1); |
OmarAlebiary | 28:39607fb67e88 | 122 | lcd.printString("or L & R",0,2); |
OmarAlebiary | 28:39607fb67e88 | 123 | lcd.printString("to escape ",0,3); |
OmarAlebiary | 28:39607fb67e88 | 124 | lcd.printString("enemies.",0,4); |
OmarAlebiary | 28:39607fb67e88 | 125 | lcd.printString("< press BACK ", 12, 5); |
OmarAlebiary | 28:39607fb67e88 | 126 | |
OmarAlebiary | 28:39607fb67e88 | 127 | lcd.refresh(); |
OmarAlebiary | 28:39607fb67e88 | 128 | wait(0.5); |
OmarAlebiary | 28:39607fb67e88 | 129 | while ( pad.check_event(Gamepad::BACK_PRESSED) == false){//keep looping since back not pressed |
OmarAlebiary | 28:39607fb67e88 | 130 | pad.leds_on();//turn all leds on |
OmarAlebiary | 28:39607fb67e88 | 131 | wait(0.1); |
OmarAlebiary | 28:39607fb67e88 | 132 | pad.leds_off();//turn all leds off |
OmarAlebiary | 28:39607fb67e88 | 133 | wait(0.1); |
OmarAlebiary | 28:39607fb67e88 | 134 | |
OmarAlebiary | 28:39607fb67e88 | 135 | } |
OmarAlebiary | 28:39607fb67e88 | 136 | } |
OmarAlebiary | 28:39607fb67e88 | 137 | |
OmarAlebiary | 28:39607fb67e88 | 138 | |
OmarAlebiary | 28:39607fb67e88 | 139 | |
OmarAlebiary | 28:39607fb67e88 | 140 | |
OmarAlebiary | 28:39607fb67e88 | 141 |