Mochu Yao explorer game
Dependencies: mbed
Diff: explorer/explorer.cpp
- Revision:
- 3:672d4bd8225d
- Parent:
- 2:89f04cd3bf45
- Child:
- 7:88c4ba6bb37b
--- a/explorer/explorer.cpp Mon Apr 20 08:31:02 2020 +0000 +++ b/explorer/explorer.cpp Tue Apr 21 12:31:27 2020 +0000 @@ -1,6 +1,6 @@ #include "explorer.h" //the explorer.cpp need to defined the module and movement of the explorer including the restarted point -int move_right[10][10] = { +int move_right_sprite[10][10] = { { 0,0,0,1,1,1,0,0,0,0 }, { 0,0,0,1,0,1,0,0,0,0 }, { 0,0,0,1,1,1,0,0,0,0 }, @@ -11,10 +11,9 @@ { 0,0,0,0,1,1,1,0,0,0 }, { 0,0,0,1,0,0,0,1,0,0 }, { 1,0,1,0,0,0,0,0,1,0 }, - { 0,1,0,0,0,0,0,0,0,1 }, }; -int move_left[10][10] = { +int move_left_sprite[10][10] = { { 0,0,0,1,1,1,0,0,0,0 }, { 0,0,0,1,0,1,0,0,0,0 }, { 0,0,0,1,1,1,0,0,0,0 }, @@ -24,11 +23,10 @@ { 0,0,0,0,1,0,0,0,0,0 }, { 0,0,0,1,1,0,0,0,0,0 }, { 0,0,1,0,0,1,0,0,0,0 }, - { 0,1,0,0,0,0,1,0,1,0 }, - { 1,0,0,0,0,0,0,1,0,0 }, + { 0,1,0,0,0,0,1,0,0,0 }, }; -int stand_right[10][10] = { +int stand_right_sprite[10][10] = { { 0,0,0,1,1,1,0,0,0,0 }, { 0,0,0,1,0,1,0,0,0,0 }, { 0,0,0,1,1,1,0,0,0,0 }, @@ -39,10 +37,9 @@ { 0,0,0,0,1,0,0,0,0,0 }, { 0,0,0,1,0,1,0,0,0,0 }, { 0,0,0,1,0,1,0,0,0,0 }, - { 0,0,0,1,0,1,0,0,0,0 }, }; -int stand_left[10][10] = { +int stand_left_sprite[10][10] = { { 0,0,0,1,1,1,0,0,0,0 }, { 0,0,0,1,0,1,0,0,0,0 }, { 0,0,0,1,1,1,0,0,0,0 }, @@ -53,66 +50,72 @@ { 0,0,0,0,1,0,0,0,0,0 }, { 0,0,0,1,0,1,0,0,0,0 }, { 0,0,0,1,0,1,0,0,0,0 }, - { 0,0,0,1,0,1,0,0,0,0 }, }; -Explorer::explorer() {} +Explorer::Explorer() {} -Explorer::~explorer() {} +Explorer::~Explorer() {} -void Explorer::set_x_coordinate((float joystick_x, int move, Player_direction direction, float joystick_y) +void Explorer::set_x_coordinate(float joy_x, int speed, Player_direction direction) { //this process is to set x and make sure the player can move _player_direction = direction; - _move_counter = move; - change_x(joystick_x); - _x = 0.3*_move_counter + 30; + _speed = speed; + if (joystick_x < float(-0.5)) { + _speed = _speed--;// + _player_direction = left; + _sprite = Move_left;//makesure the value is the Move_left value in the enum + //now x is moving to the right than add to the X position + } else if (joystick_x > float(0.5)) { + _speed = _speed++; + _player_direction = right; + _sprite = Move_right;//makesure the value is the Move_right value in the enum + } else if (_player_direction == right) { + _sprite = Stand_right;// not moving so equals to enum Stand_right. + } else { + _sprite = Stand_left;//the least situation is equals to enum Stand_right. + } + _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){ + if (sprite == Move_right) { + return *move_right_sprite; + } else if (sprite == Move_left) { + return *move_left_sprite; + } else if (sprite == Stand_left) { + return *stand_right_sprite; + } else { + return *stand_left_sprite; + } } +Player_direction Explorer::get_direction() { + return _player_direction; +} -void Explorer::change_x(float joystick_x) { - //now x is moving to the left than add to the X position - else if (joystick_x < float(-0.1)) { - _move_counter = _move_counter--; - _player_direction = left; - _respond_value = move_left; - //now x is moving to the right than add to the X position - } else if (joystick_x > float(0.1)) { - _move_counter = _move_counter++; - _player_direction = right; - _respond_value = move_right; - } else if (_player_direction == right) { // not moving. - _respond_value = stand_right; - } else { - _respond_value = stand_left; - } -} - -void Explorer::reset_flag(bool flag) { - if (flag) { - _r_flag = true; - } else { - _r_flag = false; - } +explorer_sprite get_explorer_sprite(); { + return _sprite; } -void explorer::set_y_coordinate(bool ifjump, int jump_counter, int level, Gamepad &gamepad); +void Explorer::set_y_coordinate(bool ifjump, int jump_height, int level) { _level = level; - _jump_counter = jump_counter; + _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 && _jump_counter < ) { - _jump_counter = ; // - } + 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 = ; } - if (_jump_counter !=) _jump_counter--; - _y = _level - *_jump_counter; - + _y = _level - 0.5*_jumpheight; +} int Explorer::get_y() { return _y; } @@ -121,40 +124,41 @@ return _x; } -int Explorer::get_m_counter();() { - return _moving_counter; +int Explorer::get_speed() { + return _speed; +} -int Explorer::get_j_counter() { - return _jump_counter; -} - -bool Explorer::get_f_flag() { - return _f_flag; +int Explorer::get_jumptime() { + return _jumptime; } -bool Skateboarder::get_reset_flag() { - return _r_flag; -} - -int * Explorer::* get_respond(Respond_value respond){ - if (respond == Move_right) { - return *skate_right; - } else if (respond == Move_left) { - return *skate_left; - } else if (respond == Stand_left) { - return *skate_stand_left; - } else if (respond == Stand_right) { - return *skate_stand_left; +void Explorer::reset_flag(bool flag) { + _r_flag = flag + if (flag) { + _r_flag = true; + } else { + _r_flag = false; } } void Explorer::fall(bool f_flag, Gamepad &gamepad) { _f_flag = f_flag; - gamepad.tone(int(-15.8*_y + 1363), 0.05); // decending equation - _y++; - wait(0.01); // Control fall time and fall sound speed. - if (_y == ) { // Stop falling when y = 80. + if (f_flag == true) { + gamepad.tone(int(1500-0.5*_y), 0.05); // decending equation + _y--; + else if(_y == -80) { // Stop falling function _f_flag = false; _r_flag = true; + game.tone(1000, 0.05); + wait(0.01); + } } +} + +bool Explorer::get_fall_flag() { + return _f_flag; +} + +bool Explorer::get_reset_flag() { + return _r_flag; } \ No newline at end of file