Kaitlyn Barros / physics_ball

Dependents:   Barros_Assignment4

Revision:
0:9591bae8d04c
Child:
1:a2dda7baafaa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/physics_ball.cpp	Tue Oct 31 12:59:49 2017 +0000
@@ -0,0 +1,58 @@
+#include "physics_ball.h"
+
+//Constructor
+physics_ball::physics_ball(){
+    posx = 0;
+    posy = 0;
+    
+    speedx = 25;
+    speedy = 25;
+    
+    radius = 10;
+    color = 1;
+    
+    width = 128;
+    height = 128;
+    }
+    
+void physics_ball::set_param(int radius_in, int color_in)
+ {
+    radius = radius_in; 
+    color = color_in;
+    }   
+
+void physics_ball::define_space( int width_in, int height_in)
+{
+    width = width_in;
+    height = height_in;
+    }
+
+void physics_ball::set_state(int x_in, int y_in, float speedx_in, float speedy_in)
+{
+    posx = x_in;
+    posy = y_in;
+    
+    speedx = speedx_in;
+    speedy = speedy_in;
+    }
+    
+void physics_ball::update( float time_step_in , int posx, int posy, int speedx, int speedy, MMA8452Q & accel)
+{
+    time_step = time_step_in;
+  
+        posx = posx - (speedx * accel.readY());
+        posy = posy - (speedy * accel.readX());
+        
+        //Ball 1 Physics 
+        if ((posx <= radius) || (posx >= 128-radius)){
+        speedx = -1 * speedx;
+         }
+        if ((radius < posx) && (posx < 128- radius)){
+             speedx = speedx;
+             }
+        if ((posy <= radius) || (posy >= 128-radius)) {
+         speedy = -1 * speedy;
+        }       
+              }
+              
+              
\ No newline at end of file