ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el19tb

Dependencies:   mbed

Revision:
41:6267c66953ca
Parent:
37:65c9e5a65738
Child:
42:04e326dcf09b
--- a/Frogger/Frogger.cpp	Mon May 18 02:36:44 2020 +0000
+++ b/Frogger/Frogger.cpp	Mon May 18 03:12:30 2020 +0000
@@ -64,21 +64,34 @@
     //keep reading and processing user input
     while(1) {
         graphics.clear(); // clear the lcd screen
-        runCurrentLevel();
+        runCurrentLevel(); // add velocity to level vehicles and logs
 
-        graphics.showChicken(); 
-        process_input(); // user controls the frog object
+        graphics.showFrog(); // display current position of frog
+        process_input(); // user controls the frog object   
         
-        // now when the chicken is above the safety 
-        // lane we need to ensure that it only can go on logs
+        checkCurrentLevelCollision(); // check if the frog is alive
+        checkFrogInWater(); // check if the frog is in the water level
+            
+        graphics.refresh(); // refresh the lcd screen
         
-            
-        graphics.refresh();
-        wait_ms(70);
+        wait_ms(70); // fpms
     } 
 }
 
-void checkIfFrogIsInWater()
+void Frogger::checkCurrentLevelCollision()
+{
+    switch (current_level)
+    {
+        case 1:
+            level->levelOneCollision();
+            break;
+        case 2:
+            level->levelTwoCollision();
+            break;
+    }
+}
+
+void Frogger::checkIfFrogIsInWater()
 {
     if(chicken.y < screenH - grid*6){
         frogDie = true;  // frog can die if it is in water  
@@ -112,16 +125,16 @@
     /* make this a switch statement */
     if(gamepad.A_pressed()){
         moveChicken(1,0);
-        attach = false;
+        level->frogOnLog = false;
     } else if(gamepad.X_pressed()){
         moveChicken(0,-1);
-        attach = false;
+        level->frogOnLog = false;
     } else if(gamepad.B_pressed()){
         moveChicken(0,1);
-        attach = false;
+        level->frogOnLog = false;
     } else if(gamepad.Y_pressed()){
         moveChicken(-1,0);
-        attach = false;
+        level->frogOnLog = false;
     } 
 }
 
@@ -295,11 +308,7 @@
     chicken.right_side = grid + chicken.x;
     chicken.up = chicken.y;
     chicken.down = grid + chicken.y;
-        
-    //display the new state of the chicken
-    //graphics.showChicken();
-    
-    //wait_ms(30);
+
 }
 
 void Frogger::moveCar(Car *car, int dir, int x) {
@@ -318,8 +327,7 @@
 void Frogger::setCollision(Car *car){
     
     float other_bottom = car->vehicle.height + car->vehicle.y;
-    
-    
+       
     if(!(chicken.up >= other_bottom || 
     (chicken.right_side <= car->vehicle.x)  ||
     (chicken.down <= car->vehicle.y) ||