testing documentation
Dependencies: mbed ll16j23s_test_docs
Diff: Food/Food.cpp
- Revision:
- 10:a2d643b3c782
- Parent:
- 9:0571880085cc
--- a/Food/Food.cpp Mon May 25 20:31:52 2020 +0000 +++ b/Food/Food.cpp Tue May 26 23:25:09 2020 +0000 @@ -13,12 +13,16 @@ //deconstructor } -void Food::init(FXOS8700CQ &mag) { +void Food::init(Gamepad &pad, N5110 &lcd, FXOS8700CQ &mag) { mag.init(); Data _values = mag.get_values(); - _seed = 1000000*(_values.mx + _values.my + _values.mz); + _seed = 1000000*(_values.mx + _values.my + _values.mz); //seed generated from combination of accelerometre values so any can change for seed to change srand(_seed); + while (rand_pos(pad, lcd) == false){ //while new food coordinates are in the snake/walls + rand_pos(pad, lcd); //choose new coords by rerunning the function + printf("Reselected food position\n"); + } } @@ -29,7 +33,7 @@ //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) + if (lcd.getPixel(_x,_y)) { //checks if selected pixel is already black (ie body or walls at this location) return false; } else { return true;