ELEC2645 (2017/18) / Mbed OS el16ajm
Revision:
15:130900e5c268
Parent:
14:a57a40ff9430
Child:
16:4d329ce7b156
diff -r a57a40ff9430 -r 130900e5c268 main.cpp
--- a/main.cpp	Tue May 08 13:15:41 2018 +0000
+++ b/main.cpp	Tue May 08 14:06:47 2018 +0000
@@ -95,6 +95,7 @@
         pad.leds_off();
         wait(0.1);
     }
+    wait(0.1);
 
 }
 
@@ -110,8 +111,8 @@
 
 void reset()
 {
-    mainMenu.init();
-    gameEngine.init();
+    mainMenu.init();        //resets both the mainMenu and gameEngine
+    gameEngine.init();      //the gameEngine will reset the food and the snake in the process
 }
 
 void renderGame()
@@ -120,7 +121,7 @@
     lcd.clear();
     gameEngine.draw(lcd);
     lcd.refresh();
-    wait(setDif());
+    wait(setDif()); //adaptive fps depending on difficulty
 }
 
 void renderMenu()
@@ -129,16 +130,17 @@
     lcd.clear();
     mainMenu.draw(lcd);
     lcd.refresh();
-    wait(1.0f/8);
+    wait(1.0f/8); //fixed at 8 fps
 }
 
 void transition()
 {
-    //transition animation between modes to stop 'ghosting' of inputs
-    for (int i = 0; i <= 11; i++) {
+    //transition animation between modes to reduce 'ghosting' of inputs
+    
+    for (int i = 0; i <= 11; i++) {                 //max values for i and j were chosen as the screen is 84x44 and the sqaures being drawn are 4x4
         for (int j = 0; j <= 21; j++) {
-            lcd.drawRect(j*4,i*4,4,4,FILL_BLACK);
-            wait(0.005);
+            lcd.drawRect(j*4,i*4,4,4,FILL_BLACK);   //covers the entire screen in 4x4 squares
+            wait(0.005);                            //waits a small amount of time to allow the screen to keep up
             lcd.refresh();
         }
     }
@@ -149,16 +151,16 @@
 {
     int _dif = mainMenu.getDif();
 
-    if (_dif == 1) {    //Low difficulty
+    if (_dif == 1) {                         //Low difficulty
         return 1.0f/4;
-    } else if (_dif == 2) { //Medium difficulty
+    } else if (_dif == 2) {                  //Medium difficulty
         return 1.0f/8;
-    } else if (_dif == 3) { //Hard difficulty
+    } else if (_dif == 3) {                  //Hard difficulty
         return 1.0f/12;
-    } else {    //Adaptive difficulty
+    } else {                                 //Adaptive difficulty
         float _delta = gameEngine.getScore(); 
-        if (_delta < 25) { //Limits FPS to 25
-            return ((1.0f/(_delta + 1.0)));
+        if (_delta < 25) {                   //Limits FPS to 25
+            return ((1.0f/(_delta + 1)));    //changes the fps depending on score
         } else {
             return (1.0f/25);
         }