ELEC2645 (2018/19) / Mbed 2 deprecated el17kz

Dependencies:   mbed

Revision:
2:1900a4144537
Child:
3:59e67155e2dd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Runner/Runner.cpp	Thu May 09 03:52:35 2019 +0000
@@ -0,0 +1,61 @@
+#include "Runner.h"
+
+// nothing doing in the constructor and destructor
+Runner::Runner()
+{
+
+}
+
+Runner::~Runner()
+{
+
+}
+
+void Runner::init(int x,int height,int width)
+{
+    _x = x;  // x value on screen is fixed
+    _y = FLOOR - height;
+    _height = height;
+    _width = width;
+    _score = 0;  // start score from zero
+
+}
+
+void Runner::draw(N5110 &lcd)
+{
+    // draw paddle in screen buffer. 
+    lcd.drawRect(_x,_y,_width,_height,FILL_BLACK);
+}
+
+void Runner::update(Direction d,float mag)
+{
+    if ( 
+        (d == N) &&
+        (_y == FLOOR - _height)
+        ) {
+        _speed = -2;
+    } else if (
+        (_y < FLOOR - 24)
+        ) {
+        _speed = 2;
+    } 
+    _y += _speed;
+    // check the y origin to ensure that the runner doesn't go under floor
+    if (_y + _height + 1 > FLOOR) {
+        _y = FLOOR - _height;
+    }
+}
+
+void Runner::add_score()
+{
+    _score++;
+}
+int Runner::get_score()
+{
+    return _score;
+}
+
+Vector2D Runner::get_pos() {
+    Vector2D p = {_x,_y};
+    return p;    
+}
\ No newline at end of file