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.
Dependencies: mbed
Diff: Ball/Ball.cpp
- Revision:
- 4:08a0ff6668df
- Parent:
- 3:f86c1cf90d0d
- Child:
- 5:ed71996c0534
diff -r f86c1cf90d0d -r 08a0ff6668df Ball/Ball.cpp --- 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