Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
36:dfdd619874ae
Parent:
31:6566026b4c6a
Child:
37:ee47699915b8
--- a/Blocks/Blocks.cpp	Wed Apr 17 09:15:43 2019 +0000
+++ b/Blocks/Blocks.cpp	Thu Apr 18 06:19:33 2019 +0000
@@ -281,7 +281,7 @@
 }
 
 
-int Blocks::draw(N5110 &lcd, int length, int blocknum, int srn, int blockgap)
+int Blocks::draw(N5110 &lcd, int length, int blockgap)
 {   
     _velocity.x = 0;
     _velocity.y = 1;
@@ -289,16 +289,16 @@
     //Also prevents SnakeFood from going out of the side of the screen.
     if(_bx < 0){
         _bx = 0;
-        }
+    }
     if(_bx > 84){
         _bx = 84;
-        }
+    }
     if(_by >= (blockgap)){
         k = 0;
-        }
+    }
      if(k == 0){
         send=0;
-        _bx = 0;  //change the number here so that there is always an unsurity(a little) if the food will come or not(change the limits for this)
+        _bx = 0;
         _by = -11;
         k = k+1;
         pos = 4;
@@ -322,7 +322,7 @@
             }
             i++;
         }
-        double roundagain = length/(14/4);  //to make sure at least one is smaller than the snake size
+        double roundagain = length/(7/2);  //to make sure at least one is smaller than the snake size
         caseselect[rand()%5] = floor(roundagain);
           
      }
@@ -411,19 +411,11 @@
 
 
 void Blocks::update(int blocknum, int srn, int send) //send sends the block number only when the y position satisfies a particular requirement
-{
-    if(blockdrop == 0)  {
-        _bx += _velocity.x;
-        _by += _velocity.y;
-    }
-    blockdrop += 1;
-    
-    if(blockdrop == 1)  {  //make this a variable multiple of game speed
-        blockdrop = 0;
-    }
-    if(send)  {
-        caseselect[srn] = blocknum;
-    }
+{                                                    //and srn gives the srn of the block, snake is colliding with.
+    _bx += _velocity.x;
+    _by += _velocity.y;
+        
+    if(send) {caseselect[srn] = blocknum;}
 }