Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
16:7b474f873683
Parent:
15:f4d069da093d
Child:
17:54e13faeaf64
--- a/SnakevsBlock/SnakevsBlock.cpp	Thu Apr 04 18:50:40 2019 +0000
+++ b/SnakevsBlock/SnakevsBlock.cpp	Fri Apr 05 05:46:11 2019 +0000
@@ -17,7 +17,7 @@
     foodbuff = 0;
     send=0;
     speed = 1;
-    //memory = 0;
+    blockgap = 0;
 }
 
 
@@ -30,7 +30,7 @@
 
 void SnakevsBlock::draw(N5110 &lcd, Gamepad &pad)
 {
-    _s.draw(lcd, length); //Draws the Snake.     //Make these snake buffs relative to the snake drops which in turn relate to the game speed
+    _s.draw(pad, lcd, length); //Draws the Snake.     //Make these snake buffs relative to the snake drops which in turn relate to the game speed
     if(foodbuff >=0)  {
         _f.draw(lcd); //Draws the first food.
         if(foodbuff >=50)  {
@@ -40,11 +40,8 @@
             }
         }
         foodbuff +=1;
-        if(foodbuff == 110)  {
-            foodbuff = 110;
-        }
     }
-    if(foodbuff >=4) {
+    if(foodbuff >=8) {
         send = _b.draw(lcd, length, blocknum, srn);
     }
     
@@ -73,6 +70,10 @@
     _ff.update();
     _fff.update(); 
     _b.update(blocknum, srn, send);
+    blockgap++;
+    if(blockgap == 150)  {  //change this while changing the block drop gap
+        blockgap = 0;
+    }
 }
 
 void SnakevsBlock::get_pos()
@@ -128,7 +129,11 @@
         pad.tone(1000.0,0.1);
         f_pos.x = rand() % 82;
         f_pos.y = -2;
-        
+        if((blockgap==147)||(blockgap==148)||(blockgap==149)||(blockgap==150)||(blockgap==0)||(blockgap==1)||(blockgap==2)||(blockgap==3)||(blockgap==4)||(blockgap==5)||(blockgap==6)||(blockgap==7)||(blockgap==8)||(blockgap==9)||(blockgap==10)||(blockgap==11)||(blockgap==12)||(blockgap==13))  { //change this while changing the block drop gap
+            if(f_pos.y == -2)  {
+                f_pos.y = -18;
+            }
+        }
         length+=1;
         
     }
@@ -159,7 +164,11 @@
         pad.tone(1000.0,0.1);
         ff_pos.x = rand() % 82;
         ff_pos.y = -2;
-        
+        if((blockgap==147)||(blockgap==148)||(blockgap==149)||(blockgap==150)||(blockgap==0)||(blockgap==1)||(blockgap==2)||(blockgap==3)||(blockgap==4)||(blockgap==5)||(blockgap==6)||(blockgap==7)||(blockgap==8)||(blockgap==9)||(blockgap==10)||(blockgap==11)||(blockgap==12)||(blockgap==13))  { //change this while changing the block drop gap
+            if(ff_pos.y == -2)  {
+                ff_pos.y = -18;
+            }
+        }
         length+=1;
         
     }
@@ -190,7 +199,11 @@
         pad.tone(1000.0,0.1);
         fff_pos.x = rand() % 82;
         fff_pos.y = -2;
-        
+        if((blockgap==147)||(blockgap==148)||(blockgap==149)||(blockgap==150)||(blockgap==0)||(blockgap==1)||(blockgap==2)||(blockgap==3)||(blockgap==4)||(blockgap==5)||(blockgap==6)||(blockgap==7)||(blockgap==8)||(blockgap==9)||(blockgap==10)||(blockgap==11)||(blockgap==12)||(blockgap==13))  { //change this while changing the block drop gap
+            if(fff_pos.y == -2)  {
+                fff_pos.y = -18;
+            }
+        }
         length+=1;
         
     }