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: Doodler/Doodler.cpp
- Revision:
- 5:8814d6de77d0
- Parent:
- 4:8ec314f806ae
- Child:
- 6:848d1e4c1a31
--- a/Doodler/Doodler.cpp Thu Apr 11 14:44:14 2019 +0000 +++ b/Doodler/Doodler.cpp Sat Apr 13 17:37:52 2019 +0000 @@ -5,37 +5,38 @@ Doodler::~Doodler(){ } -void Doodler::init(int x, int y, int radius){ - _radius = radius; +void Doodler::init(int radius){ - _x = x; - _y = y; - - _velocity.x = 0; - _velocity.y = 0; +// initial position of doodler at middle + _x = (70/2)+6; // middle + _y = 43; // if doodler is above the middle, the screen shifts up (floors shift down) + _radius = radius; + _speed =0.5; // default speed } void Doodler::draw(N5110 &lcd){ lcd.drawCircle(_x, _y, _radius, FILL_BLACK); } - -void Doodler::set_velocity(Vector2D v){ - _velocity.x = v.x; - _velocity.y = v.y; +void Doodler::update(Direction d, float mag){ + _speed = int(mag*10.0f); + + if (d == W){ // if direction is left + _x-= _speed; + } else if (d == E){ + _x+= _speed; + } +// checking doodler does not leave screen: + if (_x > WIDTH-4){ + _x = WIDTH-4; + } + if (_x < _radius){ + _x = _radius; + } } -Vector2D Doodler::get_velocity(){ - Vector2D v = {_velocity.x,_velocity.y}; - return v; -} Vector2D Doodler::get_pos(){ Vector2D p = {_x,_y}; return p; } - -void Doodler::set_pos(Vector2D p){ - _x = p.x; - _y = p.y; -} \ No newline at end of file