ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Revision:
11:2041290b5a74
Parent:
10:e1d2289705ef
Child:
12:c5123abb4fbe
--- a/Floors/Floors.cpp	Wed Apr 17 15:19:58 2019 +0000
+++ b/Floors/Floors.cpp	Wed Apr 17 16:58:01 2019 +0000
@@ -5,13 +5,12 @@
 Floors::~Floors(){
 }
 
-void Floors::init(int x, int y, int width, int height){
+void Floors::init(int y, int width, int height){
     _height = height;
     _width = width;
-    
-    _pos.x = x;
+//  x-coordinate initially random: screen =84 (visible to 84-FLOORS_WIDTH): 0 left, 70 right
+    _pos.x = rand()% 74; 
     _pos.y = y;
-    
 }
 
 void Floors::draw(N5110 &lcd){
@@ -19,9 +18,15 @@
 }
 
 void Floors::update(Vector2D current_pos){
+// when they leave the screen they will re-appear in random x-coordinate so that 10 floors are always on screen
     _pos = current_pos;
-    // if they are below the y  bottom then they re-appear at top in a random place
-    
+    srand(time(0)); 
+    if (_pos.y > 48 ){ 
+    _pos.y = 0; 
+    _pos.x = rand()% 74; 
+    srand(time(0)); 
+    }
+    set_pos(_pos);
 }
 
 Vector2D Floors::get_pos(){
@@ -29,7 +34,6 @@
     return p;
 }
 
-
 void Floors::set_pos(Vector2D p){
     _pos.x = p.x;
     _pos.y = p.y;