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
Doodler/Doodler.cpp@4:8ec314f806ae, 2019-04-11 (annotated)
- Committer:
- el17m2h
- Date:
- Thu Apr 11 14:44:14 2019 +0000
- Revision:
- 4:8ec314f806ae
- Child:
- 5:8814d6de77d0
Added a doodler that will be controlled by the user using the joystick.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17m2h | 4:8ec314f806ae | 1 | #include "Doodler.h" |
el17m2h | 4:8ec314f806ae | 2 | |
el17m2h | 4:8ec314f806ae | 3 | Doodler::Doodler(){ |
el17m2h | 4:8ec314f806ae | 4 | } |
el17m2h | 4:8ec314f806ae | 5 | Doodler::~Doodler(){ |
el17m2h | 4:8ec314f806ae | 6 | } |
el17m2h | 4:8ec314f806ae | 7 | |
el17m2h | 4:8ec314f806ae | 8 | void Doodler::init(int x, int y, int radius){ |
el17m2h | 4:8ec314f806ae | 9 | _radius = radius; |
el17m2h | 4:8ec314f806ae | 10 | |
el17m2h | 4:8ec314f806ae | 11 | _x = x; |
el17m2h | 4:8ec314f806ae | 12 | _y = y; |
el17m2h | 4:8ec314f806ae | 13 | |
el17m2h | 4:8ec314f806ae | 14 | _velocity.x = 0; |
el17m2h | 4:8ec314f806ae | 15 | _velocity.y = 0; |
el17m2h | 4:8ec314f806ae | 16 | } |
el17m2h | 4:8ec314f806ae | 17 | |
el17m2h | 4:8ec314f806ae | 18 | void Doodler::draw(N5110 &lcd){ |
el17m2h | 4:8ec314f806ae | 19 | lcd.drawCircle(_x, _y, _radius, FILL_BLACK); |
el17m2h | 4:8ec314f806ae | 20 | } |
el17m2h | 4:8ec314f806ae | 21 | |
el17m2h | 4:8ec314f806ae | 22 | |
el17m2h | 4:8ec314f806ae | 23 | void Doodler::set_velocity(Vector2D v){ |
el17m2h | 4:8ec314f806ae | 24 | _velocity.x = v.x; |
el17m2h | 4:8ec314f806ae | 25 | _velocity.y = v.y; |
el17m2h | 4:8ec314f806ae | 26 | } |
el17m2h | 4:8ec314f806ae | 27 | |
el17m2h | 4:8ec314f806ae | 28 | Vector2D Doodler::get_velocity(){ |
el17m2h | 4:8ec314f806ae | 29 | Vector2D v = {_velocity.x,_velocity.y}; |
el17m2h | 4:8ec314f806ae | 30 | return v; |
el17m2h | 4:8ec314f806ae | 31 | } |
el17m2h | 4:8ec314f806ae | 32 | |
el17m2h | 4:8ec314f806ae | 33 | Vector2D Doodler::get_pos(){ |
el17m2h | 4:8ec314f806ae | 34 | Vector2D p = {_x,_y}; |
el17m2h | 4:8ec314f806ae | 35 | return p; |
el17m2h | 4:8ec314f806ae | 36 | } |
el17m2h | 4:8ec314f806ae | 37 | |
el17m2h | 4:8ec314f806ae | 38 | void Doodler::set_pos(Vector2D p){ |
el17m2h | 4:8ec314f806ae | 39 | _x = p.x; |
el17m2h | 4:8ec314f806ae | 40 | _y = p.y; |
el17m2h | 4:8ec314f806ae | 41 | } |