Mochu Yao explorer game

Dependencies:   mbed

Revision:
33:ea83f08fa466
Parent:
31:8e92b65e0779
Child:
34:66e37a0d59c3
--- a/explorer/explorer.cpp	Wed Apr 29 12:19:12 2020 +0000
+++ b/explorer/explorer.cpp	Wed Apr 29 13:28:41 2020 +0000
@@ -105,29 +105,30 @@
   return _explorer_sprite;
 }
     
-void Explorer::set_y_coordinate(bool ifjump, int jump_height) {
+void Explorer::set_y_coordinate(bool ifjump, int jump_height, int ) {
   _jump_height = jump_height;
-  // jump need to have this function
-  // when you jump makesure the module will not be offscreen also if you fall from the surface you can not jump back again
-  if (ifjump == 1) {  
-    _jump_height = 40; }  //the player can jump up to 30 height and then fall down 
-  if (_jump_height !=0) { 
-    _jump_height--;
-    _y = 20 + _jump_height;
-    if ((_line_4.left <= _x) && (_line_4.right >= _x) && (_y >= 40)) {
-    _y = 40; _jump_height = 0;}
-    else if ((_line_5.left <= _x) && (_line_5.right >= _x) && (_y >= 40)) {
-    _y = 40; _jump_height = 0;}
-    else if ((_line_6.left <= _x) && (_line_6.right >= _x) && (_y >= 40)) {
-    _y = 40; _jump_height = 0;}
-    else if ((_line_1.left <= _x) && (_line_1.right >= _x) && (_y < 40)) {
-    _y = 20; _jump_height = 0;}
-    else if ((_line_2.left <= _x) && (_line_2.right >= _x) && (_y < 40)) {
-    _y = 20; _jump_height = 0;}
-    else if ((_line_3.left <= _x) && (_line_3.right >= _x) && (_y < 40)) {
-    _y = 20; _jump_height = 0;}
-    else { _f_flag = true; }
+  if (ifjump && _jump_height < 35) {  
+    _jump_height = 40; }
+  if (_jump_height !=0) _speed--;  // Keep falling until not jumping.
+  if ((_line_4.left <= _x - 5) && (_line_4.right >= _x)){
+    _y_flag = 1;}
+    else if ((_line_5.left <= _x - 5) && (_line_5.right >= _x)) {
+    _y_flag = 1;}
+    else if ((_line_6.left <= _x - 5) && (_line_6.right >= _x)) {
+    _y_flag = 1;}
+    else if ((_line_1.left <= _x) && (_line_1.right >= _x)){
+    _y_flag = 0; }
+    else if ((_line_2.left <= _x) && (_line_2.right >= _x)){
+    _y_flag = 0;}
+    else if ((_line_3.left <= _x) && (_line_3.right >= _x)){
+    _y_flag = 0;}
+  }       
+  if (_y_flag == 1 && ifjump) { 
+    _platform = 5;
+  } else if (_y_flag == 0) {
+    _platform = 23;
   }
+  _y = _platform - 0.5*_jump_height;  
 }
   
 int Explorer::get_y() {
@@ -156,10 +157,10 @@
 
  
 void Explorer::fall(bool f_flag, Gamepad &gamepad) { 
-  _f_flag = f_flag;
-    gamepad.tone(int(1500+0.5*_y), 0.05);  // decending equation 
-    _y++;
-  if(_y == 80) {  // Stop falling function 
+  _f_flag = f_flag;  // decending equation
+  if (_f_flag == true) { 
+    _y++; }
+  else if(_y == 80) {  // Stop falling function 
     _f_flag = false;
     _r_flag = true;
     gamepad.tone(1000, 0.05);