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.
Diff: Ball/Ball.cpp
- Revision:
- 13:e5a36fbd48ae
- Parent:
- 11:2cf0d4ce8677
- Child:
- 14:108052b6222b
diff -r 9982239b7906 -r e5a36fbd48ae Ball/Ball.cpp
--- a/Ball/Ball.cpp Thu Apr 11 21:42:03 2019 +0000
+++ b/Ball/Ball.cpp Fri Apr 12 17:01:47 2019 +0000
@@ -12,20 +12,22 @@
_y = 24;
}
-void Ball::draw (N5110 &lcd){
- lcd.drawCircle(_x, _y, 4, FILL_BLACK);
+void Ball::draw(N5110 &lcd){
+ int radius = get_radius();
+ lcd.drawCircle(_x, _y, radius, FILL_BLACK);
}
void Ball::update(FXOS8700CQ &accelerometer){
- Data acc_values = accelerometer.get_values();
- _accel.x = acc_values.ax;
- _accel.y = acc_values.ay;
-
- _velocity.x += _accel.x;
- _velocity.y += _accel.y;
-
+ 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(){
@@ -38,11 +40,6 @@
return vel;
}
-Vector2D Ball::get_accel(){
- Vector2D accel = {_accel.x, _accel.y};
- return accel;
-}
-
int Ball::get_radius(){
int radius = _radius;
return radius;