Kostadin Chakarov / Mbed 2 deprecated el17kec

Dependencies:   mbed

Revision:
2:006a2ddfabb6
Child:
3:fe856d0890ee
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Ball/Ball.cpp	Wed Mar 20 20:58:36 2019 +0000
@@ -0,0 +1,65 @@
+#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;
+}
\ No newline at end of file