ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_PROJECT_EL18KK

Dependencies:   mbed

Revision:
4:08a0ff6668df
Parent:
3:f86c1cf90d0d
Child:
5:ed71996c0534
--- a/Ball/Ball.cpp	Mon Apr 27 21:58:35 2020 +0000
+++ b/Ball/Ball.cpp	Sat May 16 13:10:01 2020 +0000
@@ -38,6 +38,7 @@
     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},
 };
 
+
 Ball::Ball() {
     
     }
@@ -77,4 +78,32 @@
                 
                 lcd.refresh();                
             }
+    }
+void Ball::bounceBall(int x_pos, int y_pos, int height, int status, N5110 &lcd){
+        _user_input_x = x_pos;
+        _user_input_y = y_pos;
+        _height = height;
+        _status = status;
+        int dir =-2;
+        if(_status){
+            lcd.drawSprite(_user_input_x, _user_input_y,11,15,(int *)ball[0]);
+            if(_user_input_y <= (y_pos - _height)) {
+                    dir = 3; //falls faster than rises up
+                }
+            else if(_user_input_y >= (y_pos)) {
+                    dir = -2;
+                }
+            _user_input_y+= dir;
+            wait(0.1);
+            lcd.refresh();
+            //clears background only in the area the ball is moving
+            lcd.drawRect(_user_input_x,(48-y_pos),13,(y_pos + _height),FILL_WHITE);
+        }
+    }
+void Ball::set_status(bool status) {
+        _status = status;
+    }
+int Ball::get_status() {
+        int val = _status;
+        return val;
     }
\ No newline at end of file