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:
- kocemax
- Date:
- 2019-03-20
- Revision:
- 2:006a2ddfabb6
- Child:
- 3:fe856d0890ee
File content as of revision 2:006a2ddfabb6:
#include "Ball.h" #include "PlayerControl.h" // Constructor Ball::Ball() { _xBall = WIDTH/2; // draw ball in the middle of the columns initially _yBall = HEIGHT - GAP - 2; // draw ball close to the bottom of the LCD _counterx = 1; _countery = 1; } // Destructor Ball::~Ball() { } void Ball::drawBall(N5110 &lcd) { lcd.drawRect(_xBall,_yBall,2,2,FILL_BLACK); } void Ball::moveBall() { _xBall += _counterx; _yBall -= _countery; if (_xBall > 82) { _counterx = -1; } else if( _xBall < 1) { _counterx = 1; } if (_yBall < 1) { _countery = -1; } else if (_yBall > 46) { _countery = 1; } } Vector2D Ball::get_ballPos(Gamepad &pad) { Vector2D posBall = {_xBall,_yBall}; return posBall; } bool Ball::endCondition(Gamepad &pad) { PlayerControl pl; Vector2D posBall = get_ballPos(pad); Vector2D posPad = pl.get_padPos(pad); if (posBall.y < posPad.y) { return true; } else return false; }