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: Paddle/Paddle.cpp
- Revision:
- 16:1761dfe801af
- Parent:
- 15:b867a6620f96
- Child:
- 18:e5eb50c5e61f
--- a/Paddle/Paddle.cpp Tue Apr 23 17:09:47 2019 +0000
+++ b/Paddle/Paddle.cpp Tue Apr 23 17:51:42 2019 +0000
@@ -22,7 +22,7 @@
_speed = 1; // default speed
_score = 0; // start score from zero
_lives = 6;
- //_tilt? = false; use to choose between motion methods
+ _tilt = false; //use to choose between motion methods
}
@@ -34,34 +34,35 @@
void Paddle::update(Direction d,float mag)
{
-// //if (_tilt == false) {
-// _speed = int(mag*10.0f); // scale is arbitrary, could be changed in future
-
-// // update y value depending on direction of movement
-// // North is decrement as origin is at the top-left so decreasing moves up
-// if (d == W) {
-// _x-=_speed;
-// } else if (d == E) {
-// _x+=_speed;
-// }
-
-// // check the y origin to ensure that the paddle doesn't go off screen
-// if (_x < 1) {
-// _x = 1;
-// }
-// if (_x > WIDTH - _width - 1) {
-// _x = WIDTH - _width - 1;
-// }
+ if (_tilt == false) {
+ _speed = int(mag*10.0f); // scale is arbitrary, could be changed in future
+
+ // update y value depending on direction of movement
+ // North is decrement as origin is at the top-left so decreasing moves up
+ if (d == W) {
+ _x-=_speed;
+ } else if (d == E) {
+ _x+=_speed;
+ }
- //else if (_tilt =+ true) {
+ // check the y origin to ensure that the paddle doesn't go off screen
+ if (_x < 1) {
+ _x = 1;
+ }
+ if (_x > WIDTH - _width - 1) {
+ _x = WIDTH - _width - 1;
+ }
+ }
+ else if (_tilt == true) {
- Data values = acc.get_values();
- float roll_rad = atan2(values.ay,values.az);
- _speed = int((roll_rad*(360/3.14159265))*0.3f); // scale is arbitrary, could be changed in future
-
- // update y value depending on direction of movement
- // North is decrement as origin is at the top-left so decreasing moves up
- _x -= _speed;
+ Data values = acc.get_values();
+ float roll_rad = atan2(values.ay,values.az);
+ _speed = int((roll_rad*(360/3.14159265))*0.3f); // scale is arbitrary, could be changed in future
+
+ // update y value depending on direction of movement
+ // North is decrement as origin is at the top-left so decreasing moves up
+ _x -= _speed;
+ }
// check the y origin to ensure that the paddle doesn't go off screen
if (_x < 1) {
@@ -94,4 +95,14 @@
Vector2D Paddle::get_pos() {
Vector2D p = {_x,_y};
return p;
-}
\ No newline at end of file
+}
+
+void Paddle::set_tilt()
+{
+ _tilt = true;
+}
+
+void Paddle::set_joy()
+{
+ _tilt = false;
+}