Mochu Yao explorer game
Dependencies: mbed
explorer/explorer.h@27:354d91d59b6d, 2020-04-28 (annotated)
- Committer:
- el17my
- Date:
- Tue Apr 28 17:58:00 2020 +0000
- Revision:
- 27:354d91d59b6d
- Parent:
- 26:4d193529b447
- Child:
- 30:65e639ace415
4.29
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 _r_flag; |
el17my | 27:354d91d59b6d | 38 | bool _start_flag; |
el17my | 27:354d91d59b6d | 39 | int _speed; |
el17my | 27:354d91d59b6d | 40 | int _jump_height; |
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 | 27:354d91d59b6d | 54 | _player.set_y_coordinate(false, _jump_height); } |
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 | _r_flag = _player.get_reset_flag(); |
el17my | 27:354d91d59b6d | 69 | |
el17my | 27:354d91d59b6d | 70 | lcd.drawSprite(_player_x,_player_y,10,10,(int *)_player.get_form(_explorer_sprite));//draw the player |
el17my | 27:354d91d59b6d | 71 | } |
el17my | 27:354d91d59b6d | 72 | } |
el17my | 27:354d91d59b6d | 73 | |
el17my | 27:354d91d59b6d | 74 | * @endcode |
el17my | 27:354d91d59b6d | 75 | */ |
el17my | 13:30330d61f09c | 76 | |
el17my | 7:88c4ba6bb37b | 77 | class Explorer { |
el17my | 7:88c4ba6bb37b | 78 | public: |
el17my | 7:88c4ba6bb37b | 79 | Explorer(); |
el17my | 7:88c4ba6bb37b | 80 | //Constructor |
el17my | 7:88c4ba6bb37b | 81 | ~Explorer(); |
el17my | 7:88c4ba6bb37b | 82 | //Destructor |
el17my | 8:201ef0618b7d | 83 | void init(); |
el17my | 7:88c4ba6bb37b | 84 | void set_x_coordinate(float joy_x, int speed, Player_direction direction); |
el17my | 8:201ef0618b7d | 85 | void set_y_coordinate(bool ifjump, int jump_height); |
el17my | 7:88c4ba6bb37b | 86 | int get_y(); |
el17my | 7:88c4ba6bb37b | 87 | |
el17my | 7:88c4ba6bb37b | 88 | int get_x(); |
el17my | 7:88c4ba6bb37b | 89 | |
el17my | 7:88c4ba6bb37b | 90 | int get_speed(); |
el17my | 7:88c4ba6bb37b | 91 | |
el17my | 7:88c4ba6bb37b | 92 | int get_jump_height(); |
el17my | 7:88c4ba6bb37b | 93 | |
el17my | 7:88c4ba6bb37b | 94 | Player_direction get_direction(); |
el17my | 7:88c4ba6bb37b | 95 | |
el17my | 8:201ef0618b7d | 96 | Explorer_sprite get_explorer_sprite(); |
el17my | 7:88c4ba6bb37b | 97 | |
el17my | 8:201ef0618b7d | 98 | int * get_form(Explorer_sprite sprite); |
el17my | 7:88c4ba6bb37b | 99 | //this function is used to get the players form and print on the screen (same as the item file) |
el17my | 7:88c4ba6bb37b | 100 | |
el17my | 7:88c4ba6bb37b | 101 | void fall(bool f_flag, Gamepad &gamepad); |
el17my | 7:88c4ba6bb37b | 102 | //the fall flag need to add music to hint the player that the game is over |
el17my | 20:20e6ba54e15c | 103 | void reset_flag(bool flag); |
el17my | 7:88c4ba6bb37b | 104 | //the reset flag also need to add music to hint the player that the game has been reseted |
el17my | 7:88c4ba6bb37b | 105 | bool get_fall_flag(); |
el17my | 7:88c4ba6bb37b | 106 | |
el17my | 7:88c4ba6bb37b | 107 | bool get_reset_flag(); |
el17my | 7:88c4ba6bb37b | 108 | |
el17my | 7:88c4ba6bb37b | 109 | private: |
el17my | 7:88c4ba6bb37b | 110 | |
el17my | 23:7be9701fc1b8 | 111 | int _x; |
el17my | 23:7be9701fc1b8 | 112 | int _y; |
el17my | 23:7be9701fc1b8 | 113 | int _speed; |
el17my | 23:7be9701fc1b8 | 114 | int _jump_height; |
el17my | 23:7be9701fc1b8 | 115 | bool _f_flag; |
el17my | 23:7be9701fc1b8 | 116 | bool _r_flag; |
el17my | 12:bb89733cc51a | 117 | Line _line_1; |
el17my | 12:bb89733cc51a | 118 | Line _line_2; |
el17my | 12:bb89733cc51a | 119 | Line _line_3; |
el17my | 12:bb89733cc51a | 120 | Line _line_4; |
el17my | 12:bb89733cc51a | 121 | Line _line_5; |
el17my | 12:bb89733cc51a | 122 | Line _line_6; |
el17my | 12:bb89733cc51a | 123 | Player_direction _player_direction; |
el17my | 12:bb89733cc51a | 124 | Explorer_sprite _explorer_sprite; |
el17my | 7:88c4ba6bb37b | 125 | }; |
el17my | 7:88c4ba6bb37b | 126 | #endif |