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
Food/Food.cpp
- Committer:
- JoeShotton
- Date:
- 2020-05-23
- Revision:
- 6:6c9453397f4a
- Parent:
- 5:06fa7674622a
- Child:
- 7:dd84e0fab346
File content as of revision 6:6c9453397f4a:
#include "Food.h"
Food::Food()
{
//constructor
_x = 22; // starts off-screen
_y = 30;
_frame = 0;
}
Food::~Food()
{
//deconstructor
}
void Food::init(FXOS8700CQ &mag)
{
mag.init();
Data _values = mag.get_values();
_seed = 1000000*(_values.mx + _values.my + _values.mz);
srand(_seed);
}
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);
}
void Food::draw(N5110 &lcd, int &_frame) {
// 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::do_food(N5110 &lcd)
{
draw(lcd, _frame);
}