Fork of bouncing_ball by Stephen Licht

Revision:
5:dd8df17df666
Parent:
3:b3d6cd568c6c
Child:
6:1e5cd98fc2aa
--- a/bouncing_ball.cpp	Tue Nov 14 14:18:35 2017 +0000
+++ b/bouncing_ball.cpp	Tue Nov 14 14:57:59 2017 +0000
@@ -62,12 +62,22 @@
         _upside_down_status = 0;
 
         // Make circle bounce off of edges if at the edges:
-        if (( posx <= radius) || ((posx + radius) >= _width)) {
+        if (posx <= radius) {
+            speedx = -speedx;
+            posx = radius + BUFFER;
+            }
+        if ((posx + radius) >= _width) {
             speedx = -speedx;
-        }
-        if (( posy <= radius) || ((posy + radius) >= _height)) {
+            posx = posx + radius - BUFFER;
+            }
+        if (posy <= radius) {
             speedy = -speedy;
-        }
+            posy = radius + BUFFER;
+            }
+        if ((posy + radius) >= _height){
+            speedy = -speedy;
+            posy = posy + radius - BUFFER;
+            }
 
         //Accelerate per actual real world physics:
         speedx -= GRAVITY * accelerometer.readY(); //* time_step;