Ahmed Hedait / Mbed 2 deprecated el16ah

Dependencies:   mbed

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