Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
37:ee47699915b8
Parent:
36:dfdd619874ae
Child:
38:30e4e6191762
--- a/SnakevsBlock/SnakevsBlock.cpp	Thu Apr 18 06:19:33 2019 +0000
+++ b/SnakevsBlock/SnakevsBlock.cpp	Thu Apr 18 14:03:43 2019 +0000
@@ -77,7 +77,7 @@
     if(blockbuff == blockgap)  {  //this makes blockbuff reset every time the new set of blocks appear.
         blockbuff = -11;
     }
-    if(length > 15)  {  //to make progressive levels harder
+    if(length >= 20)  {  //to make progressive levels harder
         if(blockgap>=50)  {  //to make progressive levels harder
             blockgap -= 20;
         }
@@ -164,6 +164,11 @@
                 srn = CheckBlock(block);  //this tells us which of the 5 blocks we are colliding with
                 blocknum = b_number[srn];
                 ImplementCollision(pad);
+                if((length>=10)&&(b_number[srn]>0)) { //this makes the block stop moving down if it's length is more than 10 and still collides.
+                    _b.velocity.y = 0;
+                    break;//change this so that it collides slower.
+                }
+                else {_b.velocity.y = 1;}
             }
         }
 }
@@ -202,20 +207,26 @@
         snake_pos[7] = _s.get_pos_before7(length);
         snake_pos[8] = _s.get_pos_before8(length);
         snake_pos[9] = _s.get_pos_before9(length);
+        /*
         snake_pos[10] = _s.get_pos_before10(length);
         snake_pos[11] = _s.get_pos_before11(length);
         snake_pos[12] = _s.get_pos_before12(length);
         snake_pos[13] = _s.get_pos_before13(length);
         snake_pos[14] = _s.get_pos_before14(length);
-        
+        */
         //If statements check if the snake sprite has collided with any
         //of the blocks' sides and then stop the snake moving in x axis
         
-        for(int i=0; i<=14; i++)  {
+        int _length;
+        
+        if(length<=10) {_length = length;} //to stop the snake length virtually at 10 when it goes past it.
+        else {_length = 10;}
+    
+        for(int i=0; i<=9; i++)  {
             b[i] = 1;
         }
         
-    for(int i=0; i<=14; i++)  { //i checks for all possible collisions with the snake respective to it's length.
+    for(int i=0; i<=9; i++)  { //i checks for all possible collisions with the snake respective to it's length.
         for(int b_y_combination=0; b_y_combination<=10; b_y_combination++)  {
             if (
                 (snake_pos[i].y == b_pos.y + b_y_combination) ||
@@ -225,11 +236,11 @@
                     //For West side of walls 
                     if(
                         ((snake_pos[i].x == b_pos.x + b_x_combination+2) ||  //W
-                        (snake_pos[i].x + 1 == b_x_combination+2))&&(d != E)&&(length > i) //W
+                        (snake_pos[i].x + 1 == b_x_combination+2))&&(d != E)&&(_length > i) //W
                         ) {
                         //code makes sure that the colliding part doesn't move in x axis.
-                        for(int snake_beed_num=0; snake_beed_num<=15; snake_beed_num++)  {
-                            if(length == snake_beed_num + i)  {
+                        for(int snake_beed_num=0; snake_beed_num<=10; snake_beed_num++)  {
+                            if(_length == snake_beed_num + i)  {
                                 b[snake_beed_num - 1] = 0;
                             }
                         }
@@ -238,11 +249,11 @@
                     //for East side of walls
                     else if (
                         ((snake_pos[i].x + 1 == b_x_combination) ||  //E
-                        (snake_pos[i].x + 2 == b_x_combination))&&(d != W) //E
+                        (snake_pos[i].x + 2 == b_x_combination))&&(d != W)&&(_length > i) //E
                     ) {
                         //code makes sure that the colliding part doesn't move in x axis.
-                        for(int snake_beed_num=0; snake_beed_num<=15; snake_beed_num++)  {
-                            if(length == snake_beed_num + i)  {
+                        for(int snake_beed_num=0; snake_beed_num<=10; snake_beed_num++)  {
+                            if(_length == snake_beed_num + i)  {
                                 b[snake_beed_num - 1] = 0;
                             }
                         }