5

Dependents:   Labirint

Revision:
0:fe2b9c70f7b8
Child:
1:5285b567f4c9
diff -r 000000000000 -r fe2b9c70f7b8 Paddle.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Paddle.cpp	Wed Feb 08 19:51:11 2017 +0000
@@ -0,0 +1,61 @@
+#include "Paddle.h"
+
+Paddle::Paddle()
+{
+
+}
+
+Paddle::~Paddle()
+{
+
+}
+
+void Paddle::init(int x,int height,int width)
+{
+
+    _x = x;  // x value on screen is fixed
+    _y = HEIGHT/2 - height/2;  // y depends on height of screen and height of paddle
+    _height = height;
+    _width = width;
+    _speed = 1;  // default speed
+    _score = 0;
+
+}
+
+void Paddle::draw(N5110 &lcd)
+{
+
+    // draw paddle in screen buffer. 1 for filled rectangle
+    lcd.drawRect(_x,_y,_width,_height,1);
+}
+
+void Paddle::update(Direction d,float mag)
+{
+
+    _speed = int(mag*10.0f);  // scale is arbitrary, could be changed in future
+
+    // update y value depending on direction of movement
+    // North is decrement as origin is at the top-left so decreasing moves up
+    if (d == N) {
+        _y-=_speed;
+    } else if (d == S) {
+        _y+=_speed;
+    }
+
+    // check the y origin to ensure that the paddle doesn't go off screen
+    if (_y < 0) {
+        _y = 0;
+    }
+    if (_y > HEIGHT - _height) {
+        _y = HEIGHT - _height;
+    }
+}
+
+void Paddle::add_score()
+{
+    _score++;
+}
+int Paddle::get_score()
+{
+    return _score;
+}
\ No newline at end of file