testing documentation
Dependencies: mbed ll16j23s_test_docs
Food/Food.cpp
- Committer:
- JoeShotton
- Date:
- 2020-05-25
- Revision:
- 9:0571880085cc
- Parent:
- 8:bcc3403d7e79
- Child:
- 10:a2d643b3c782
File content as of revision 9:0571880085cc:
#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); } bool Food::rand_pos(Gamepad &pad, N5110 &lcd) { wait_ms(10); pad.led(3,0.1); _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); if (lcd.getPixel(_x,_y)) { //checks if selected pixel is already on (ie body or walls at this location) return false; } else { return true; } } void Food::draw(N5110 &lcd, int &_frame) { // draw food, with alternating pixels depending on frame. _frame++; _frame = _frame % 12; if (_frame > 6) { lcd.drawLine(_x, _y, _x + 1,_y + 1,1); } else { lcd.drawLine(_x + 1, _y, _x,_y + 1,1); } } void Food::run(N5110 &lcd) { draw(lcd, _frame); }