runner

Dependencies:   mbed

Revision:
4:7fca66882a00
Parent:
3:59e67155e2dd
Child:
8:5fde4e54a2f4
--- a/Obstacle/Obstacle.cpp	Thu May 09 05:01:02 2019 +0000
+++ b/Obstacle/Obstacle.cpp	Thu May 09 06:17:43 2019 +0000
@@ -13,11 +13,11 @@
 
 void Obstacle::init(int y,int height,int width)
 {
-    _x = WIDTH - 5;  // x value on screen is fixed
+    _x = WIDTH;  // x value on screen is fixed
     _y = y;
     _height = height;
     _width = width;
-
+    _speed = 0;
 }
 
 void Obstacle::draw(N5110 &lcd)
@@ -25,14 +25,21 @@
     lcd.drawRect(_x,_y,_width,_height,FILL_BLACK);
 }
 
-void Obstacle::update()
+void Obstacle::update(bool ran)
 {
-    _speed = 3;
-    _x -= _speed;
-    // check the x origin to ensure that the obstacle doesn't go beyond screen
-    if (_x < 0) {
-        _x = 1;
+    if (
+        (ran == 1) &&
+        (_speed == 0)
+    ) {
+        _speed = 3;
+        _x = WIDTH;
+    } else if (
+        (_x < -1)
+    ) {
+        _x = WIDTH;
+        _speed = 0;
     }
+     _x -= _speed;
 }