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
Diff: Head/Head.cpp
- Revision:
- 5:e0f08e8022de
- Parent:
- 4:748b3e0062f6
- Child:
- 6:266fb8fc17f4
--- a/Head/Head.cpp Wed May 27 20:57:21 2020 +0000 +++ b/Head/Head.cpp Thu May 28 16:29:55 2020 +0000 @@ -21,7 +21,7 @@ _x = WIDTH/2 - _length/2; // snake spawns in random position _y = HEIGHT/2 - _length/2; // set the direction of snake to north - + } void Head::draw(N5110 &lcd) { @@ -29,10 +29,12 @@ } -void Head::update(Direction d, float mag) -{ +void Head::update(enum Direction d, float mag) +{ + // update y value depending on direction of movement // North is decrement as origin is at the top-left so decreasing moves up + _speed = int(mag*10.0f); if (d == N && d != S){ _y -= _speed; @@ -51,23 +53,7 @@ _x += _speed; } - switch(d){ - case S: - _y; - break; - case N: - _y = 1; - break; - - case W: - _x = 1; - break; - - case E: - _x = 1; - break; - } } // The head changes to the new position @@ -77,4 +63,4 @@ Vector2D Head::get_pos() { Vector2D pos = {_x,_y}; return pos; -} \ No newline at end of file +}