Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
19:05cc9f801468
Parent:
18:b391caa5754c
Child:
20:1e6338403427
--- a/SnakevsBlock/SnakevsBlock.cpp	Mon Apr 08 05:57:04 2019 +0000
+++ b/SnakevsBlock/SnakevsBlock.cpp	Mon Apr 08 16:46:14 2019 +0000
@@ -14,10 +14,12 @@
 {
     //The snake length configuration and all the other initial information passing will be done here
     length = 3;
+    level = 1;
     foodbuff = 0;
     send=0;
     speed = 1;
-    blockgap = 0;
+    blockgap = 161;
+    blockbuff = 0;
     b0 = 1;
     b1 = 1;
     b2 = 1;
@@ -57,8 +59,10 @@
         foodbuff +=1;
     }
     if(foodbuff >=8) {
-        blockgap = 0;
-        send = _b.draw(lcd, length, blocknum, srn);
+        send = _b.draw(lcd, length, blocknum, srn, blockgap);
+    }
+    if(foodbuff == 8) {
+        blockbuff = 0;
     }
     
     //Code to print length on game screen.
@@ -86,9 +90,13 @@
     _ff.update();
     _fff.update(); 
     _b.update(blocknum, srn, send);
-    blockgap++;
-    if(blockgap == 300)  {  //change this while changing the block drop gap
-        blockgap = 0;
+    blockbuff++;
+    if(blockbuff == blockgap)  {  //change this while changing the block drop gap
+        blockbuff = 0;
+    }
+    if(length > 15)  {  //change this while changing the block drop gap
+        blockgap -= 10;
+        level += 1;
     }
 }
 
@@ -145,10 +153,8 @@
         pad.tone(1000.0,0.1);
         f_pos.x = rand() % 82;
         f_pos.y = -2;
-        if((blockgap<28)&&(blockgap>292))  { //change this while changing the block drop gap
-            if(f_pos.y == -2)  {
-                f_pos.y = -18;
-            }
+        if(blockbuff<25)  { //change this while changing the block drop gap
+            f_pos.y = -30;
         }
         length+=1;
         
@@ -180,10 +186,8 @@
         pad.tone(1000.0,0.1);
         ff_pos.x = rand() % 82;
         ff_pos.y = -2;
-        if((blockgap<28)&&(blockgap>292))  { //change this while changing the block drop gap
-            if(ff_pos.y == -2)  {
-                ff_pos.y = -18;
-            }
+        if(blockbuff<25)  { //change this while changing the block drop gap
+            f_pos.y = -30;
         }
         length+=1;
         
@@ -215,10 +219,8 @@
         pad.tone(1000.0,0.1);
         fff_pos.x = rand() % 82;
         fff_pos.y = -2;
-        if((blockgap<28)&&(blockgap>292))  { //change this while changing the block drop gap
-            if(fff_pos.y == -2)  {
-                fff_pos.y = -18;
-            }
+        if(blockbuff<25)  { //change this while changing the block drop gap
+            f_pos.y = -30;
         }
         length+=1;