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:
- 13:72bc2579e85e
- Parent:
- 12:9f2f64016f56
- Child:
- 14:c3a435597196
--- a/Snake/Snake.cpp Mon Apr 09 10:16:58 2018 +0000
+++ b/Snake/Snake.cpp Wed Apr 11 11:42:16 2018 +0000
@@ -20,14 +20,23 @@
}
-
-void Snake::init()
+Direction g_current_direction()
{
- _x = 41;
- _y = 23;
+ extern Direction g_d;
+
+ return g_d;
- _next = W;
+}
+
+
+void Snake::init(Direction direction, int pos_x, int pos_y)
+{
+
+ _pos.x = pos_x;
+ _pos.y = pos_y;
+
+ _current = direction;
}
@@ -36,17 +45,17 @@
set_snake_direction(in, cur);
Direction next = get_snake_direction();
- //set_current_direction(next);
+ set_current_direction();
cur = get_current_direction();
set_snake_position(next);
- Vector2D pos = get_snake_position();
+ Vector2D _pos = get_snake_position();
}
void Snake::draw(N5110 &lcd)
{
- lcd.setPixel(_x, _y, true);
+ lcd.setPixel(_pos.x,_pos.y,true);
}
@@ -299,15 +308,22 @@
return d;
}
-/*
-void Snake::set_current_direction(Direction new_cur)
+void Snake::set_current_direction()
{
- _next = new_cur;
-}*/
+
+ extern Direction g_d;
+
+ g_d = get_snake_direction();
+
+ _current = g_d;
+
+
+}
+
Direction Snake::get_current_direction()
{
- Direction d = _next;
+ Direction d = _current;
return d;
}
@@ -327,7 +343,7 @@
case(N):
g_p.x = g_p.x;
- --g_p.y;
+ ++g_p.y;
break;
@@ -341,7 +357,7 @@
case(S):
g_p.x = g_p.x;
- ++g_p.y;
+ --g_p.y;
break;
@@ -362,15 +378,15 @@
}
- _x = g_p.x;
- _y = g_p.y;
+ _pos.x = g_p.x;
+ _pos.y = g_p.y;
}
Vector2D Snake::get_snake_position()
{
- Vector2D pos = {_x, _y};
+ Vector2D pos = _pos;
return pos;
}