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
SnakeEngine/SnakeEngine.cpp
- Committer:
- JoeShotton
- Date:
- 2020-05-23
- Revision:
- 5:06fa7674622a
- Parent:
- 4:ea3fa51c4386
- Child:
- 6:6c9453397f4a
File content as of revision 5:06fa7674622a:
#include "SnakeEngine.h" SnakeEngine::SnakeEngine() { //constructor score = 0; } SnakeEngine::~SnakeEngine() { //destructor } /* 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)))) { // checks infront of head to see if pixel is set // due to the size of the head, there is an offset for the check for North and Eastward directions pad.led(1,0.9); return true; } else { pad.led(1,0.0); return = false; } } */ void SnakeEngine::init(FXOS8700CQ &mag){ _food.init(mag); //_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; } */ } }