ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18jgb

Dependencies:   mbed

Revision:
18:c600a6545e81
Parent:
13:cfdfe60a2327
Child:
19:33c77517cb88
--- a/Aim/Aim.cpp	Tue May 19 16:55:43 2020 +0000
+++ b/Aim/Aim.cpp	Wed May 20 14:37:02 2020 +0000
@@ -28,9 +28,7 @@
 {
 
 }
-
-
-    
+ 
 
 void Aim::init()
 {
@@ -102,6 +100,31 @@
     }
 }
 
+void Aim::acc_control(FXOS8700CQ &acc)
+{
+    float roll = acc.get_roll_angle();
+    _x = _x + roll;
+    //printf("roll =  %f\n", roll);
+    float pitch = acc.get_pitch_angle();
+    _y = _y - pitch;
+    //printf("pitch =  %f\n", pitch);
+    
+    // check the x origin to ensure that the paddle doesn't go off screen
+    if (_x < 1) {
+        _x = 1;
+    }
+    if (_x > 84 - _width - 1) {
+        _x = 84 - _width - 1;
+    }
+    // check the y origin to ensure that the sprite doesn't go off screen
+    if (_y < 1) {
+        _y = 1;
+    }
+    if (_y > 48 - _height - 1) {
+        _y = 48 - _height - 1;
+    }
+}
+
 Vector2D Aim::get_pos() {
     Vector2D p = {(_x+2),(_y+2)};
     return p;