ELEC2645 (2018/19) / Mbed 2 deprecated el17ttds

Dependencies:   mbed N5110_tf

Revision:
7:08f78909dda7
Parent:
4:3446009e2f38
Child:
8:d1c04f0e4890
--- a/main.cpp	Wed May 08 19:05:36 2019 +0000
+++ b/main.cpp	Thu May 09 01:30:57 2019 +0000
@@ -17,10 +17,10 @@
 }
 
 void init() {
-
-    // initialise display and peripherals
-    lcd.init();
-    pad.init();
+  alive = true;
+  // initialise display and peripherals
+  lcd.init();
+  pad.init();
 
     // initialise any in game functions (e.g: sprites)
     engine.init(MAP_WIDTH,MAP_HEIGHT,SCREEN_WIDTH,SCREEN_HEIGHT);
@@ -42,16 +42,16 @@
     wait(2.0);
 
     while (pad.check_event(Gamepad::START_PRESSED) == false) {
-        lcd.printString("Press start ",0,5);
+        lcd.printString("Press Start ",0,5);
         lcd.refresh();
         wait(0.2);
-        lcd.printString("Press start. ",0,5);
+        lcd.printString("Press Start. ",0,5);
         lcd.refresh();
         wait(0.2);
-        lcd.printString("Press start.. ",0,5);
+        lcd.printString("Press Start.. ",0,5);
         lcd.refresh();
         wait(0.2);
-        lcd.printString("Press start... ",0,5);
+        lcd.printString("Press Start... ",0,5);
         wait(0.2);
     }
 }
@@ -129,18 +129,43 @@
     }
 }
 
-void play() {
-
-    lcd.refresh();
-    wait(0.2);
+void play() { // My game loop
+  lcd.refresh();
+  wait(0.2);
+  gameLoop();
+}
 
-    while ( pad.check_event(Gamepad::START_PRESSED) == false) {
-        lcd.refresh();
-        engine.read(pad);
-        engine.write(MAX_SPEED);
-        engine.render(lcd);
-        wait(0.1);
+void gameLoop() {
+  while ( (alive == true) || (pad.check_event(Gamepad::START_PRESSED) == false) ) {
+    lcd.refresh();
+    engine.read(pad);
+    alive = engine.write(MAX_SPEED, pad);
+    engine.render(lcd);
+    wait(0.1);
+  }
+  if (alive) {
+    while (pad.check_event(Gamepad::START_PRESSED) == false) {
+      lcd.clear();
+      lcd.printString("    PAUSED    ", 0, 0);
+      lcd.refresh();
+      wait(0.5);
+      lcd.printString("Press Start", 0, 3);
+      lcd.refresh();
+      wait(0.2);
+      lcd.printString("Press Start.", 0, 3);
+      lcd.refresh();
+      wait(0.2);
+      lcd.printString("Press Start .", 0, 3);
+      lcd.refresh();
+      wait(0.2);
+      lcd.printString("Press Start  .", 0, 3);
+      lcd.refresh();
+      wait(0.2);
     }
+  } else {
+    lcd.clear();
+    lcd.printString("YOU HELLA DEAD", 0, 0);
+  }
 }
 
 void tutorial() {