ELEC2645 (2017/18) / Mbed OS el16ajm
Revision:
10:279d3775d52c
Parent:
9:fe86ddbf7799
Child:
11:b25874e7efe4
diff -r fe86ddbf7799 -r 279d3775d52c main.cpp
--- a/main.cpp	Sun May 06 20:49:48 2018 +0000
+++ b/main.cpp	Sun May 06 22:42:49 2018 +0000
@@ -31,26 +31,26 @@
 void renderGame();
 void renderMenu();
 void welcome();
+void transition();
 
 ///////////// functions ////////////////
 int main()
-{   
+{
     init();
     welcome();
 
-    wait(1.0f/8);  // and wait for one frame period
-
-
+    transition();
+    
     // game loop - read input, update the game state and render the display
     while (1) {
-        if (mainMenu.started()) {
+        if (!mainMenu.started()) { //menu logic and rendering
+            mainMenu.read_input(pad);
+            mainMenu.update();
+            renderMenu();
+        } else { //game logic and rendering
             gameEngine.read_input(pad);
             gameEngine.update(pad);
             renderGame();
-        } else {
-            mainMenu.read_input(pad);
-            mainMenu.update(); //draws the main menu before the game fully starts
-            renderMenu();
         }
     }
 }
@@ -83,9 +83,9 @@
 
 void renderGame()
 {
-    
+
     int fps = 8;  // frames per second
-    
+
     // clear screen, re-draw and refresh
     lcd.clear();
     gameEngine.draw(lcd);
@@ -102,3 +102,15 @@
     wait(1.0f/8);
 }
 
+void transition()
+{ //transition animation between modes to stop 'ghosting' of inputs
+    for (int i = 0; i <= 11; i++) {
+        for (int j = 0; j <= 21; j++) {
+            lcd.drawRect(j*4,i*4,4,4,FILL_BLACK);
+            wait(0.005);
+            lcd.refresh();
+        }
+    }
+
+}
+