ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Revision:
33:de130e274391
Parent:
31:5c4acae51026
Child:
34:a9b14a4ccd46
--- a/main.cpp	Thu May 09 11:21:53 2019 +0000
+++ b/main.cpp	Thu May 09 11:39:59 2019 +0000
@@ -35,6 +35,7 @@
 void update_game(UserInput input);
 void render();
 void welcome();
+void check_score();
 void game_over();
 
 int main()
@@ -43,23 +44,15 @@
     int number_of_failures = run_all_tests();
     if(number_of_failures > 0) return number_of_failures;
 #endif
-
     while(1) {
         init();
         welcome();
         int fps = 8;
         render();  // draws
-        wait(1.0f/fps);
         while(1) {
             render();
             eng.read_input(pad);
-            bool score_added = eng.get_score_check();
-            eng.update(pad);
-            bool updated_score_added = eng.get_score_check();
-            if ( (score_added == true) && (updated_score_added == true) ) {
-                eng.subtract_score();
-            }  // checking if the previous score has increased by one right after one update means that the a floor
-            // remains fixed at y = 10 (which adds a score). This will then prevent the score from increasing infinitely.
+            check_score();
             wait(0.8f/fps);
             bool end_game = eng.get_game_over();
             if (end_game == true) {
@@ -70,8 +63,6 @@
                 break;
             }
         }
-        render();
-        wait(0.1);
     }
 }
 
@@ -106,6 +97,16 @@
     }
 }
 
+void check_score()
+{
+    bool score_added = eng.get_score_check();
+    eng.update(pad);
+    bool updated_score_added = eng.get_score_check();
+    if ( (score_added == true) && (updated_score_added == true) ) {
+        eng.subtract_score();
+    }  // checking if the previous score has increased by one right after one update means that the a floor
+}  // remains fixed at y = 10 (which adds a score). This will then prevent the score from increasing infinitely.
+
 void game_over()
 {
     lcd.clear();