Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:7769e2ad5d7a
- Child:
- 1:8e319bd14b84
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sun May 05 11:50:04 2019 +0000
@@ -0,0 +1,134 @@
+#include "main.h"
+
+/////////////// objects ///////////////
+N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
+Gamepad pad;
+
+int main() {
+
+ init();
+ welcome();
+ menu();
+
+}
+
+void init() {
+
+ // initialise display and peripherals
+ lcd.init();
+ pad.init();
+
+ // initialise any in game functions (e.g: sprites)
+}
+
+void welcome() {
+ // Draw coin
+ // wait
+ // Draw protagonist
+ // wait
+ // draw enemies
+ // wait
+ lcd.printString(" GAME! ",0,0);
+ lcd.refresh();
+ wait(1.0);
+ lcd.printString("By Thomas",0,2);
+ lcd.printString("Foster",0,3);
+ lcd.refresh();
+ wait(2.0);
+
+ while (pad.check_event(Gamepad::START_PRESSED) == false) {
+ lcd.printString("Press start ",0,5);
+ lcd.refresh();
+ wait(0.2);
+ lcd.printString("Press start. ",0,5);
+ lcd.refresh();
+ wait(0.2);
+ lcd.printString("Press start.. ",0,5);
+ lcd.refresh();
+ wait(0.2);
+ lcd.printString("Press start... ",0,5);
+ wait(0.2);
+ }
+}
+
+void menu() {
+
+ string option = "0";
+ lcd.init();
+
+ while(option == "0") {
+
+ lcd.printString("A - Play Now",0,1);
+ lcd.printString("B - Tutorial",0,2);
+ lcd.printString("X - Highscores",0,3);
+ lcd.printString("Y - Credits",0,4);
+ lcd.refresh();
+
+ if (pad.check_event(Gamepad::A_PRESSED) == true) {
+ option = "A";
+ } else if (pad.check_event(Gamepad::B_PRESSED) == true) {
+ option = "B";
+ } else if (pad.check_event(Gamepad::X_PRESSED) == true) {
+ option = "X";
+ } else if (pad.check_event(Gamepad::Y_PRESSED) == true) {
+ option = "Y";
+ }
+
+ wait(0.2);
+ }
+ if (option == "A") {
+ init();
+ lcd.printString(" Play game? ",0,0);
+ ask();
+ } else if (option == "B") {
+ init();
+ lcd.printString("Play tutorial?",0,0);
+ ask();
+ } else if (option == "X") {
+ init();
+ highscores();
+ } else {
+ init();
+ credits();
+ }
+}
+
+void ask() {
+
+ string option = "0";
+ lcd.printString("Are you sure?",0,3);
+ lcd.printString("Back? Start?",0,5);
+ lcd.refresh();
+
+ while (option == "0") {
+
+ if (pad.check_event(Gamepad::START_PRESSED) == true) {
+ option = "start";
+ } else if(pad.check_event(Gamepad::BACK_PRESSED) == true) {
+ option = "back";
+ }
+ wait(0.2);
+ }
+
+ if (option == "back") {
+ menu();
+ } else {
+ init();
+ lcd.printString("Start pressed",0,0);
+ lcd.refresh();
+ }
+}
+
+void highscores() {
+
+ init();
+ lcd.printString(" Highscores!! ",0,0);
+ lcd.refresh();
+}
+
+void credits() {
+
+ init();
+ lcd.printString(" Credits!! ",0,0);
+ lcd.refresh();
+}
\ No newline at end of file