contains my game for the embedded systems project 2645

Dependencies:   mbed FXOS8700CQQQ

Committer:
OmarAlebiary
Date:
Mon Apr 29 17:34:37 2019 +0000
Revision:
32:e5d997d2ed79
Parent:
31:4d4a9d78cae5
Child:
33:24ef796ff2c8
Fixed accelerometer sensitivity

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 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 30:c5060010a1e6 35 lcd.printString("Play /acc -Y", 2, 3);
OmarAlebiary 30:c5060010a1e6 36 lcd.printString("Instructions-B", 1, 4);
OmarAlebiary 30:c5060010a1e6 37 lcd.printString("Credits - X", 1, 5);
OmarAlebiary 28:39607fb67e88 38 pad.leds_off();
OmarAlebiary 28:39607fb67e88 39 wait(0.1);
OmarAlebiary 28:39607fb67e88 40 pad.leds_on();
OmarAlebiary 28:39607fb67e88 41 wait(0.1);
OmarAlebiary 28:39607fb67e88 42 lcd.refresh();
OmarAlebiary 28:39607fb67e88 43
OmarAlebiary 28:39607fb67e88 44 check_button_pressed(pad,lcd);
OmarAlebiary 28:39607fb67e88 45
OmarAlebiary 28:39607fb67e88 46 }
OmarAlebiary 28:39607fb67e88 47
OmarAlebiary 28:39607fb67e88 48
OmarAlebiary 30:c5060010a1e6 49 void Menus::check_button_pressed(Gamepad &pad,N5110 &lcd){
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 30:c5060010a1e6 55 }else if (pad.check_event(Gamepad::B_PRESSED) == true){
OmarAlebiary 28:39607fb67e88 56 InstructionsMenu(pad,lcd);
OmarAlebiary 28:39607fb67e88 57 if (pad.check_event(Gamepad::BACK_PRESSED) == true){
OmarAlebiary 28:39607fb67e88 58 drawMenu(lcd,pad);
OmarAlebiary 28:39607fb67e88 59 }
OmarAlebiary 30:c5060010a1e6 60 }else if (pad.check_event(Gamepad::Y_PRESSED) == true){
OmarAlebiary 30:c5060010a1e6 61 pad.leds_off();
OmarAlebiary 30:c5060010a1e6 62 while(1){
OmarAlebiary 30:c5060010a1e6 63 Rocket_Race.Game_Loop_accelerometer(lcd,pad);
OmarAlebiary 30:c5060010a1e6 64 }
OmarAlebiary 30:c5060010a1e6 65 }else if (pad.check_event(Gamepad::X_PRESSED) == true){
OmarAlebiary 28:39607fb67e88 66 credits(lcd,pad);
OmarAlebiary 28:39607fb67e88 67 if (pad.check_event(Gamepad::BACK_PRESSED) == true){
OmarAlebiary 28:39607fb67e88 68 drawMenu(lcd,pad);
OmarAlebiary 28:39607fb67e88 69 }
OmarAlebiary 28:39607fb67e88 70 }
OmarAlebiary 28:39607fb67e88 71 }
OmarAlebiary 28:39607fb67e88 72
OmarAlebiary 28:39607fb67e88 73
OmarAlebiary 28:39607fb67e88 74 void Menus::credits(N5110 &lcd,Gamepad &pad) {
OmarAlebiary 28:39607fb67e88 75
OmarAlebiary 28:39607fb67e88 76 lcd.clear();
OmarAlebiary 28:39607fb67e88 77
OmarAlebiary 28:39607fb67e88 78 lcd.printString("Game By:", 8, 1);
OmarAlebiary 28:39607fb67e88 79 lcd.printString("Omar Alebiary", 7, 2);
OmarAlebiary 28:39607fb67e88 80 lcd.printString("ID: 201172644", 7, 3);
OmarAlebiary 28:39607fb67e88 81
OmarAlebiary 28:39607fb67e88 82 lcd.printString("< press BACK ", 12, 5);
OmarAlebiary 28:39607fb67e88 83
OmarAlebiary 28:39607fb67e88 84 lcd.refresh();
OmarAlebiary 28:39607fb67e88 85 wait(0.5);
OmarAlebiary 28:39607fb67e88 86 while ( pad.check_event(Gamepad::BACK_PRESSED) == false){//keep looping since back not pressed
OmarAlebiary 28:39607fb67e88 87 pad.leds_on();//turn all leds on
OmarAlebiary 28:39607fb67e88 88 wait(0.1);
OmarAlebiary 28:39607fb67e88 89 pad.leds_off();//turn all leds off
OmarAlebiary 30:c5060010a1e6 90 wait(0.1);
OmarAlebiary 28:39607fb67e88 91 }
OmarAlebiary 28:39607fb67e88 92
OmarAlebiary 28:39607fb67e88 93 }
OmarAlebiary 28:39607fb67e88 94
OmarAlebiary 28:39607fb67e88 95
OmarAlebiary 28:39607fb67e88 96 void Menus::loading_menu(N5110 &lcd) {
OmarAlebiary 28:39607fb67e88 97 lcd.clear();
OmarAlebiary 28:39607fb67e88 98 lcd.printString("loading...", 2, 1);
OmarAlebiary 28:39607fb67e88 99
OmarAlebiary 28:39607fb67e88 100 lcd.drawLine(7, 20,12 ,20,1);
OmarAlebiary 28:39607fb67e88 101 lcd.refresh();
OmarAlebiary 28:39607fb67e88 102 wait(0.6);
OmarAlebiary 28:39607fb67e88 103 lcd.drawLine(7, 20,24 ,20,1);
OmarAlebiary 28:39607fb67e88 104 lcd.refresh();
OmarAlebiary 28:39607fb67e88 105 wait(0.5);
OmarAlebiary 28:39607fb67e88 106 lcd.drawLine(7, 20,34 ,20,1);
OmarAlebiary 28:39607fb67e88 107 lcd.refresh();
OmarAlebiary 28:39607fb67e88 108 wait(0.6);
OmarAlebiary 28:39607fb67e88 109 lcd.drawLine(7, 20,44,20,1);
OmarAlebiary 28:39607fb67e88 110 lcd.refresh();
OmarAlebiary 28:39607fb67e88 111 wait(0.2);
OmarAlebiary 28:39607fb67e88 112 lcd.drawLine(7, 20,65 ,20,1);
OmarAlebiary 28:39607fb67e88 113 lcd.refresh();
OmarAlebiary 28:39607fb67e88 114 wait(0.2);
OmarAlebiary 28:39607fb67e88 115 }
OmarAlebiary 28:39607fb67e88 116
OmarAlebiary 31:4d4a9d78cae5 117 void Menus::SecondInstructionsMenu(N5110 &lcd){
OmarAlebiary 31:4d4a9d78cae5 118 lcd.clear();
OmarAlebiary 31:4d4a9d78cae5 119 lcd.printString("U can also use",0,0);
OmarAlebiary 31:4d4a9d78cae5 120 lcd.printString("accelormeter",0,1);
OmarAlebiary 31:4d4a9d78cae5 121 lcd.printString("to control ",0,2);
OmarAlebiary 31:4d4a9d78cae5 122 lcd.printString("the rocket ",0,3);
OmarAlebiary 31:4d4a9d78cae5 123
OmarAlebiary 31:4d4a9d78cae5 124 lcd.printString("< press BACK ", 12, 5);
OmarAlebiary 31:4d4a9d78cae5 125 lcd.refresh();
OmarAlebiary 31:4d4a9d78cae5 126 }
OmarAlebiary 31:4d4a9d78cae5 127
OmarAlebiary 28:39607fb67e88 128 void Menus::InstructionsMenu(Gamepad &pad,N5110 &lcd){
OmarAlebiary 28:39607fb67e88 129
OmarAlebiary 28:39607fb67e88 130 lcd.clear();
OmarAlebiary 28:39607fb67e88 131 lcd.printString("How to play:",0,0);
OmarAlebiary 28:39607fb67e88 132 lcd.printString("Use joystick",0,1);
OmarAlebiary 28:39607fb67e88 133 lcd.printString("or L & R",0,2);
OmarAlebiary 28:39607fb67e88 134 lcd.printString("to escape ",0,3);
OmarAlebiary 28:39607fb67e88 135 lcd.printString("enemies.",0,4);
OmarAlebiary 31:4d4a9d78cae5 136 lcd.refresh();
OmarAlebiary 31:4d4a9d78cae5 137 wait(3);
OmarAlebiary 31:4d4a9d78cae5 138 SecondInstructionsMenu(lcd);
OmarAlebiary 31:4d4a9d78cae5 139
OmarAlebiary 28:39607fb67e88 140 lcd.refresh();
OmarAlebiary 31:4d4a9d78cae5 141 wait(1);
OmarAlebiary 28:39607fb67e88 142 while ( pad.check_event(Gamepad::BACK_PRESSED) == false){//keep looping since back not pressed
OmarAlebiary 28:39607fb67e88 143 pad.leds_on();//turn all leds on
OmarAlebiary 28:39607fb67e88 144 wait(0.1);
OmarAlebiary 28:39607fb67e88 145 pad.leds_off();//turn all leds off
OmarAlebiary 28:39607fb67e88 146 wait(0.1);
OmarAlebiary 28:39607fb67e88 147
OmarAlebiary 32:e5d997d2ed79 148 }
OmarAlebiary 28:39607fb67e88 149 }
OmarAlebiary 28:39607fb67e88 150
OmarAlebiary 28:39607fb67e88 151
OmarAlebiary 28:39607fb67e88 152
OmarAlebiary 28:39607fb67e88 153
OmarAlebiary 28:39607fb67e88 154