Similar to the example code.

Dependencies:   mbed N5110

Revision:
0:97418ec4c37d
Child:
1:85ab0d979b57
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Cylinder/Cylinder.cpp	Tue Apr 23 16:04:18 2019 +0000
@@ -0,0 +1,127 @@
+#include "Cylinder.h"
+
+void Cylinder::init()
+{
+    _x1 = 72;
+    _x2 = 102;
+    _x3 = 132;
+    _height1 = rand()%11+10;
+    _height2 = rand()%11+10;
+    _height3 = rand()%11+10;
+    _gap1 = rand()%11+15;
+    _gap2 = rand()%11+15;
+    _gap3 = rand()%11+15;
+    _score = 0;
+
+}
+
+void Cylinder::draw(N5110 &lcd)
+{
+    lcd.drawRect(0,0,84,48,FILL_TRANSPARENT);
+    lcd.drawRect(64,0,20,20,FILL_TRANSPARENT);
+    if(_x1 > 60 ) {
+         _a = 1;
+         _b = _height2;
+         _c = _height3;
+    } else if (_x2 > 60) {
+         _a = _height1;
+         _b = 1;
+        _c = _height3;
+    } else if (_x3 > 60) {
+        _a = _height1;
+        _b = _height2;
+        _c = 1;
+    } else {
+        _a = _height1;
+        _b = _height2;
+        _c = _height3;
+    }
+
+
+    lcd.drawRect(_x1,0,4,_a,FILL_BLACK);
+    lcd.drawRect(_x1,_height1+_gap1,4,49-_height1-_gap1,FILL_BLACK);
+    lcd.drawRect(_x2,0,4,_b,FILL_BLACK);
+    lcd.drawRect(_x2, _height2+_gap2,4,49-_height2-_gap2,FILL_BLACK);
+    lcd.drawRect(_x3,0,4,_c,FILL_BLACK);
+    lcd.drawRect(_x3, _height3+_gap3, 4, 49-_height3-_gap3, FILL_BLACK);
+
+}
+
+void Cylinder::update()
+{
+    _x1 -= 3;
+    _x2 -= 3;
+    _x3 -= 3;
+
+}
+
+void Cylinder::check()
+{
+    if(_x1 < 0) {
+        _x1 = 86;
+        _height1 = rand()%11+10;
+        _gap1 = rand()%11+15;
+        _score += 1;
+    }
+    if(_x2 < 0) {
+        _x2 = 86;
+        _height2 = rand()%11+10;
+        _gap2 = rand()%11+15;
+        _score += 1;
+    }
+    if(_x3 < 0) {
+        _x3 = 86;
+        _height3 = rand()%11+10;
+        _gap3 = rand()%11+15;
+        _score += 1;
+    }
+}
+
+void Cylinder::print_score(N5110 &lcd)
+{
+    _yourscore = _score;
+    char buffer[1];
+    int score = _yourscore;
+    sprintf(buffer, "%2d", score);
+    lcd.printString(buffer, 64,1);
+
+}
+
+void Cylinder::print_yourscore(N5110 &lcd)
+{
+    char buffer2[14];
+    int yourscore = _yourscore;
+    sprintf(buffer2,"YourScore = %2d ",yourscore);
+    lcd.printString(buffer2,0,1);
+}
+
+int Cylinder::get_highest_score(int high_score)
+{
+    if (high_score <= _yourscore) {
+        high_score = _yourscore;
+    }
+    return high_score;
+}
+
+
+Data Cylinder::get_data()
+{
+    _data.x1 = _x1;
+    _data.x2 = _x2;
+    _data.x3 = _x3;
+
+    _data.height1 = _height1;
+    _data.height2 = _height2;
+    _data.height3 = _height3;
+
+    _data.gap1 = _gap1;
+    _data.gap2 = _gap2;
+    _data.gap3 = _gap3;
+
+    return _data;
+
+}
+
+
+
+