Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
84:9950d561fdf8
Parent:
83:329da564799a
Child:
87:871d9fecb593
--- a/MenuClasses/StartScreen/StartScreen.cpp	Mon May 06 14:28:35 2019 +0000
+++ b/MenuClasses/StartScreen/StartScreen.cpp	Mon May 06 16:15:21 2019 +0000
@@ -139,9 +139,7 @@
 {
     _lcd = lcd;
     _pad = pad;
-    _stats.init(_lcd, _pad);
-    _settings.init(_lcd, _pad);
-    _tutorial.init(_lcd, _pad);
+    StartScreen::object_initialisations();
     fps = 15; //sets the default frames per second to a certain value.
     menu_index = 16; //main menu selection arrow position
     g_mode = 1; //game mode selection (joystick/motion control).
@@ -150,6 +148,15 @@
     controlSensitivity = 5; //sensitivity of control speed of menu options.
 }
 
+
+void StartScreen::object_initialisations()
+{
+    _stats.init(_lcd, _pad); //Stats object initialisation.
+    _settings.init(_lcd, _pad); //Settings object initialisation.
+    _tutorial.init(_lcd, _pad); //Tutorial object initialisation.
+}
+
+
 void StartScreen::titleScreen()
 {
     //this saves the Theme song I want to play at the start.
@@ -163,16 +170,13 @@
         _pad->tone(song[(ani+48)/3],0.1);
 
         //This Allows us to skip/play the animation before the menu screen
-        _startPressed = false; //by default, animmation is not skipped, as StartScreen::instruct(lcd,pad) requires Start_Pressed to be 0 to be displayed
-        if((_pad->check_event(Gamepad::START_PRESSED) == true)||(_pad->check_event(Gamepad::A_PRESSED) == true)) { //to allow the gamer to skip the long starting animation if they are not a fan.
-            _startPressed = true;
-            break;
+        if (StartScreen::checkStartorAPressed()) {
+            return;    //if StartorA is pressed, the while loop is escaped.
+        } else {
+            wait(0.2);
         }
-        wait(0.2);
     }
-    if (_startPressed == false) {
-        wait(0.3);    //dont wait anymore if start is pressed. (this is to allow for quick skip towards menu)
-    }
+    wait(0.3);
     _pad->leds_off();
     _lcd->clear();
 
@@ -194,7 +198,9 @@
         _pad->leds_off();
         wait(0.1);
     }
-    _pad->tone(1000.0,0.1);
+    if (_startPressed == false) {//dont wait anymore if start is pressed. (this is to allow for quick skip towards menu)
+        _pad->tone(1000.0,0.1);
+    }
     _lcd->clear();
     _pad->leds_off();
 }
@@ -230,6 +236,19 @@
     return _backPressed; //returns true if back is pressed, returns false otherwise.
 }
 
+
+bool StartScreen::checkStartorAPressed()
+{
+    //This Allows us to skip/play the animation before the menu screen
+    if((_pad->check_event(Gamepad::START_PRESSED) == true)||(_pad->check_event(Gamepad::A_PRESSED) == true)) { //to allow the gamer to skip the long starting animation if they are not a fan.
+        _pad->tone(1000.0,0.1);
+        _startPressed = true;
+    } else {
+        _startPressed = false;
+    }
+    return _startPressed; //returns true if start/A is pressed, returns false otherwise.
+}
+
 void StartScreen::menu()
 {
     _lcd->clear();
@@ -240,7 +259,7 @@
         _lcd->clear();
         StartScreen::mainMenu();
         _lcd->refresh();
-        
+
     }
     _pad->tone(1000.0,0.1);
     StartScreen::nextMenu(); //after all main menu operations have been completed, this function allows us to get to the next menu.