ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18lg

Dependencies:   mbed

Revision:
5:e0f08e8022de
Parent:
4:748b3e0062f6
Child:
8:59b01b57f0da
--- a/Body/Body.cpp	Wed May 27 20:57:21 2020 +0000
+++ b/Body/Body.cpp	Thu May 28 16:29:55 2020 +0000
@@ -1,8 +1,32 @@
-#include Body.h
-
-
+#include "Body.h"
 
-
+Body::Body() {
+    }
+    
+Body::~Body() {
+    }
+    
+void Body::update(Vector2D hP, int nbody) {   
+_nbody = nbody;
+_x_init = hP.x;
+_y_init = hP.y;
+ prevx = bodyx[0];
+ prevy = bodyy[0];
+bodyx[0] = _x_init;
+bodyy[0] = _y_init;
+for (int i = 1; i < nbody; i++) {
+    prev2x = bodyx[i];
+    prev2y = bodyy[i];
+    bodyx[i] = prevx;
+    bodyy[i] = prevy;
+    prevx = prev2x;
+    prevy = prev2y;
+    }
+    }
+    void Body::draw(N5110 &lcd, int nbody) {
 
-for (int i = 0; i < nbody; i++){                            
-            lcd.drawRect(tailx[i], taily[i], 2, 2, FILL_BLACK);
\ No newline at end of file
+int _nbody = nbody;
+for (int k = 0; k < _nbody; k++){                            //Snake tail
+            lcd.drawRect(bodyx[k], bodyy[k], 2, 2, FILL_BLACK); 
+        }      
+        }
\ No newline at end of file