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
Head/Head.cpp
- Committer:
- el18lg
- Date:
- 2020-05-27
- Revision:
- 3:beb0cc405b1e
- Child:
- 4:748b3e0062f6
File content as of revision 3:beb0cc405b1e:
#include "Head.h" // nothing doing in the constructor and destructor Head::Head() { } Head::~Head() { } void Head::init(int length, int speed) { _length = length; _speed = speed; srand(time(NULL)); _x = WIDTH/2 - _length/2; // snake spawns in random position _y = HEIGHT/2 - _length/2; int direction = N; // set the direction of snake to north } void Head::draw(N5110 &lcd) { lcd.drawCircle(_x,_y,_length,FILL_BLACK); } void Head::update(Direction d) { // update y value depending on direction of movement // North is decrement as origin is at the top-left so decreasing moves up if (pad.X_pressed()){ d == N; } if (pad.B_pressed()){ d == S; } if (pad.Y_pressed()){ d == W; } if (pad.A_pressed()){ d == E; } } // The head changes to the new position Vector2D Head::get_pos() { Vector2D pos = {_x,_y}; return pos; }