ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Revision:
20:a359092079b0
Parent:
19:5a7b0cdf013b
Child:
21:6b16ca9834e6
--- a/Floors/Floors.cpp	Thu Apr 25 08:43:46 2019 +0000
+++ b/Floors/Floors.cpp	Thu Apr 25 11:34:01 2019 +0000
@@ -7,8 +7,8 @@
 void Floors::init(int y, int width, int height){
     _height = height;
     _width = width;
-//  x-coordinate initially random: 2 left, 70 right
-    int _array[] = {3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70}; 
+//  x-coordinate initially random: 2-71 
+    int _array[] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70, 71}; 
     // excluding centre so doodler falls to the floor at bottom
     _position.x = _array[rand()%(sizeof(_array) / sizeof *_array)];
     _position.y = y;
@@ -20,14 +20,19 @@
 
 void Floors::update(float doodler_pos_y){
 // when they leave the screen they will re-appear in random x-coordinate so that 10 floors are always on screen
- //rectangle (2-81 & 10 - 45)
+ //rectangle (1-82 & 9 - 48 )
     _doodler_pos_y = doodler_pos_y;
     if (_position.y > 43 ){ 
-    _position.y = 10;   
-    _position.x = 2 + (rand()% 68);
+    _position.y = 9;   
+    _position.x = 1 + (rand()% 70);
+    place = rand()% 8;
+    if (place == 2){ // 1/8 chance of placing an enemy
+        _eny.init(_position.x, _position.y);
     }
-    if ( _doodler_pos_y < 25){ // shift floors once doodler reaches over halfway the screen
+    }
+    if (_doodler_pos_y < 25){ // shift floors once doodler reaches over halfway the screen
         _position.y  += 1; 
+        _eny.update(_position.x, _position.y);
     }
 }