Harry Rance 200925395 Embedded Systems Project

Dependencies:   mbed

Revision:
3:43970d8d642e
Parent:
2:50feb42b982c
Child:
4:107bdbbf78bf
--- a/main.cpp	Wed Apr 26 17:40:17 2017 +0000
+++ b/main.cpp	Sun Apr 30 15:23:56 2017 +0000
@@ -3,10 +3,11 @@
 #include "Gamepad.h"
 #include "N5110.h"
 #include "GameEngine.h"
+#include "Menu.h"
 
 #define US_X 42
 #define AA_X 2
-#define SPEED 1.5
+#define SPEED 1.8
 
 ////////// structs //////////
 struct UserInput {
@@ -18,6 +19,7 @@
 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
 Gamepad pad;
 GameEngine engine;
+Menu menu;
 
 ////////// prototypes //////////
 void init();
@@ -34,8 +36,22 @@
   wait(1.0f/fps);
 
   while(1){
-    engine.read_input(pad);
-    engine.update(pad);
+    float brightness = pad.read_pot();
+    lcd.setBrightness(brightness);
+    if (menu.is_game_active() == 1){
+      engine.read_input(pad);
+      engine.update(pad);
+      if (pad.check_event(Gamepad::START_PRESSED)){
+        menu.stop_game();
+      }
+      else if (pad.check_event(Gamepad::BACK_PRESSED)){
+        engine.initialise(US_X, AA_X, SPEED);
+        menu.stop_game();
+      }
+    } else if (menu.is_game_active() == 0){
+      menu.read_input(pad);
+      menu.update(pad);
+    }
     render();
     wait(1.0f/fps);
   }
@@ -44,7 +60,11 @@
 void render()
 {
   lcd.clear();
-  engine.draw(lcd);
+  if (menu.is_game_active() == 1){
+    engine.draw(lcd);
+  } else if (menu.is_game_active() == 0) {
+    menu.draw(lcd);
+  }
   lcd.refresh();
 }
 
@@ -53,6 +73,7 @@
   lcd.init();
   pad.init();
 
+  menu.initialise(25, 0);
   engine.initialise(US_X, AA_X, SPEED);
 
 }