Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
70:7caab8069b9b
Parent:
68:b9cfd27987ac
Child:
71:4bd2b27693f3
--- a/GameEngine/SnakevsBlock/SnakevsBlock.cpp	Sat May 04 17:18:44 2019 +0000
+++ b/GameEngine/SnakevsBlock/SnakevsBlock.cpp	Sat May 04 20:48:10 2019 +0000
@@ -20,8 +20,9 @@
     _dropbuff = 0; //this makes the food fall at diffrent times when a particular level starts.
     send_block_number = 0; //this is 0 when there is no collision, thus block number isn't remembered for next set (which would lead to empty blocks).
     blockgap = 300; //this is the number of itterations the block will reccur after in the first level.
+
     for(int i=0; i<=14; i++)  {
-        b[i] = 1;   //makes all the snake beads move by default.
+        b[i] = 1;
     }
 }
 
@@ -104,7 +105,8 @@
 void SnakevsBlock::draw(N5110 &lcd, Gamepad &pad)
 {
     _length = _l._getLength(); //saves the snake length into a private variable.
-    _s.draw(lcd, _length, level); //Draws the Snake.     //Make these snake buffs relative to the snake drops which in turn relate to the game speed
+    SnakevsBlock::makeVirtualLengthMaxTen(); //stops the length at 10 for collision and drawing purposes.
+    _s.draw(lcd, _virtualLength, level); //Draws the Snake.     //Make these snake buffs relative to the snake drops which in turn relate to the game speed
     if(_dropbuff >= 0)  {
         _f.draw(lcd); //Draws the first food after a loop delay of 0.
     }
@@ -167,8 +169,8 @@
     // 81.000000 0.000000 top right
     // 0.000000 0.000000 is top left
     // 81.000000 45.000000 bottom right
-    snakex = _s.get_pos().x; //this could be snake_pos[0].x or simply snake_pos[0] to represent both x&y but as it is used the most, it improves readability.
-    snakey = _s.get_pos().y; //this could be snake_pos[0].y or simply snake_pos[0] to represent both x&y but as it is used the most, it improves readability.
+    snakex = _s.get_pos(0).x; //this could be snake_pos[0].x or simply snake_pos[0] to represent both x&y but as it is used the most, it improves readability.
+    snakey = _s.get_pos(0).y; //this could be snake_pos[0].y or simply snake_pos[0] to represent both x&y but as it is used the most, it improves readability.
     //printf("snakexy in GAME = %d %d \n", snakex, snakey);
     //Obtains all required coordinates.
     food_pos[0] = _f.get_pos();
@@ -177,16 +179,16 @@
     //obtains origin cordinates of block.
     b_pos = _b.get_pos();
     //this saves the positions of each snake beed (the first to the last) in a single array. Element[0] is the top beed and soo on.
-    snake_pos[0] = _s.get_pos(); //gets the position of the top beed and saves in array.
-    snake_pos[1] = _s.get_pos_before1(); //gets the position of the second beed and saves in array.
-    snake_pos[2] = _s.get_pos_before2(); //gets the position of the third beed and saves in array.
-    snake_pos[3] = _s.get_pos_before3(); //gets the position of the fourth beed and saves in array.
-    snake_pos[4] = _s.get_pos_before4(); //gets the position of the fifth beed and saves in array.
-    snake_pos[5] = _s.get_pos_before5(); //gets the position of the sixth beed and saves in array.
-    snake_pos[6] = _s.get_pos_before6(); //gets the position of the seventh beed and saves in array.
-    snake_pos[7] = _s.get_pos_before7(); //gets the position of the eight beed and saves in array.
-    snake_pos[8] = _s.get_pos_before8(); //gets the position of the ninth beed and saves in array.
-    snake_pos[9] = _s.get_pos_before9(); //gets the position of the last beed and saves in array.
+    snake_pos[0] = _s.get_pos(0); //gets the position of the top beed and saves in array.
+    snake_pos[1] = _s.get_pos(1); //gets the position of the second beed and saves in array.
+    snake_pos[2] = _s.get_pos(2); //gets the position of the third beed and saves in array.
+    snake_pos[3] = _s.get_pos(3); //gets the position of the fourth beed and saves in array.
+    snake_pos[4] = _s.get_pos(4); //gets the position of the fifth beed and saves in array.
+    snake_pos[5] = _s.get_pos(5); //gets the position of the sixth beed and saves in array.
+    snake_pos[6] = _s.get_pos(6); //gets the position of the seventh beed and saves in array.
+    snake_pos[7] = _s.get_pos(7); //gets the position of the eight beed and saves in array.
+    snake_pos[8] = _s.get_pos(8); //gets the position of the ninth beed and saves in array.
+    snake_pos[9] = _s.get_pos(9); //gets the position of the last beed and saves in array.
 }
 
 
@@ -356,9 +358,7 @@
 
 void SnakevsBlock::CheckSnakeBlockSidesEastWestCollision(int b_x_combination, int i) //i checks for all possible collisions with the snake respective to it's length.
 {
-    SnakevsBlock::makeVirtualLengthMaxTen(); //stops the length at 10 for collision purposes.
-
-//For West side of walls
+    //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)&&(_virtualLength > i) //W