ELEC2645 (2018/19) / Mbed 2 deprecated el17ttds

Dependencies:   mbed N5110_tf

Committer:
el17ttds
Date:
Sun May 05 11:50:04 2019 +0000
Revision:
0:7769e2ad5d7a
Child:
1:8e319bd14b84
Main menu

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17ttds 0:7769e2ad5d7a 1 #include "main.h"
el17ttds 0:7769e2ad5d7a 2
el17ttds 0:7769e2ad5d7a 3 /////////////// objects ///////////////
el17ttds 0:7769e2ad5d7a 4 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
el17ttds 0:7769e2ad5d7a 5 Gamepad pad;
el17ttds 0:7769e2ad5d7a 6
el17ttds 0:7769e2ad5d7a 7 int main() {
el17ttds 0:7769e2ad5d7a 8
el17ttds 0:7769e2ad5d7a 9 init();
el17ttds 0:7769e2ad5d7a 10 welcome();
el17ttds 0:7769e2ad5d7a 11 menu();
el17ttds 0:7769e2ad5d7a 12
el17ttds 0:7769e2ad5d7a 13 }
el17ttds 0:7769e2ad5d7a 14
el17ttds 0:7769e2ad5d7a 15 void init() {
el17ttds 0:7769e2ad5d7a 16
el17ttds 0:7769e2ad5d7a 17 // initialise display and peripherals
el17ttds 0:7769e2ad5d7a 18 lcd.init();
el17ttds 0:7769e2ad5d7a 19 pad.init();
el17ttds 0:7769e2ad5d7a 20
el17ttds 0:7769e2ad5d7a 21 // initialise any in game functions (e.g: sprites)
el17ttds 0:7769e2ad5d7a 22 }
el17ttds 0:7769e2ad5d7a 23
el17ttds 0:7769e2ad5d7a 24 void welcome() {
el17ttds 0:7769e2ad5d7a 25 // Draw coin
el17ttds 0:7769e2ad5d7a 26 // wait
el17ttds 0:7769e2ad5d7a 27 // Draw protagonist
el17ttds 0:7769e2ad5d7a 28 // wait
el17ttds 0:7769e2ad5d7a 29 // draw enemies
el17ttds 0:7769e2ad5d7a 30 // wait
el17ttds 0:7769e2ad5d7a 31 lcd.printString(" GAME! ",0,0);
el17ttds 0:7769e2ad5d7a 32 lcd.refresh();
el17ttds 0:7769e2ad5d7a 33 wait(1.0);
el17ttds 0:7769e2ad5d7a 34 lcd.printString("By Thomas",0,2);
el17ttds 0:7769e2ad5d7a 35 lcd.printString("Foster",0,3);
el17ttds 0:7769e2ad5d7a 36 lcd.refresh();
el17ttds 0:7769e2ad5d7a 37 wait(2.0);
el17ttds 0:7769e2ad5d7a 38
el17ttds 0:7769e2ad5d7a 39 while (pad.check_event(Gamepad::START_PRESSED) == false) {
el17ttds 0:7769e2ad5d7a 40 lcd.printString("Press start ",0,5);
el17ttds 0:7769e2ad5d7a 41 lcd.refresh();
el17ttds 0:7769e2ad5d7a 42 wait(0.2);
el17ttds 0:7769e2ad5d7a 43 lcd.printString("Press start. ",0,5);
el17ttds 0:7769e2ad5d7a 44 lcd.refresh();
el17ttds 0:7769e2ad5d7a 45 wait(0.2);
el17ttds 0:7769e2ad5d7a 46 lcd.printString("Press start.. ",0,5);
el17ttds 0:7769e2ad5d7a 47 lcd.refresh();
el17ttds 0:7769e2ad5d7a 48 wait(0.2);
el17ttds 0:7769e2ad5d7a 49 lcd.printString("Press start... ",0,5);
el17ttds 0:7769e2ad5d7a 50 wait(0.2);
el17ttds 0:7769e2ad5d7a 51 }
el17ttds 0:7769e2ad5d7a 52 }
el17ttds 0:7769e2ad5d7a 53
el17ttds 0:7769e2ad5d7a 54 void menu() {
el17ttds 0:7769e2ad5d7a 55
el17ttds 0:7769e2ad5d7a 56 string option = "0";
el17ttds 0:7769e2ad5d7a 57 lcd.init();
el17ttds 0:7769e2ad5d7a 58
el17ttds 0:7769e2ad5d7a 59 while(option == "0") {
el17ttds 0:7769e2ad5d7a 60
el17ttds 0:7769e2ad5d7a 61 lcd.printString("A - Play Now",0,1);
el17ttds 0:7769e2ad5d7a 62 lcd.printString("B - Tutorial",0,2);
el17ttds 0:7769e2ad5d7a 63 lcd.printString("X - Highscores",0,3);
el17ttds 0:7769e2ad5d7a 64 lcd.printString("Y - Credits",0,4);
el17ttds 0:7769e2ad5d7a 65 lcd.refresh();
el17ttds 0:7769e2ad5d7a 66
el17ttds 0:7769e2ad5d7a 67 if (pad.check_event(Gamepad::A_PRESSED) == true) {
el17ttds 0:7769e2ad5d7a 68 option = "A";
el17ttds 0:7769e2ad5d7a 69 } else if (pad.check_event(Gamepad::B_PRESSED) == true) {
el17ttds 0:7769e2ad5d7a 70 option = "B";
el17ttds 0:7769e2ad5d7a 71 } else if (pad.check_event(Gamepad::X_PRESSED) == true) {
el17ttds 0:7769e2ad5d7a 72 option = "X";
el17ttds 0:7769e2ad5d7a 73 } else if (pad.check_event(Gamepad::Y_PRESSED) == true) {
el17ttds 0:7769e2ad5d7a 74 option = "Y";
el17ttds 0:7769e2ad5d7a 75 }
el17ttds 0:7769e2ad5d7a 76
el17ttds 0:7769e2ad5d7a 77 wait(0.2);
el17ttds 0:7769e2ad5d7a 78 }
el17ttds 0:7769e2ad5d7a 79 if (option == "A") {
el17ttds 0:7769e2ad5d7a 80 init();
el17ttds 0:7769e2ad5d7a 81 lcd.printString(" Play game? ",0,0);
el17ttds 0:7769e2ad5d7a 82 ask();
el17ttds 0:7769e2ad5d7a 83 } else if (option == "B") {
el17ttds 0:7769e2ad5d7a 84 init();
el17ttds 0:7769e2ad5d7a 85 lcd.printString("Play tutorial?",0,0);
el17ttds 0:7769e2ad5d7a 86 ask();
el17ttds 0:7769e2ad5d7a 87 } else if (option == "X") {
el17ttds 0:7769e2ad5d7a 88 init();
el17ttds 0:7769e2ad5d7a 89 highscores();
el17ttds 0:7769e2ad5d7a 90 } else {
el17ttds 0:7769e2ad5d7a 91 init();
el17ttds 0:7769e2ad5d7a 92 credits();
el17ttds 0:7769e2ad5d7a 93 }
el17ttds 0:7769e2ad5d7a 94 }
el17ttds 0:7769e2ad5d7a 95
el17ttds 0:7769e2ad5d7a 96 void ask() {
el17ttds 0:7769e2ad5d7a 97
el17ttds 0:7769e2ad5d7a 98 string option = "0";
el17ttds 0:7769e2ad5d7a 99 lcd.printString("Are you sure?",0,3);
el17ttds 0:7769e2ad5d7a 100 lcd.printString("Back? Start?",0,5);
el17ttds 0:7769e2ad5d7a 101 lcd.refresh();
el17ttds 0:7769e2ad5d7a 102
el17ttds 0:7769e2ad5d7a 103 while (option == "0") {
el17ttds 0:7769e2ad5d7a 104
el17ttds 0:7769e2ad5d7a 105 if (pad.check_event(Gamepad::START_PRESSED) == true) {
el17ttds 0:7769e2ad5d7a 106 option = "start";
el17ttds 0:7769e2ad5d7a 107 } else if(pad.check_event(Gamepad::BACK_PRESSED) == true) {
el17ttds 0:7769e2ad5d7a 108 option = "back";
el17ttds 0:7769e2ad5d7a 109 }
el17ttds 0:7769e2ad5d7a 110 wait(0.2);
el17ttds 0:7769e2ad5d7a 111 }
el17ttds 0:7769e2ad5d7a 112
el17ttds 0:7769e2ad5d7a 113 if (option == "back") {
el17ttds 0:7769e2ad5d7a 114 menu();
el17ttds 0:7769e2ad5d7a 115 } else {
el17ttds 0:7769e2ad5d7a 116 init();
el17ttds 0:7769e2ad5d7a 117 lcd.printString("Start pressed",0,0);
el17ttds 0:7769e2ad5d7a 118 lcd.refresh();
el17ttds 0:7769e2ad5d7a 119 }
el17ttds 0:7769e2ad5d7a 120 }
el17ttds 0:7769e2ad5d7a 121
el17ttds 0:7769e2ad5d7a 122 void highscores() {
el17ttds 0:7769e2ad5d7a 123
el17ttds 0:7769e2ad5d7a 124 init();
el17ttds 0:7769e2ad5d7a 125 lcd.printString(" Highscores!! ",0,0);
el17ttds 0:7769e2ad5d7a 126 lcd.refresh();
el17ttds 0:7769e2ad5d7a 127 }
el17ttds 0:7769e2ad5d7a 128
el17ttds 0:7769e2ad5d7a 129 void credits() {
el17ttds 0:7769e2ad5d7a 130
el17ttds 0:7769e2ad5d7a 131 init();
el17ttds 0:7769e2ad5d7a 132 lcd.printString(" Credits!! ",0,0);
el17ttds 0:7769e2ad5d7a 133 lcd.refresh();
el17ttds 0:7769e2ad5d7a 134 }