Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
68:b9cfd27987ac
Parent:
63:205f0ca48473
Child:
70:7caab8069b9b
--- a/GameObjects/Snake/Snake.cpp	Sat May 04 12:28:04 2019 +0000
+++ b/GameObjects/Snake/Snake.cpp	Sat May 04 16:56:04 2019 +0000
@@ -17,9 +17,10 @@
     {0,1,0},
 };
 
-void Snake::init()
+void Snake::init(int length, int speed)
 {
-    _speed = 1;// change this according to the options selected
+    _length = length;
+    _speed = speed;// change this according to the options selected
     m = 0; //Variable used to allow a starting location for the player.
 }
 
@@ -28,12 +29,10 @@
 {
     _length = length;
     if(m == 0) {
-        _x[0] = WIDTH/2;  //Spawns player sprite near the middle of the screen.
-        _y[0] = HEIGHT - 3;
+        Vector2D p = {WIDTH/2, HEIGHT - 3};  //Spawns player sprite near the middle of the screen.
+        Snake::set_pos(p);
 
         for(int i=0; i<=13; i++)  {
-            _x[i+1] = _x[i];
-            _y[i+1] = _y[i] - 3;
             b[i] = 1;
         }
         b[14] = 1;
@@ -58,6 +57,17 @@
 }
 
 
+void Snake::set_pos(Vector2D p)
+{
+    _x[0] = p.x;  //Spawns player sprite near the middle of the screen.
+    _y[0] = p.y;
+
+    for(int i=0; i<=13; i++)  {
+        _x[i+1] = _x[i];
+        _y[i+1] = _y[i] - 3;
+    }
+}
+
 Vector2D Snake::get_pos()
 {
     for(int i=1; i<=10; i++)  {