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: SnakeEngine/SnakeEngine.cpp
- Revision:
- 4:ea3fa51c4386
- Parent:
- 3:fcd6d70e9694
- Child:
- 5:06fa7674622a
diff -r fcd6d70e9694 -r ea3fa51c4386 SnakeEngine/SnakeEngine.cpp --- a/SnakeEngine/SnakeEngine.cpp Wed May 20 21:25:40 2020 +0000 +++ b/SnakeEngine/SnakeEngine.cpp Sat May 23 15:31:30 2020 +0000 @@ -3,43 +3,13 @@ SnakeEngine::SnakeEngine() { //constructor + score = 0; } SnakeEngine::~SnakeEngine() { //destructor } - -void SnakeEngine::read_input(Gamepad &pad) -{ - //_d = pad.get_direction(); - //_mag = pad.get_mag(); -} - -/* -int Gamepad::get_cardinal() -{ - float angle = get_angle(); // 0 to 360, -1 for centred - - int d = 0; - // partition 360 into segments and check which segment the angle is in - if (angle < 0.0f) { - d = 0; // check for -1.0 angle - } else if (angle < 22.5f) { // then keep going in 45 degree increments - d = 1; - } else if (angle < 112.5f) { - d = 2; - } else if (angle < 202.5f) { - d = 3; - } else if (angle < 292.5f) { - d = 4; - } else { - d = 1; - } - - return d; -} -*/ /* bool collision(int state, int x, int y,) { if ((lcd.getPixel(x, y) == 1 && ((state == 1) || (state == 4))) || (lcd.getPixel(x+1, y+1) == 1 && ((state == 2) || (state == 3)))) { @@ -52,4 +22,47 @@ return = false; } } -*/ \ No newline at end of file +*/ +void SnakeEngine::init(){ + _food.init(); + //_food.rand_pos(_food._x, _food._y); +} + +void SnakeEngine::move_body(Gamepad &pad, N5110 &lcd, bool &death){ + _body.snake_movement(pad); + _body.draw_body(lcd); + //printf("Moving!"); + _food.do_food(lcd); + snake_food_collision(pad, _body._length); + if (_body._state > 0){ + _body.snake_snake_collision(pad, death); + } +} + +void SnakeEngine::snake_food_collision(Gamepad &pad, int &_length) { + if (_food._x == _body._x_head && _food._y == _body._y_head){ + //printf("FOOD!"); + _food.rand_pos(pad, _food._x, _food._y); + pad.led(3,0.9); + _length += 5; + score++; + + /* + for(int i = 1; i < _length; i++) { + if (_x_head == _body_x[i] && _y_head == _body_y[i]) { //checks if head coord is the same as any of the body coords + pad.led(1,0.9); + //printf("DEAD \n"); + _state = 0; + death = true; + //return true; + } else { + //pad.led(1,0.0); + //printf("ALIVE \n"); + //return false; + } + */ + + + } +} +