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.
Ball/Ball.cpp
- Committer:
- ahmedhedait
- Date:
- 2018-05-08
- Revision:
- 20:041affa5e242
- Parent:
- 17:68d4b4095d80
- Child:
- 21:bcc84d5cb068
File content as of revision 20:041affa5e242:
#include "Ball.h"
// nothing doing in the constructor and destructor
Ball::Ball()
{
}
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;
}
}