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.
Diff: Ball/Ball.cpp
- Revision:
- 20:041affa5e242
- Parent:
- 17:68d4b4095d80
- Child:
- 21:bcc84d5cb068
--- a/Ball/Ball.cpp Tue May 08 11:32:13 2018 +0000 +++ b/Ball/Ball.cpp Tue May 08 11:57:19 2018 +0000 @@ -9,4 +9,47 @@ Ball::~Ball() { +} + +void Ball::init() +{ + _circy = 5; + _circx = 5; + _speed = 1; + +} + +void Ball::draw(N5110 &lcd) +{ + // VERY SIMPLE CODE IN WHCIH I DREW THE BALL OF THE MAZE. + lcd.drawCircle(_circx,_circy,2,FILL_BLACK); +} + +void Ball::update(Direction dir) +{ + if (dir == N) { + _circy -= _speed; + } else if (dir == S) { + _circy += _speed; + } + + if (dir == W) { + _circx -= _speed; + } else if (dir == E) { + _circx += _speed; + } + + // THIS CODE IS NEEDED TO MAKE SURE THAT THE BALL DOES NOT OFF THE DIMENSIONS OF THE LCD SCREEN. + if (_circy < 3) { + _circy = 3; + } + + if (_circy > HEIGHT - 4) { + _circy = HEIGHT - 4; + } + + if (_circx < 3) { + _circx = 3; + } + } \ No newline at end of file