Mochu Yao explorer game
Dependencies: mbed
explorer/explorer.h@36:cdfba51a0a44, 2020-05-13 (annotated)
- Committer:
- el17my
- Date:
- Wed May 13 08:49:44 2020 +0000
- Revision:
- 36:cdfba51a0a44
- Parent:
- 33:ea83f08fa466
5.13
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17my | 14:5e73a6e34c17 | 1 | #ifndef EXPLORER_H |
el17my | 14:5e73a6e34c17 | 2 | #define EXPLORER_H |
el17my | 14:5e73a6e34c17 | 3 | |
el17my | 14:5e73a6e34c17 | 4 | |
el17my | 14:5e73a6e34c17 | 5 | #include "mbed.h" |
el17my | 14:5e73a6e34c17 | 6 | #include "Gamepad.h" |
el17my | 14:5e73a6e34c17 | 7 | #include "surface.h" |
el17my | 14:5e73a6e34c17 | 8 | //use the enum to define the value we need for the explorer |
el17my | 14:5e73a6e34c17 | 9 | enum Explorer_sprite {Move_right,Move_left,Stand_left, Stand_right}; |
el17my | 14:5e73a6e34c17 | 10 | //we have four sprite form so we can define the sprite on the screen by using these enum |
el17my | 14:5e73a6e34c17 | 11 | //the explorer's direction |
el17my | 14:5e73a6e34c17 | 12 | enum Player_direction {right,left}; |
el17my | 14:5e73a6e34c17 | 13 | |
el17my | 14:5e73a6e34c17 | 14 | /** Explorer Class |
el17my | 7:88c4ba6bb37b | 15 | * @the explorer file has three functions |
el17my | 23:7be9701fc1b8 | 16 | * @ 1 the movement of a explorer to jump and move in left or right direction |
el17my | 23:7be9701fc1b8 | 17 | * @ 2 check fallen and collision |
el17my | 23:7be9701fc1b8 | 18 | * @ 3 reset the game |
el17my | 23:7be9701fc1b8 | 19 | * @ date April 15th 2020 |
el17my | 23:7be9701fc1b8 | 20 | * @ author Yaomochu |
el17my | 27:354d91d59b6d | 21 | * @code |
el17my | 27:354d91d59b6d | 22 | |
el17my | 27:354d91d59b6d | 23 | #include "mbed.h" |
el17my | 27:354d91d59b6d | 24 | #include "N5110.h" |
el17my | 27:354d91d59b6d | 25 | #include "Gamepad.h" |
el17my | 27:354d91d59b6d | 26 | #include "explorer.h" |
el17my | 27:354d91d59b6d | 27 | #include <cstdlib> |
el17my | 27:354d91d59b6d | 28 | #include <ctime> |
el17my | 27:354d91d59b6d | 29 | |
el17my | 27:354d91d59b6d | 30 | Gamepad gamepad; |
el17my | 27:354d91d59b6d | 31 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
el17my | 27:354d91d59b6d | 32 | Explorer _player; |
el17my | 27:354d91d59b6d | 33 | |
el17my | 27:354d91d59b6d | 34 | int _player_x; |
el17my | 27:354d91d59b6d | 35 | int _player_y; |
el17my | 27:354d91d59b6d | 36 | bool _f_flag; |
el17my | 27:354d91d59b6d | 37 | bool _start_flag; |
el17my | 27:354d91d59b6d | 38 | int _speed; |
el17my | 27:354d91d59b6d | 39 | int _jump_height; |
el17my | 33:ea83f08fa466 | 40 | int _y_flag; |
el17my | 27:354d91d59b6d | 41 | Player_direction _player_direction; |
el17my | 27:354d91d59b6d | 42 | Explorer_sprite _explorer_sprite; |
el17my | 27:354d91d59b6d | 43 | |
el17my | 27:354d91d59b6d | 44 | int main() { |
el17my | 27:354d91d59b6d | 45 | _player.init(); |
el17my | 27:354d91d59b6d | 46 | _start_flag = true; |
el17my | 27:354d91d59b6d | 47 | while(1) { |
el17my | 27:354d91d59b6d | 48 | |
el17my | 27:354d91d59b6d | 49 | // Y coordinate |
el17my | 27:354d91d59b6d | 50 | if (_f_flag == true) |
el17my | 27:354d91d59b6d | 51 | { |
el17my | 27:354d91d59b6d | 52 | _player.fall(_f_flag, gamepad); |
el17my | 27:354d91d59b6d | 53 | } else { |
el17my | 33:ea83f08fa466 | 54 | _player.set_y_coordinate(false, _jump_height, _y_flag} |
el17my | 27:354d91d59b6d | 55 | _f_flag = _player.get_fall_flag(); |
el17my | 27:354d91d59b6d | 56 | _player_y = _player.get_y(); |
el17my | 27:354d91d59b6d | 57 | _jump_height = _player.get_jump_height(); |
el17my | 27:354d91d59b6d | 58 | |
el17my | 27:354d91d59b6d | 59 | // X coordinate |
el17my | 27:354d91d59b6d | 60 | _player_x = _player.get_x(); |
el17my | 27:354d91d59b6d | 61 | _speed = _player.get_speed(); |
el17my | 27:354d91d59b6d | 62 | _player.set_x_coordinate(1, _speed, _player_direction); |
el17my | 27:354d91d59b6d | 63 | |
el17my | 27:354d91d59b6d | 64 | |
el17my | 27:354d91d59b6d | 65 | //change in to a new direction. |
el17my | 27:354d91d59b6d | 66 | _player_direction = _player.get_direction(); |
el17my | 27:354d91d59b6d | 67 | |
el17my | 27:354d91d59b6d | 68 | lcd.drawSprite(_player_x,_player_y,10,10,(int *)_player.get_form(_explorer_sprite));//draw the player |
el17my | 27:354d91d59b6d | 69 | } |
el17my | 27:354d91d59b6d | 70 | } |
el17my | 27:354d91d59b6d | 71 | |
el17my | 27:354d91d59b6d | 72 | * @endcode |
el17my | 27:354d91d59b6d | 73 | */ |
el17my | 13:30330d61f09c | 74 | |
el17my | 7:88c4ba6bb37b | 75 | class Explorer { |
el17my | 7:88c4ba6bb37b | 76 | public: |
el17my | 30:65e639ace415 | 77 | // Constructor and destructor. |
el17my | 30:65e639ace415 | 78 | /** |
el17my | 30:65e639ace415 | 79 | * @brief Constructor @details Non user specified. |
el17my | 30:65e639ace415 | 80 | */ |
el17my | 7:88c4ba6bb37b | 81 | Explorer(); |
el17my | 30:65e639ace415 | 82 | /** |
el17my | 30:65e639ace415 | 83 | * @brief Destructor @details Non user specified. |
el17my | 30:65e639ace415 | 84 | */ |
el17my | 7:88c4ba6bb37b | 85 | ~Explorer(); |
el17my | 8:201ef0618b7d | 86 | void init(); |
el17my | 30:65e639ace415 | 87 | |
el17my | 30:65e639ace415 | 88 | // Mutators. |
el17my | 30:65e639ace415 | 89 | /** |
el17my | 30:65e639ace415 | 90 | * @brief Sets the X coordinate of the Explorer. |
el17my | 30:65e639ace415 | 91 | * @param joy_x @details The horizontal value of the joystick x. |
el17my | 30:65e639ace415 | 92 | * @param speed @details The player's speed to move. |
el17my | 30:65e639ace415 | 93 | * @param Player_direction direction @details The current direction the skater is facing from the enum class |
el17my | 30:65e639ace415 | 94 | */ |
el17my | 7:88c4ba6bb37b | 95 | void set_x_coordinate(float joy_x, int speed, Player_direction direction); |
el17my | 30:65e639ace415 | 96 | /** |
el17my | 30:65e639ace415 | 97 | * @brief Sets the Y coordinate of the Explorer. |
el17my | 30:65e639ace415 | 98 | * @param ifjump @details B boolean flag that is true only if the B button is pressed |
el17my | 30:65e639ace415 | 99 | * @param jump_height @details the height when player jumps and which level to stay |
el17my | 33:ea83f08fa466 | 100 | * @param y_flag @details the upper or lower surface |
el17my | 33:ea83f08fa466 | 101 | * @param platform @details the y for the platform |
el17my | 30:65e639ace415 | 102 | */ |
el17my | 33:ea83f08fa466 | 103 | void set_y_coordinate(bool ifjump, int jump_height, int y_flag); |
el17my | 30:65e639ace415 | 104 | /** |
el17my | 30:65e639ace415 | 105 | * @brief get y coordinate. |
el17my | 30:65e639ace415 | 106 | * @returns The y coordinate of the explorer |
el17my | 30:65e639ace415 | 107 | */ |
el17my | 7:88c4ba6bb37b | 108 | int get_y(); |
el17my | 30:65e639ace415 | 109 | /** |
el17my | 30:65e639ace415 | 110 | * @brief get x coordinate. |
el17my | 30:65e639ace415 | 111 | * @returns The x coordinate of the explorer |
el17my | 30:65e639ace415 | 112 | */ |
el17my | 7:88c4ba6bb37b | 113 | int get_x(); |
el17my | 30:65e639ace415 | 114 | /** |
el17my | 30:65e639ace415 | 115 | * @brief get speed. |
el17my | 30:65e639ace415 | 116 | * @returns The moving speed of the explorer |
el17my | 30:65e639ace415 | 117 | */ |
el17my | 7:88c4ba6bb37b | 118 | int get_speed(); |
el17my | 30:65e639ace415 | 119 | /** |
el17my | 30:65e639ace415 | 120 | * @brief get jump height. |
el17my | 30:65e639ace415 | 121 | * @returns the increasing height of the explorer. |
el17my | 30:65e639ace415 | 122 | */ |
el17my | 7:88c4ba6bb37b | 123 | int get_jump_height(); |
el17my | 30:65e639ace415 | 124 | /** |
el17my | 36:cdfba51a0a44 | 125 | * @brief get the level of the player. |
el17my | 36:cdfba51a0a44 | 126 | * @returns if the player is on upper or lower platform. |
el17my | 36:cdfba51a0a44 | 127 | */ |
el17my | 36:cdfba51a0a44 | 128 | int get_y_flag(); |
el17my | 36:cdfba51a0a44 | 129 | /** |
el17my | 30:65e639ace415 | 130 | * @brief get player's direction. |
el17my | 30:65e639ace415 | 131 | * @returns direction of the player. |
el17my | 30:65e639ace415 | 132 | */ |
el17my | 7:88c4ba6bb37b | 133 | Player_direction get_direction(); |
el17my | 30:65e639ace415 | 134 | /** |
el17my | 30:65e639ace415 | 135 | * @brief get sprite. |
el17my | 30:65e639ace415 | 136 | * @returns four different sprites. |
el17my | 30:65e639ace415 | 137 | */ |
el17my | 8:201ef0618b7d | 138 | Explorer_sprite get_explorer_sprite(); |
el17my | 30:65e639ace415 | 139 | /** |
el17my | 30:65e639ace415 | 140 | * @brief get the players form and print on the screen (same as the item file) |
el17my | 30:65e639ace415 | 141 | * @returns the sprite of the explorer |
el17my | 30:65e639ace415 | 142 | */ |
el17my | 8:201ef0618b7d | 143 | int * get_form(Explorer_sprite sprite); |
el17my | 30:65e639ace415 | 144 | /** |
el17my | 30:65e639ace415 | 145 | * @brief get the fall flag |
el17my | 30:65e639ace415 | 146 | * @param &gamepad @details The gamepad object from Gamepad class. |
el17my | 30:65e639ace415 | 147 | * @param f_flag @details the fall flag. |
el17my | 30:65e639ace415 | 148 | */ |
el17my | 7:88c4ba6bb37b | 149 | void fall(bool f_flag, Gamepad &gamepad); |
el17my | 30:65e639ace415 | 150 | /** |
el17my | 30:65e639ace415 | 151 | * @brief get the reset flag |
el17my | 30:65e639ace415 | 152 | * @param flag @details the reset flag. |
el17my | 30:65e639ace415 | 153 | */ |
el17my | 20:20e6ba54e15c | 154 | void reset_flag(bool flag); |
el17my | 30:65e639ace415 | 155 | /** |
el17my | 30:65e639ace415 | 156 | * @brief Gets the fall flag. |
el17my | 30:65e639ace415 | 157 | * @returns The fall flag of the explorer. |
el17my | 30:65e639ace415 | 158 | */ |
el17my | 7:88c4ba6bb37b | 159 | bool get_fall_flag(); |
el17my | 30:65e639ace415 | 160 | /** |
el17my | 30:65e639ace415 | 161 | * @brief Gets the reset flag. |
el17my | 30:65e639ace415 | 162 | * @returns The reset flag of the explorer. |
el17my | 30:65e639ace415 | 163 | */ |
el17my | 7:88c4ba6bb37b | 164 | bool get_reset_flag(); |
el17my | 7:88c4ba6bb37b | 165 | |
el17my | 7:88c4ba6bb37b | 166 | private: |
el17my | 7:88c4ba6bb37b | 167 | |
el17my | 23:7be9701fc1b8 | 168 | int _x; |
el17my | 23:7be9701fc1b8 | 169 | int _y; |
el17my | 23:7be9701fc1b8 | 170 | int _speed; |
el17my | 23:7be9701fc1b8 | 171 | int _jump_height; |
el17my | 23:7be9701fc1b8 | 172 | bool _f_flag; |
el17my | 23:7be9701fc1b8 | 173 | bool _r_flag; |
el17my | 33:ea83f08fa466 | 174 | int _platform; |
el17my | 33:ea83f08fa466 | 175 | int _y_flag; |
el17my | 12:bb89733cc51a | 176 | Line _line_1; |
el17my | 12:bb89733cc51a | 177 | Line _line_2; |
el17my | 12:bb89733cc51a | 178 | Line _line_3; |
el17my | 12:bb89733cc51a | 179 | Line _line_4; |
el17my | 12:bb89733cc51a | 180 | Line _line_5; |
el17my | 12:bb89733cc51a | 181 | Line _line_6; |
el17my | 12:bb89733cc51a | 182 | Player_direction _player_direction; |
el17my | 12:bb89733cc51a | 183 | Explorer_sprite _explorer_sprite; |
el17my | 7:88c4ba6bb37b | 184 | }; |
el17my | 7:88c4ba6bb37b | 185 | #endif |