Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
67:39b9ba6019b0
Parent:
66:e47333ffc6ca
Child:
68:b9cfd27987ac
--- a/main.cpp	Fri May 03 22:39:38 2019 +0000
+++ b/main.cpp	Sat May 04 12:28:04 2019 +0000
@@ -32,6 +32,8 @@
 ///////////// prototypes //////////////
 void init();
 void refresh_game();
+void read_write_stats();
+void _set_mode_speed();
 
 //Constants//
 int fps = 40;  // frames per second, this will be changed in menu.
@@ -44,13 +46,11 @@
     init();
     _start.titleScreen(lcd, pad);
     while(1)  { //This loop is created for Play/Continue configuration
-        _start.read_stats(sd); //this is to save the current highest level in the stats class that can be used in menu.
-        _stats.write(1, sd); //this tells the stats class that the game has started from level 1;
-        _start.menuScreen(lcd, pad);  // this takes us to main menu inside startscreen, and connects automatically to all other menu functions.
-        _start.credits(lcd); // this is after the menu to allow us to hide credits if we want to play the game fast.
-        fps = _start.fps; // sets the frames per second required, selected from the game speed menu.
-        g_mode = _start.g_mode;// allows us to pass this information on to the snakevsblock class, to set the controls to either joystick or motion control.
+        read_write_stats();
+        _start.menu(lcd, pad);  // this takes us to main menu inside startscreen, and connects automatically to all other menu functions.
+        _set_mode_speed();
         // start the game
+        _start.credits(lcd); // this is after the menu to allow us to hide credits if we want to play the game without wasting any time.
         refresh_game();
         wait(1.0f/fps);
 
@@ -59,16 +59,16 @@
 
             _game.read_input(pad, device, g_mode); //this reads the angle or joystick direction, on the condition of either of them being selected.
             _game.update(lcd, pad); //updates the game screen and checks for any collisions.
-            back = _game.CheckGameProgression(lcd, pad, sd); //the int back stores the value 1 if back is pressed inside the update function of snakevsblock,
+            refresh_game();
+            
+            //the int back stores the value 1 if back is pressed inside the update function of snakevsblock,
             //This function also handles level progression and level failure operations by using the class WinLoose.
-            //and also sends relevant data to the sd card to implement stats functionality.
-            
-            
+            back = _game.CheckGameProgression(lcd, pad, sd); //and also sends relevant data to the sd card to implement stats functionality.
+
             if(back)  {
                 break;    //and this allows us to return to main menu by using the keyword break.
             }
 
-            refresh_game();
             wait(1.0f/fps);
         }
     }
@@ -91,4 +91,20 @@
     _game.draw(lcd, pad); //draws the next game frame
     _game.get_pos(); //takes the game object coordinates and saves it privately to use later for implementing collisions.
     lcd.refresh();  //refreshes the N5110 screen to display the frame.
+}
+
+void read_write_stats()
+{
+    _start.read_stats(sd); //this is to save the current highest level in the stats class that can be used in menu.
+    _stats.write(1, sd); //this tells the stats class that the game has started from level 1;
+}
+
+void _set_mode_speed()
+{
+    fps = _start.fps; // sets the frames per second required, selected from the game speed menu.
+    g_mode = _start.g_mode;// allows us to pass this information on to the snakevsblock class, to set the controls to either joystick or motion control.
+    
+    if (g_mode == 2) {  //show instructions to handle motion control.
+        _start.motionControlInstructions(lcd);    //this only comes up on the screen is the user selects motion control from menu options.
+    }
 }
\ No newline at end of file