ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el17sdl_v2

Dependencies:   mbed

Revision:
14:4356797fd16e
Parent:
11:c4b740a970f8
--- a/SnakeTail/SnakeTail.cpp	Sun May 24 15:08:31 2020 +0000
+++ b/SnakeTail/SnakeTail.cpp	Sun May 24 15:27:53 2020 +0000
@@ -9,7 +9,11 @@
 {
     
 }
-
+/*  The snake tail is drawn as individual segments
+    coordinates for each segment are stored in two arrays
+    this update function iterates through the segments and changes 
+    the coordinates to the previous segments
+*/
 void SnakeTail::update(Vector2D prevHead, int length) 
 {
     _length = length;
@@ -21,18 +25,21 @@
     prevY = tailY[0];
     tailX[0] = _x_init;
     tailY[0] = _y_init;
-    
-    
-    
+
     for(int i = 1; i < _length; i++) {
+        //stores the current x and y coordinates
         prev2X = tailX[i];
         prev2Y = tailY[i];
+        //updtes the current coordinates so the are the same as i-1
         tailX[i] = prevX;
         tailY[i] = prevY;
+        //sets previous x and y to the original coordinates for this i 
         prevX = prev2X;
         prevY = prev2Y;
     }
-    /*for (int l = 0; l < _length; l++) {
+    
+    /*debugging print statements to make sure the array is being updated correctly 
+    for (int l = 0; l < _length; l++) {
         printf("i = %i\n", l);
         printf("tailX[i] = %i\n", tailX[l]);
         printf("tailY[i] = %i\n", tailY[l]);