Yao mochu
/
Explorer
explorer game
explorer/explorer.cpp
- Committer:
- el17my
- Date:
- 2020-04-20
- Revision:
- 2:89f04cd3bf45
- Child:
- 3:672d4bd8225d
File content as of revision 2:89f04cd3bf45:
#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] = { { 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 }, { 0,0,0,0,1,0,1,0,0,0 }, { 0,0,1,1,1,1,1,0,0,0 }, { 0,0,1,0,1,0,0,0,0,0 }, { 0,0,0,0,1,0,0,0,0,0 }, { 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] = { { 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 }, { 0,0,1,0,1,0,0,0,0,0 }, { 0,0,1,1,1,1,1,0,0,0 }, { 0,0,0,0,1,0,1,0,0,0 }, { 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 }, }; int stand_right[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 }, { 0,0,0,0,1,0,1,0,0,0 }, { 0,0,1,1,1,1,1,0,0,0 }, { 0,0,1,0,1,0,0,0,0,0 }, { 0,0,0,0,1,0,0,0,0,0 }, { 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] = { { 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 }, { 0,0,1,0,1,0,0,0,0,0 }, { 0,0,1,1,1,1,1,0,0,0 }, { 0,0,0,0,1,0,1,0,0,0 }, { 0,0,0,0,1,0,0,0,0,0 }, { 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() {} void Explorer::set_x_coordinate((float joystick_x, int move, Player_direction direction, float joystick_y) { //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; } 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; } } void explorer::set_y_coordinate(bool ifjump, int jump_counter, int level, Gamepad &gamepad); _level = level; _jump_counter = jump_counter; // 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 = ; // } //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; int Explorer::get_y() { return _y; } int Explorer::get_x() { return _x; } int Explorer::get_m_counter();() { return _moving_counter; int Explorer::get_j_counter() { return _jump_counter; } bool Explorer::get_f_flag() { return _f_flag; } 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::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. _f_flag = false; _r_flag = true; } }