Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: SnakeTail/SnakeTail.cpp
- Revision:
- 11:c4b740a970f8
- Parent:
- 7:c67a5c6a874f
- Child:
- 14:4356797fd16e
--- a/SnakeTail/SnakeTail.cpp Fri May 22 12:29:53 2020 +0000
+++ b/SnakeTail/SnakeTail.cpp Sat May 23 10:50:43 2020 +0000
@@ -10,31 +10,40 @@
}
-void SnakeTail::update(Vector2D headPos, int length)
+void SnakeTail::update(Vector2D prevHead, int length)
{
- int _length = length;
- int _x = headPos.x;
- int _y = headPos.y;
- tailX[0] = _x;
- tailY[0] = _y;
- int prevX = tailX[0];
- int prevY = tailY[0];
+ _length = length;
+ _x_init = prevHead.x;
+ _y_init = prevHead.y;
+ //printf("x_init = %i\n", _x_init);
+ //printf("y_init = %i\n", _y_init);
+ prevX = tailX[0];
+ prevY = tailY[0];
+ tailX[0] = _x_init;
+ tailY[0] = _y_init;
- for (int i = 1; i < _length; i++) {
+ for(int i = 1; i < _length; i++) {
+ prev2X = tailX[i];
+ prev2Y = tailY[i];
tailX[i] = prevX;
tailY[i] = prevY;
- prevX = tailX[i];
- prevY = tailY[i];
- printf("i = %i\n", i);
- printf("tail x[i]= %i\n", tailX[i]);
- printf("tail y [i]= %i\n", tailY[i]);
+ prevX = prev2X;
+ prevY = prev2Y;
}
+ /*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]);
+ }*/
}
+
+
+
void SnakeTail::draw(N5110 &lcd, int length) {
int _length = length;
- for(int j = 1; j < _length; j++) {
+ for(int j = 0; j < _length; j++) {
lcd.drawRect(tailX[j], tailY[j], 2, 2, FILL_BLACK);
}
}