ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18lg

Dependencies:   mbed

Revision:
4:748b3e0062f6
Parent:
3:beb0cc405b1e
Child:
5:e0f08e8022de
--- a/Head/Head.cpp	Wed May 27 16:14:56 2020 +0000
+++ b/Head/Head.cpp	Wed May 27 20:57:21 2020 +0000
@@ -11,15 +11,16 @@
 
 }
 
-void Head::init(int length, int speed)
+void Head::init(int x, int y, int length, int speed)
 {
-    
+    _x = x;
+    _y = y;
     _length = length;
     _speed = speed;
     srand(time(NULL));
     _x = WIDTH/2 - _length/2;  // snake spawns in random position
     _y = HEIGHT/2 - _length/2;  
-    int direction = N;  // set the direction of snake to north
+  // set the direction of snake to north
     
 }
 void Head::draw(N5110 &lcd) {
@@ -28,26 +29,47 @@
 }
 
 
-void Head::update(Direction d)
+void Head::update(Direction d, float mag)
 {
     // update y value depending on direction of movement
     // North is decrement as origin is at the top-left so decreasing moves up
-    
-    if (pad.X_pressed()){    
-            d == N;
+    _speed = int(mag*10.0f);
+    if (d == N && d != S){
+            _y -= _speed;
+            
             }
-    if (pad.B_pressed()){
-            d == S;
+    if (d == S && d != N){
+            _y += _speed;
+            
+            }
+    if (d == W && d != E){
+           
+            _x -= _speed;
             }
-    if (pad.Y_pressed()){
-            d == W;
-            }
-    if (pad.A_pressed()){
-            d == E;
+    if (d == E && d != W){
+           
+            _x += _speed;
         }
+                    
+                     switch(d){                      
+                case S:
+                 _y;
+                 break;
+                    
+                case N:
+                 _y = 1;
+                 break;
+                    
+                case W:
+                 _x = 1;
+                 break;
+                    
+                case E:
+                 _x = 1;
+                 break;
+                    }
+                    
     }
-    
-    
     // The head changes to the new position