ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el19tb

Dependencies:   mbed

Revision:
17:67dbdfcdcec2
Parent:
16:8a65cccd9685
Child:
18:6be4c3c94a3d
--- a/CrossyChicken/CrossyChicken.cpp	Wed May 13 23:07:05 2020 +0000
+++ b/CrossyChicken/CrossyChicken.cpp	Thu May 14 01:07:27 2020 +0000
@@ -241,10 +241,49 @@
     }      
 }
 
-void CrossyChicken::drawWater()
+// the water sprites are going to 'move' to make it realistic
+void CrossyChicken::createWater(){   
+    int state = 1;   
+    
+    for(it = 0; it != 21; it++)
+    {
+        // fsm for drawing safety lane background
+        switch(state)
+        {
+            case 1: // initial state
+                row_water_one[it].push_back('F'); // first type of water
+                state++; // transition to next state
+                break;
+            case 2: 
+                row_water_one[it].push_back('S'); // second type of water
+                state++; // transition to state 3
+                break;
+                
+            case 3:
+                row_water_one[it].push_back('T'); // third type of water
+                state = 1; // back to start state
+                break;
+        } 
+    }
+}
+
+void CrossyChicken::moveWater()
 {
+    for(it = 0; it != row_water_one.size(); it++){
+        graphics.moveWaterWithSpeed(&row_water_one[it]);
+    }
+}
 
-
+// if sprite goes out of bound then show again
+void CrossyChicken::loopWater(Water *sprite)
+{
+    // check if car goes out of bounds
+    if(sprite->x > 84+grid){
+        sprite->x = -4;
+        
+    } else if(sprite->x < -4){ 
+        sprite->x = 84 + grid;
+    } 
 }
 
 // make the frog move same speed as log