Josh Davy / Mbed OS Flip_OS_5

Dependencies:   el17jd

Revision:
9:96969b1c6bde
Parent:
8:21b6d4dbce44
Child:
10:58cf89dd878c
--- a/Level/Level.cpp	Fri Apr 19 17:54:09 2019 +0000
+++ b/Level/Level.cpp	Wed Apr 24 10:18:45 2019 +0000
@@ -4,13 +4,12 @@
 
 Level::~Level() {}
 
-void Level::init(Block blocks [],MovingBlock moving_blocks [],
+void Level::init(Block blocks [],
                  int number_of_blocks,
-                 int number_of_moving_blocks,
                  Vector2D goal)
 {
     _number_of_blocks = number_of_blocks;
-    _number_of_moving_blocks = number_of_moving_blocks;
+
 
 
     for (int i = 0; i<_number_of_blocks; i++) {
@@ -20,20 +19,84 @@
         _blocks[i].second.y = blocks[i].second.y;
     }
 
-    for (int i = 0; i<_number_of_moving_blocks; i++) {
-        _moving_blocks[i] = moving_blocks[i];
+    _goal = goal;
+    _number_of_moving_blocks = 0;
+}
+
+Block * Level::get_blocks()
+{
+    return _blocks;
+}
+
+int Level::get_number_of_blocks()
+{
+    return _number_of_blocks;
+}
+
+Vector2D Level::get_goal()
+{
+    return _goal;
+}
+
+void Level::update_moving_blocks()
+{
+    MovingBlock current_block;
+    for (int i = 0; i < _number_of_moving_blocks; i++) {
+        current_block = _moving_blocks[i];
+
+
+        if (current_block.extending) {
+
+            _blocks[current_block.index].first.x += 1;
+            _blocks[current_block.index].second.x += 1;
+
+        } else  {
+
+            _blocks[current_block.index].first.x -= 1;
+            _blocks[current_block.index].second.x -= 1;
+
+        }
+
+
+
+
+        if (_blocks[current_block.index].first.x >
+                (current_block.initial_pos + current_block.distance)) {
+            current_block.extending = false;
+        }
+        if (_blocks[current_block.index].first.x < current_block.initial_pos) {
+            current_block.extending = true;
+
+        }
+
+        _moving_blocks[i] = current_block;
     }
 
 
-    _goal = goal;
-}
-
-void Level::update()
-{
 
 }
 
 
+void Level::declare_moving_block(int index,bool extending,int distance)
+{
+    MovingBlock new_moving_block;
+    new_moving_block.index = index;
+    new_moving_block.distance = distance;
+    new_moving_block.extending = extending;
+    new_moving_block.initial_pos = _blocks[index].first.x;
+    
+    if(!extending) {
+        _blocks[index].first.x += distance;
+        _blocks[index].second.x += distance;
+    }
+    
+    
+
+    _moving_blocks[_number_of_moving_blocks] = new_moving_block;
+    _number_of_moving_blocks += 1;
+
+
+}
 
 void Level::render(N5110 &lcd)
 {