Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
82:c51ae8a501d1
Parent:
81:4c1641e10dcd
Child:
83:329da564799a
--- a/GameObjects/Barriers/Barriers.cpp	Mon May 06 09:05:09 2019 +0000
+++ b/GameObjects/Barriers/Barriers.cpp	Mon May 06 10:49:50 2019 +0000
@@ -34,7 +34,7 @@
     {1},
     {1},
     {1},
-    };
+};
 void Barriers::init()
 {
     reset = 0;
@@ -45,14 +45,27 @@
 {
     velocity.x = 0;
     velocity.y = 1;
-    
-    if((reset == 0)&&((b_y < (_blockgap-11))||(b_y > -8))){
-        _barx = rand()%82;  //this makes the barrier pop up at a random, unspecified location in the x axis.
+
+    if((reset == 0)&&(b_y < (_blockgap-14))) {
+        switch(rand()%4)  {
+            case 0:
+                _barx = 19;
+                break;
+            case 1:
+                _barx = 35;
+                break;
+            case 2:
+                _barx = 51;
+                break;
+            case 3:
+                _barx = 67;
+                break;
+        }
         _bary = -22;
         reset = reset+1; //to stop this if function to keep executing.
     }
     lcd.drawSprite(_barx,_bary,22,1,(int *)Barrier); //Function to draw the frame at all i coordinates as x.
-    
+
 }
 
 Vector2D Barriers::get_pos() //Obtains the X and Y coordinate of the target.
@@ -65,10 +78,12 @@
 void Barriers::update(int blockgap)
 {
     _blockgap = blockgap;
-    _barriergap = _blockgap/3;
-    if (_blockgap <= 60) { _barriergap = 60; }
+    _barriergap = _blockgap/4;
+    if (_blockgap <= 60) {
+        _barriergap = 60;
+    }
     // this if function makes sure the block appears at the rate of blockgap.
-    if(_bary >= _barriergap){
+    if(_bary >= _barriergap) {
         reset = 0;
     }
     _barx += velocity.x;