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 ll16j23s_test_docs
Diff: Food/Food.cpp
- Revision:
- 4:ea3fa51c4386
- Parent:
- 3:fcd6d70e9694
- Child:
- 5:06fa7674622a
diff -r fcd6d70e9694 -r ea3fa51c4386 Food/Food.cpp
--- a/Food/Food.cpp Wed May 20 21:25:40 2020 +0000
+++ b/Food/Food.cpp Sat May 23 15:31:30 2020 +0000
@@ -3,6 +3,10 @@
Food::Food()
{
//constructor
+ _x = 42; // starts off-screen
+ _y = 30;
+ _frame = 0;
+ srand(3); //CHANGE THIS TO ACCELERAOMETRE VALUE
}
Food::~Food()
@@ -12,25 +16,38 @@
void Food::init()
{
- _x = 84; // starts off-screen
- _y = 0;
- //srand (x); //CHANGE THIS TO ACCELERAOMETRE VALUE
+ //rand_pos(pad, _x, _y);
+}
+
+
+void Food::rand_pos(Gamepad &pad, int &_x, int &_y) {
+
+ _x = 2 * (rand() % 42); //selects random x cell
+ //printf("Food x: %d\n", _x);
+ _y = 2 * (rand() % 24); //selects random y call
+ //printf("Food y: %d\n", _y);
+
+ pad.led(3,1);
+
}
-Vector2D Food::rand_pos(int cell_size) {
+void Food::draw(N5110 &lcd, int &_frame) {
- int _x = cell_size * (rand() % 42); //selects random x cell
- printf("Food x: %d\n", _x);
- int _y = cell_size * (rand() % 24); //selects random y call
- printf("Food y: %d\n", _y);
- Vector2D pos = {_x,_y};
- return pos;
+ // draw food, with alternating pixels depending on frame.
+ _frame++;
+ if (_frame > 12) {
+ _frame = 0;
+ }
+ if (_frame > 6) {
+ lcd.drawLine(_x, _y, _x + 1,_y + 1,1);
+ } else {
+ lcd.drawLine(_x + 1, _y, _x,_y + 1,1);
+ }
}
-
-void Food::draw(N5110 &lcd, int frame)
+void Food::do_food(N5110 &lcd)
{
- // draw food, with alternate locations depending on frame.
- lcd.drawLine(_x + frame, _y, _x + 1 - frame,_y + 1,1);
+ draw(lcd, _frame);
}
+