Mochu Yao explorer game

Dependencies:   mbed

Revision:
8:201ef0618b7d
Parent:
7:88c4ba6bb37b
Child:
17:1b4ecc01b79f
diff -r 88c4ba6bb37b -r 201ef0618b7d explorer/explorer.cpp
--- a/explorer/explorer.cpp	Thu Apr 23 07:49:39 2020 +0000
+++ b/explorer/explorer.cpp	Mon Apr 27 08:41:29 2020 +0000
@@ -55,6 +55,13 @@
 Explorer::Explorer() {} 
 
 Explorer::~Explorer() {}
+void Explorer::init() {
+  _f_flag = false;
+  _player_direction = right;
+  _r_flag = false;
+  _speed = 0;//the player is standing at first
+  _jump_height = 15;
+  }
 
 void Explorer::set_x_coordinate(float joy_x, int speed, Player_direction direction)
 {
@@ -78,7 +85,7 @@
   _x = 0.5*_speed + 30;//this equation decides how fast the player move later I will update differnet modes to choose different speed
 }
 //this function is easy to understand because this is just choosing different sprite according to the direction
-int * Explorer::get_form(explorer_sprite sprite){
+int * Explorer::get_form(Explorer_sprite sprite){
   if (sprite == Move_right) {
     return *move_right_sprite;
   } else if (sprite == Move_left) {
@@ -94,28 +101,35 @@
   return _player_direction;
 }    
 
-explorer_sprite get_explorer_sprite() {
+Explorer_sprite Explorer::get_explorer_sprite() {
   return _explorer_sprite;
 }
     
-void Explorer::set_y_coordinate(bool ifjump, int jump_height, int level) {
-  _level = level; 
+void Explorer::set_y_coordinate(bool ifjump, int jump_height) {
   _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 = 30;  //the player can jump up to 30 height and then fall down 
-  else if (_jumpheight !=0) { 
-  _jumpheight-- }
-  };
-  //not offscreen and back to the surface        
-  if (_level == 1 && ifjump){
-    _level = ;
-  } else if (_level == 0) {
-    _level = ;
+    _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; }
   }
-  _y = _level - 0.5*_jumpheight;
-}  
+}
+  
 int Explorer::get_y() {
   return _y;
 }
@@ -128,30 +142,30 @@
   return _speed;
 }
   
-int Explorer::get_jumptime() {
-  return _jumptime;
+int Explorer::get_jump_height() {
+  return _jump_height;
 }
 
-void Explorer::reset_flag(bool flag) {
-  _r_flag = flag
+void Explorer::reset_flag(bool flag, Gamepad &gamepad) {
+  _r_flag = flag;
   if (flag) {
     _r_flag = true;
   } else {
     _r_flag = false;
   }
+  gamepad.tone(600, 0.05);
 }
  
 void Explorer::fall(bool f_flag, Gamepad &gamepad) { 
   _f_flag = f_flag;
-  if (f_flag == true) {
+  if (_f_flag == true) {
     gamepad.tone(int(1500+0.5*_y), 0.05);  // decending equation 
-    _y--;
+    _y--; }
   else if(_y == -80) {  // Stop falling function 
     _f_flag = false;
     _r_flag = true;
-    game.tone(1000, 0.05);
+    gamepad.tone(1000, 0.05);
     wait(0.01);
-    }
   }
 }