Joe Shotton / Mbed 2 deprecated ELEC2645_Project_ll16j23s

Dependencies:   mbed ll16j23s_test_docs

Committer:
JoeShotton
Date:
Sun May 24 22:18:55 2020 +0000
Revision:
7:dd84e0fab346
Parent:
6:6c9453397f4a
Child:
8:bcc3403d7e79
Menu system functions implemented, although not fully working together. Map draw functions finished

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JoeShotton 3:fcd6d70e9694 1 #include "Food.h"
JoeShotton 3:fcd6d70e9694 2
JoeShotton 3:fcd6d70e9694 3 Food::Food()
JoeShotton 3:fcd6d70e9694 4 {
JoeShotton 3:fcd6d70e9694 5 //constructor
JoeShotton 5:06fa7674622a 6 _x = 22; // starts off-screen
JoeShotton 4:ea3fa51c4386 7 _y = 30;
JoeShotton 4:ea3fa51c4386 8 _frame = 0;
JoeShotton 3:fcd6d70e9694 9 }
JoeShotton 3:fcd6d70e9694 10
JoeShotton 3:fcd6d70e9694 11 Food::~Food()
JoeShotton 3:fcd6d70e9694 12 {
JoeShotton 3:fcd6d70e9694 13 //deconstructor
JoeShotton 3:fcd6d70e9694 14 }
JoeShotton 3:fcd6d70e9694 15
JoeShotton 7:dd84e0fab346 16 void Food::init(FXOS8700CQ &mag) {
JoeShotton 7:dd84e0fab346 17
JoeShotton 5:06fa7674622a 18 mag.init();
JoeShotton 5:06fa7674622a 19 Data _values = mag.get_values();
JoeShotton 6:6c9453397f4a 20 _seed = 1000000*(_values.mx + _values.my + _values.mz);
JoeShotton 5:06fa7674622a 21 srand(_seed);
JoeShotton 4:ea3fa51c4386 22 }
JoeShotton 4:ea3fa51c4386 23
JoeShotton 4:ea3fa51c4386 24
JoeShotton 7:dd84e0fab346 25 void Food::rand_pos(Gamepad &pad) {
JoeShotton 4:ea3fa51c4386 26
JoeShotton 4:ea3fa51c4386 27 _x = 2 * (rand() % 42); //selects random x cell
JoeShotton 4:ea3fa51c4386 28 //printf("Food x: %d\n", _x);
JoeShotton 4:ea3fa51c4386 29 _y = 2 * (rand() % 24); //selects random y call
JoeShotton 4:ea3fa51c4386 30 //printf("Food y: %d\n", _y);
JoeShotton 4:ea3fa51c4386 31
JoeShotton 7:dd84e0fab346 32 pad.led(3,0.1);
JoeShotton 4:ea3fa51c4386 33
JoeShotton 3:fcd6d70e9694 34 }
JoeShotton 3:fcd6d70e9694 35
JoeShotton 3:fcd6d70e9694 36
JoeShotton 4:ea3fa51c4386 37 void Food::draw(N5110 &lcd, int &_frame) {
JoeShotton 3:fcd6d70e9694 38
JoeShotton 4:ea3fa51c4386 39 // draw food, with alternating pixels depending on frame.
JoeShotton 4:ea3fa51c4386 40 _frame++;
JoeShotton 4:ea3fa51c4386 41 if (_frame > 12) {
JoeShotton 4:ea3fa51c4386 42 _frame = 0;
JoeShotton 4:ea3fa51c4386 43 }
JoeShotton 4:ea3fa51c4386 44 if (_frame > 6) {
JoeShotton 4:ea3fa51c4386 45 lcd.drawLine(_x, _y, _x + 1,_y + 1,1);
JoeShotton 4:ea3fa51c4386 46 } else {
JoeShotton 4:ea3fa51c4386 47 lcd.drawLine(_x + 1, _y, _x,_y + 1,1);
JoeShotton 4:ea3fa51c4386 48 }
JoeShotton 3:fcd6d70e9694 49 }
JoeShotton 3:fcd6d70e9694 50
JoeShotton 4:ea3fa51c4386 51 void Food::do_food(N5110 &lcd)
JoeShotton 3:fcd6d70e9694 52 {
JoeShotton 4:ea3fa51c4386 53 draw(lcd, _frame);
JoeShotton 3:fcd6d70e9694 54 }
JoeShotton 4:ea3fa51c4386 55