Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
30:461231877c89
Parent:
29:c6358c39a70e
Child:
32:3a3bdeffdf62
diff -r c6358c39a70e -r 461231877c89 StartScreen/StartScreen.cpp
--- a/StartScreen/StartScreen.cpp	Sun Apr 14 10:24:59 2019 +0000
+++ b/StartScreen/StartScreen.cpp	Mon Apr 15 06:00:01 2019 +0000
@@ -109,12 +109,6 @@
     {0,1,1,0,0,0,0,0},
     {1,1,0,0,0,0,0,0},
 };
-int i=16;
-int lr=1;
-int gs=1; 
-int st=1;
-int sc=1;  
-float cs = 4;
 
 StartScreen::StartScreen()
 {
@@ -126,7 +120,15 @@
 
 }
 
-
+void StartScreen::init()
+{
+    i = 16;
+    lr = 1;
+    gs = 1; 
+    st = 1;
+    sc = 1;  
+    cs = 4;
+}
 
 void StartScreen::screen_saver(N5110 &lcd, Gamepad &pad)
 {
@@ -149,12 +151,11 @@
 
 void StartScreen::instruct(N5110 &lcd, Gamepad &pad)
 {
-    wait(1/cs);
     lcd.printString("Please Press",5,1); //Function used to promt the user to start.
     lcd.printString("Start",25,3);
     lcd.printString("to Begin",15,5);
     lcd.refresh();
-    wait(1/cs);
+    pad.init();
     while ( pad.check_event(Gamepad::START_PRESSED) == false) {
         pad.leds_on();
         wait(0.1);
@@ -182,84 +183,57 @@
 void StartScreen::menu_screen1(N5110 &lcd, Gamepad &pad)
 {
     lcd.clear();
-    wait(1/cs);
+    StartScreen::init();
     while ((pad.check_event(Gamepad::A_PRESSED) == false)&&(pad.check_event(Gamepad::START_PRESSED) == false)) {  //Change this to if button pressed.
-        lcd.printString("SnakeVSBlock",5,0);
-        lcd.printString("Play",0,2);
-        lcd.printString("Settings",0,3);
-        lcd.printString("Stats",0,4);
-        lcd.printString("Tutorial",0,5);
-        Direction d = pad.get_direction();
-        if((d==N)&&(i>16))  {
-                i=i-8;
-        }
-        if((d==S)&&(i<40))  {
-                i=i+8;
-        }
-        lcd.drawSprite(50,i,7,9,(int *)arrow); //Function used to draw the sprite.
-        lcd.refresh();
-        wait(1/cs);
-        lcd.clear();
+        StartScreen::DisplaySc1Contents(lcd, pad);
     }
     pad.tone(1000.0,0.1);
+    wait(1/cs);
     if(i == 16)
     {
         menu_screen2(lcd, pad);
     }
     else if(i == 24)
     {
-        settings.info(lcd, pad);
-        while (pad.check_event(Gamepad::BACK_PRESSED) == false) {  //if button pressed.
-            Direction d = pad.get_direction();
-            wait(1/cs);
-            lcd.clear();
-            
-            if((d==E)&&(st==5))  {
-                st=1;
-            }
-            else if((d==W)&&(st==1))  {
-                st=5;
-            }
-            else if((d==E)&&(1<=st<=4))  {
-                st=st+1;
-            }
-            else if((d==W)&&(2<=st<=5))  {
-                st=st-1;
-            }
-            
-            lcd.drawSprite(5,22,13,8,(int *)navL); //Function used to draw the sprite.
-            lcd.drawSprite(71,22,13,8,(int *)navR); //Function used to draw the sprite.
-            if(st==1)  { 
-                cs = settings.controlSensitivity(lcd, pad);
-            }
-            if(st==2)  {
-                settings.brigntness(lcd, pad);
-            }
-            if(st==3)  {
-                settings.contrast(lcd, pad);
-            }
-            if(st==4)  {
-                settings.volume(lcd, pad);
-            }
-            if(st==5)  {
-                sc = settings.showCredits(lcd, pad);
-            } 
-            lcd.refresh();
-        }
-    pad.tone(1000.0,0.1);
-    menu_screen1(lcd, pad);
+        float *cs_sc;
+        cs_sc = settings.Implement(lcd, pad, st, cs);
+        pad.tone(1000.0,0.1);
+        menu_screen1(lcd, pad);
+        cs = cs_sc[0];
+        sc = cs_sc[1];
 }
     else
     {
         menu_screen1(lcd, pad);
         lr=1;
     }
-    
 }
+
+void StartScreen::DisplaySc1Contents(N5110 &lcd, Gamepad &pad)
+{   
+    lcd.printString("SnakeVSBlock",5,0);
+    lcd.printString("Play",0,2);
+    lcd.printString("Settings",0,3);
+    lcd.printString("Stats",0,4);
+    lcd.printString("Tutorial",0,5);
+    Direction d = pad.get_direction();
+    if((d==N)&&(i>16))  {
+            i=i-8;
+    }
+    if((d==S)&&(i<40))  {
+            i=i+8;
+    }
+    lcd.drawSprite(50,i,7,9,(int *)arrow); //Function used to draw the sprite.
+    lcd.refresh();
+    wait(1/cs);
+    lcd.clear();
+}
+
 void StartScreen::menu_screen2(N5110 &lcd, Gamepad &pad)
 {
     lcd.clear();
     wait(2/cs);
+    pad.init();
     while ((pad.check_event(Gamepad::A_PRESSED) == false)&&(pad.check_event(Gamepad::START_PRESSED) == false)) {  //Change this to if button pressed.
     
         Direction d = pad.get_direction();
@@ -297,8 +271,9 @@
 {
     lcd.clear();
     wait(2/cs);
+    pad.init();
     while ((pad.check_event(Gamepad::A_PRESSED) == false)&&(pad.check_event(Gamepad::START_PRESSED) == false)) {  //Change this to if button pressed.
-        
+    
         Direction d = pad.get_direction();
         wait(1/cs);
         if((d==E)&&(gs==4))  {