Dependencies: mbed
Diff: SnakeHead/SnakeHead.cpp
- Revision:
- 14:4356797fd16e
- Parent:
- 12:cb3a81adf48b
--- a/SnakeHead/SnakeHead.cpp Sun May 24 15:08:31 2020 +0000 +++ b/SnakeHead/SnakeHead.cpp Sun May 24 15:27:53 2020 +0000 @@ -12,15 +12,16 @@ } void SnakeHead::init(int size, int speed) { + //initialises head size and speed _size = size*2; _speed = speed; - + //head starts in centre of screen _x = WIDTH/2 - _size/2; _y = HEIGHT/2 - _size/2; - + //generates random number between 0 and 3 srand(time(NULL)); int direction = rand() %3; - + //sets initial direction of snake from the random number generated if (direction == 0) { //snake moves north _velocity.x = -_speed; _velocity.y = 0; @@ -40,6 +41,7 @@ } void SnakeHead::draw(N5110 &lcd) { + lcd.drawRect(_x,_y,_size,2,FILL_BLACK); } @@ -47,7 +49,7 @@ _x += _velocity.x; _y += _velocity.y; - + /* wall collision debugging if (_x < 0) { _x = 1; } else if (_x > 84) { @@ -56,13 +58,13 @@ _y = 1; } else if (_y > 48) { _y = 48 - _size; - } + } */ //printf("head x = %i\n", _x); //printf("head y = %i\n", _y); } void SnakeHead::change_direction(Direction d) { - + //changes direction of the head based on the direction of the joystick if (d == N) { _velocity.x = 0; _velocity.y = -_speed;