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: Body/Body.cpp
- Revision:
- 5:e0f08e8022de
- Parent:
- 4:748b3e0062f6
- Child:
- 8:59b01b57f0da
diff -r 748b3e0062f6 -r e0f08e8022de Body/Body.cpp
--- 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