Yao mochu
/
Explorer
explorer game
explorer/explorer.cpp@2:89f04cd3bf45, 2020-04-20 (annotated)
- Committer:
- el17my
- Date:
- Mon Apr 20 08:31:02 2020 +0000
- Revision:
- 2:89f04cd3bf45
- Child:
- 3:672d4bd8225d
the explorer module
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17my | 2:89f04cd3bf45 | 1 | #include "explorer.h" |
el17my | 2:89f04cd3bf45 | 2 | //the explorer.cpp need to defined the module and movement of the explorer including the restarted point |
el17my | 2:89f04cd3bf45 | 3 | int move_right[10][10] = { |
el17my | 2:89f04cd3bf45 | 4 | { 0,0,0,1,1,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 5 | { 0,0,0,1,0,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 6 | { 0,0,0,1,1,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 7 | { 0,0,0,0,1,0,1,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 8 | { 0,0,1,1,1,1,1,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 9 | { 0,0,1,0,1,0,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 10 | { 0,0,0,0,1,0,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 11 | { 0,0,0,0,1,1,1,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 12 | { 0,0,0,1,0,0,0,1,0,0 }, |
el17my | 2:89f04cd3bf45 | 13 | { 1,0,1,0,0,0,0,0,1,0 }, |
el17my | 2:89f04cd3bf45 | 14 | { 0,1,0,0,0,0,0,0,0,1 }, |
el17my | 2:89f04cd3bf45 | 15 | }; |
el17my | 2:89f04cd3bf45 | 16 | |
el17my | 2:89f04cd3bf45 | 17 | int move_left[10][10] = { |
el17my | 2:89f04cd3bf45 | 18 | { 0,0,0,1,1,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 19 | { 0,0,0,1,0,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 20 | { 0,0,0,1,1,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 21 | { 0,0,1,0,1,0,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 22 | { 0,0,1,1,1,1,1,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 23 | { 0,0,0,0,1,0,1,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 24 | { 0,0,0,0,1,0,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 25 | { 0,0,0,1,1,0,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 26 | { 0,0,1,0,0,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 27 | { 0,1,0,0,0,0,1,0,1,0 }, |
el17my | 2:89f04cd3bf45 | 28 | { 1,0,0,0,0,0,0,1,0,0 }, |
el17my | 2:89f04cd3bf45 | 29 | }; |
el17my | 2:89f04cd3bf45 | 30 | |
el17my | 2:89f04cd3bf45 | 31 | int stand_right[10][10] = { |
el17my | 2:89f04cd3bf45 | 32 | { 0,0,0,1,1,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 33 | { 0,0,0,1,0,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 34 | { 0,0,0,1,1,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 35 | { 0,0,0,0,1,0,1,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 36 | { 0,0,1,1,1,1,1,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 37 | { 0,0,1,0,1,0,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 38 | { 0,0,0,0,1,0,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 39 | { 0,0,0,0,1,0,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 40 | { 0,0,0,1,0,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 41 | { 0,0,0,1,0,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 42 | { 0,0,0,1,0,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 43 | }; |
el17my | 2:89f04cd3bf45 | 44 | |
el17my | 2:89f04cd3bf45 | 45 | int stand_left[10][10] = { |
el17my | 2:89f04cd3bf45 | 46 | { 0,0,0,1,1,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 47 | { 0,0,0,1,0,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 48 | { 0,0,0,1,1,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 49 | { 0,0,1,0,1,0,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 50 | { 0,0,1,1,1,1,1,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 51 | { 0,0,0,0,1,0,1,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 52 | { 0,0,0,0,1,0,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 53 | { 0,0,0,0,1,0,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 54 | { 0,0,0,1,0,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 55 | { 0,0,0,1,0,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 56 | { 0,0,0,1,0,1,0,0,0,0 }, |
el17my | 2:89f04cd3bf45 | 57 | }; |
el17my | 2:89f04cd3bf45 | 58 | |
el17my | 2:89f04cd3bf45 | 59 | Explorer::explorer() {} |
el17my | 2:89f04cd3bf45 | 60 | |
el17my | 2:89f04cd3bf45 | 61 | Explorer::~explorer() {} |
el17my | 2:89f04cd3bf45 | 62 | |
el17my | 2:89f04cd3bf45 | 63 | void Explorer::set_x_coordinate((float joystick_x, int move, Player_direction direction, float joystick_y) |
el17my | 2:89f04cd3bf45 | 64 | { |
el17my | 2:89f04cd3bf45 | 65 | //this process is to set x and make sure the player can move |
el17my | 2:89f04cd3bf45 | 66 | _player_direction = direction; |
el17my | 2:89f04cd3bf45 | 67 | _move_counter = move; |
el17my | 2:89f04cd3bf45 | 68 | change_x(joystick_x); |
el17my | 2:89f04cd3bf45 | 69 | _x = 0.3*_move_counter + 30; |
el17my | 2:89f04cd3bf45 | 70 | } |
el17my | 2:89f04cd3bf45 | 71 | |
el17my | 2:89f04cd3bf45 | 72 | |
el17my | 2:89f04cd3bf45 | 73 | void Explorer::change_x(float joystick_x) { |
el17my | 2:89f04cd3bf45 | 74 | //now x is moving to the left than add to the X position |
el17my | 2:89f04cd3bf45 | 75 | else if (joystick_x < float(-0.1)) { |
el17my | 2:89f04cd3bf45 | 76 | _move_counter = _move_counter--; |
el17my | 2:89f04cd3bf45 | 77 | _player_direction = left; |
el17my | 2:89f04cd3bf45 | 78 | _respond_value = move_left; |
el17my | 2:89f04cd3bf45 | 79 | //now x is moving to the right than add to the X position |
el17my | 2:89f04cd3bf45 | 80 | } else if (joystick_x > float(0.1)) { |
el17my | 2:89f04cd3bf45 | 81 | _move_counter = _move_counter++; |
el17my | 2:89f04cd3bf45 | 82 | _player_direction = right; |
el17my | 2:89f04cd3bf45 | 83 | _respond_value = move_right; |
el17my | 2:89f04cd3bf45 | 84 | } else if (_player_direction == right) { // not moving. |
el17my | 2:89f04cd3bf45 | 85 | _respond_value = stand_right; |
el17my | 2:89f04cd3bf45 | 86 | } else { |
el17my | 2:89f04cd3bf45 | 87 | _respond_value = stand_left; |
el17my | 2:89f04cd3bf45 | 88 | } |
el17my | 2:89f04cd3bf45 | 89 | } |
el17my | 2:89f04cd3bf45 | 90 | |
el17my | 2:89f04cd3bf45 | 91 | void Explorer::reset_flag(bool flag) { |
el17my | 2:89f04cd3bf45 | 92 | if (flag) { |
el17my | 2:89f04cd3bf45 | 93 | _r_flag = true; |
el17my | 2:89f04cd3bf45 | 94 | } else { |
el17my | 2:89f04cd3bf45 | 95 | _r_flag = false; |
el17my | 2:89f04cd3bf45 | 96 | } |
el17my | 2:89f04cd3bf45 | 97 | } |
el17my | 2:89f04cd3bf45 | 98 | |
el17my | 2:89f04cd3bf45 | 99 | void explorer::set_y_coordinate(bool ifjump, int jump_counter, int level, Gamepad &gamepad); |
el17my | 2:89f04cd3bf45 | 100 | _level = level; |
el17my | 2:89f04cd3bf45 | 101 | _jump_counter = jump_counter; |
el17my | 2:89f04cd3bf45 | 102 | // jump need to have this function |
el17my | 2:89f04cd3bf45 | 103 | // when you jump makesure the module will not be offscreen also if you fall from the surface you can not jump back again |
el17my | 2:89f04cd3bf45 | 104 | if (ifjump && _jump_counter < ) { |
el17my | 2:89f04cd3bf45 | 105 | _jump_counter = ; // |
el17my | 2:89f04cd3bf45 | 106 | } |
el17my | 2:89f04cd3bf45 | 107 | //not offscreen and back to the surface |
el17my | 2:89f04cd3bf45 | 108 | if (_level == 1 && ifjump){ |
el17my | 2:89f04cd3bf45 | 109 | _level = ; |
el17my | 2:89f04cd3bf45 | 110 | } else if (_level == 0) { |
el17my | 2:89f04cd3bf45 | 111 | _level = ; |
el17my | 2:89f04cd3bf45 | 112 | } |
el17my | 2:89f04cd3bf45 | 113 | if (_jump_counter !=) _jump_counter--; |
el17my | 2:89f04cd3bf45 | 114 | _y = _level - *_jump_counter; |
el17my | 2:89f04cd3bf45 | 115 | |
el17my | 2:89f04cd3bf45 | 116 | int Explorer::get_y() { |
el17my | 2:89f04cd3bf45 | 117 | return _y; |
el17my | 2:89f04cd3bf45 | 118 | } |
el17my | 2:89f04cd3bf45 | 119 | |
el17my | 2:89f04cd3bf45 | 120 | int Explorer::get_x() { |
el17my | 2:89f04cd3bf45 | 121 | return _x; |
el17my | 2:89f04cd3bf45 | 122 | } |
el17my | 2:89f04cd3bf45 | 123 | |
el17my | 2:89f04cd3bf45 | 124 | int Explorer::get_m_counter();() { |
el17my | 2:89f04cd3bf45 | 125 | return _moving_counter; |
el17my | 2:89f04cd3bf45 | 126 | |
el17my | 2:89f04cd3bf45 | 127 | int Explorer::get_j_counter() { |
el17my | 2:89f04cd3bf45 | 128 | return _jump_counter; |
el17my | 2:89f04cd3bf45 | 129 | } |
el17my | 2:89f04cd3bf45 | 130 | |
el17my | 2:89f04cd3bf45 | 131 | bool Explorer::get_f_flag() { |
el17my | 2:89f04cd3bf45 | 132 | return _f_flag; |
el17my | 2:89f04cd3bf45 | 133 | } |
el17my | 2:89f04cd3bf45 | 134 | |
el17my | 2:89f04cd3bf45 | 135 | bool Skateboarder::get_reset_flag() { |
el17my | 2:89f04cd3bf45 | 136 | return _r_flag; |
el17my | 2:89f04cd3bf45 | 137 | } |
el17my | 2:89f04cd3bf45 | 138 | |
el17my | 2:89f04cd3bf45 | 139 | int * Explorer::* get_respond(Respond_value respond){ |
el17my | 2:89f04cd3bf45 | 140 | if (respond == Move_right) { |
el17my | 2:89f04cd3bf45 | 141 | return *skate_right; |
el17my | 2:89f04cd3bf45 | 142 | } else if (respond == Move_left) { |
el17my | 2:89f04cd3bf45 | 143 | return *skate_left; |
el17my | 2:89f04cd3bf45 | 144 | } else if (respond == Stand_left) { |
el17my | 2:89f04cd3bf45 | 145 | return *skate_stand_left; |
el17my | 2:89f04cd3bf45 | 146 | } else if (respond == Stand_right) { |
el17my | 2:89f04cd3bf45 | 147 | return *skate_stand_left; |
el17my | 2:89f04cd3bf45 | 148 | } |
el17my | 2:89f04cd3bf45 | 149 | } |
el17my | 2:89f04cd3bf45 | 150 | |
el17my | 2:89f04cd3bf45 | 151 | void Explorer::fall(bool f_flag, Gamepad &gamepad) { |
el17my | 2:89f04cd3bf45 | 152 | _f_flag = f_flag; |
el17my | 2:89f04cd3bf45 | 153 | gamepad.tone(int(-15.8*_y + 1363), 0.05); // decending equation |
el17my | 2:89f04cd3bf45 | 154 | _y++; |
el17my | 2:89f04cd3bf45 | 155 | wait(0.01); // Control fall time and fall sound speed. |
el17my | 2:89f04cd3bf45 | 156 | if (_y == ) { // Stop falling when y = 80. |
el17my | 2:89f04cd3bf45 | 157 | _f_flag = false; |
el17my | 2:89f04cd3bf45 | 158 | _r_flag = true; |
el17my | 2:89f04cd3bf45 | 159 | } |
el17my | 2:89f04cd3bf45 | 160 | } |