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: Snake/Snake.cpp
- Revision:
- 12:9f2f64016f56
- Parent:
- 11:e260c17a0489
- Child:
- 13:72bc2579e85e
--- a/Snake/Snake.cpp Fri Apr 06 15:15:50 2018 +0000
+++ b/Snake/Snake.cpp Mon Apr 09 10:16:58 2018 +0000
@@ -11,6 +11,16 @@
}
+Vector2D g_snake_position()
+{
+
+ extern Vector2D g_p;
+
+ return g_p;
+
+}
+
+
void Snake::init()
{
@@ -305,54 +315,61 @@
void Snake::set_snake_position(Direction next)
{
next = get_snake_direction();
- Vector2D p;
+ // Vector2D p;
+
+ extern Vector2D g_p;
+
+ // extern int g_x;
+ // extern int g_y;
switch(next) {
case(N):
- p.x = p.x;
- --p.y;
+ g_p.x = g_p.x;
+ --g_p.y;
break;
case(E):
- ++p.x;
- p.y = p.y;
+ ++g_p.x;
+ g_p.y = g_p.y;
break;
case(S):
- p.x = p.x;
- ++p.y;
+ g_p.x = g_p.x;
+ ++g_p.y;
break;
case(W):
- --p.x;
- p.y = p.y;
+ --g_p.x;
+ g_p.y = g_p.y;
break;
default:
- p.x = p.x;
- p.y = p.y;
+ g_p.x = g_p.x;
+ g_p.y = g_p.y;
break;
}
- _x = p.x;
- _y = p.y;
-
+
+ _x = g_p.x;
+ _y = g_p.y;
+
}
Vector2D Snake::get_snake_position()
{
+
Vector2D pos = {_x, _y};
return pos;