Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
56:142e9fdb77a8
Parent:
55:df0825049171
Child:
58:affb42c56cf8
--- a/GameEngine/SnakevsBlock/SnakevsBlock.cpp	Sat Apr 27 18:56:30 2019 +0000
+++ b/GameEngine/SnakevsBlock/SnakevsBlock.cpp	Sun Apr 28 16:56:08 2019 +0000
@@ -16,9 +16,8 @@
     level = 1;
     garbage = 0; //this is to allow the user to change the position of reference for motion control by saving the absolute angle.
     foodbuff = 0; //this makes the food fall at diffrent times when a particular level starts.
-    send_block_number = 0;
-    blockgap = 300;
-    blockbuff = -50;
+    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 = 350; //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.
     SnakevsBlock::object_initialisations();
 }
@@ -27,11 +26,7 @@
 {
     //This prepares the game for the next level by reseting certain variables.
     foodbuff = 0;
-    for(int i=0; i<=2; i++)  {
-        food_pos[i].x = 0;
-        food_pos[i].y = 0;
-    }
-    if(blockgap >= 50) {blockgap -= 40;}  //to make progressive levels harder by making the blocks drop more frequently.
+    if(blockgap >= 50) {blockgap -= 30;}  //to make progressive levels harder by making the blocks drop more frequently.
     SnakevsBlock::object_initialisations();
 }
 
@@ -54,23 +49,24 @@
         garbage = angle;
     }
     device.get_values();
-    angle = -device.get_roll_angle() - garbage;
-    if(g_mode == 1)  { //this condition returns the relevant working directions if we select joystick in StartScreen.
+    switch (g_mode) {
+    case 1:
         _d = pad.get_direction(); //Obtains Direction pushed towards on Joystick.
         _mag = pad.get_mag(); //Obtains Magnitude of Joystick.
-    }
-    else if(g_mode == 2)  { //this condition returns the relevant working directions if we select motion control in StartScreen.
-        if (angle >= 8) {
+        break;
+    case 2:
+        angle = -device.get_roll_angle() - garbage;
+        if (angle >= 6) {
             _d = E;
         }
-        else if (angle <= -8) {
+        else if (angle <= -6) {
             _d = W;
         }
         else {
             _d = CENTRE;
         }
+        break;
     }
-    device.get_values();
     //printf("%d",gm);
     //printf("%f",angle);
     //printf("%f",device.get_roll_angle());
@@ -80,21 +76,18 @@
     _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
     if(foodbuff >= 0)  {
-        _f.draw(lcd, blockbuff); //Draws the first food.
+        _f.draw(lcd); //Draws the first food.
     }
     if(foodbuff >= 50)  {
-        _ff.draw(lcd, blockbuff); //Draws the second food.
+        _ff.draw(lcd); //Draws the second food.
     }
     if(foodbuff >= 80) {
-        _fff.draw(lcd, blockbuff); //Draws the third food.
+        _fff.draw(lcd); //Draws the third food.
     }
     foodbuff +=1;
     if(foodbuff >= 8) {
         _b.draw(lcd, _length);
     }
-    if(foodbuff == 8) {
-        blockbuff = -10;
-    }
     //Code to print length on game screen.
     _l.print_length_on_screen(lcd);
 } 
@@ -111,10 +104,6 @@
     _ff.update();
     _fff.update(); 
     _b.update(blocknum, blockgap, srn, send_block_number);
-    blockbuff++;
-    if(blockbuff >= blockgap)  {  //this makes blockbuff reset every time the new set of blocks appear.
-        blockbuff = -11;
-    }
     //_statset.read(sd); //to read the currently stored value.
     if(_length == 0)  {
         _wl.GameOver(lcd,pad);