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.
Ball/Ball.cpp
- Committer:
- JamesCummins
- Date:
- 2019-04-12
- Revision:
- 13:e5a36fbd48ae
- Parent:
- 11:2cf0d4ce8677
- Child:
- 14:108052b6222b
File content as of revision 13:e5a36fbd48ae:
#include "Ball.h" Ball::Ball() {} Ball::~Ball() {} void Ball::init(int radius){ _radius = radius; _x = 48; _y = 24; } void Ball::draw(N5110 &lcd){ int radius = get_radius(); lcd.drawCircle(_x, _y, radius, FILL_BLACK); } void Ball::update(FXOS8700CQ &accelerometer){ int RADIUS = get_radius(); Data values = accelerometer.get_values(); _velocity.x = -5*values.ay; _velocity.y = -5*values.ax; _x += _velocity.x; _y += _velocity.y; if (_x < RADIUS){ _x = RADIUS;} if (_x > 84 - RADIUS){ _x = 83 - RADIUS;} if (_y < RADIUS){ _y = RADIUS;} if (_y > 48 - RADIUS){ _y = 47 - RADIUS;} } Vector2D Ball::get_position(){ Vector2D pos = {_x, _y}; return pos; } Vector2D Ball::get_velocity(){ Vector2D vel = {_velocity.x, _velocity.y}; return vel; } int Ball::get_radius(){ int radius = _radius; return radius; } void Ball::set_velocity(Vector2D vel){ _velocity.x = vel.x; _velocity.y = vel.y; } void Ball::set_position(Vector2D pos){ _x = pos.x; _y = pos.y; } void Ball::set_radius(int radius){ _radius = radius; }