Yao mochu
/
Explorer
explorer game
explorer/explorer.h@13:30330d61f09c, 2020-04-28 (annotated)
- Committer:
- el17my
- Date:
- Tue Apr 28 11:51:39 2020 +0000
- Revision:
- 13:30330d61f09c
- Parent:
- 12:bb89733cc51a
- Child:
- 14:5e73a6e34c17
4.28
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17my | 7:88c4ba6bb37b | 1 | /** explorer |
el17my | 7:88c4ba6bb37b | 2 | * @the explorer file has three functions |
el17my | 7:88c4ba6bb37b | 3 | 1 the movement of a explorer to jump and move in left or right direction |
el17my | 7:88c4ba6bb37b | 4 | 2 check fallen and collision |
el17my | 7:88c4ba6bb37b | 5 | 3 reset the game |
el17my | 7:88c4ba6bb37b | 6 | * @date April 15th 2020 |
el17my | 7:88c4ba6bb37b | 7 | * @author Yaomochu |
el17my | 7:88c4ba6bb37b | 8 | */ |
el17my | 11:6740108a0825 | 9 | #ifndef EXPLORER_H |
el17my | 11:6740108a0825 | 10 | #define EXPLORER_H |
el17my | 10:559487aac60e | 11 | |
el17my | 10:559487aac60e | 12 | /** Explorer Class |
el17my | 10:559487aac60e | 13 | @code |
el17my | 10:559487aac60e | 14 | |
el17my | 7:88c4ba6bb37b | 15 | #include "mbed.h" |
el17my | 10:559487aac60e | 16 | #include "N5110.h" |
el17my | 10:559487aac60e | 17 | #include "Gamepad.h" |
el17my | 10:559487aac60e | 18 | #include "explorer.h" |
el17my | 10:559487aac60e | 19 | #include <cstdlib> |
el17my | 10:559487aac60e | 20 | #include <ctime> |
el17my | 10:559487aac60e | 21 | |
el17my | 10:559487aac60e | 22 | Gamepad gamepad; |
el17my | 10:559487aac60e | 23 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
el17my | 10:559487aac60e | 24 | Explorer _player; |
el17my | 10:559487aac60e | 25 | |
el17my | 10:559487aac60e | 26 | int _player_x; |
el17my | 10:559487aac60e | 27 | int _player_y; |
el17my | 10:559487aac60e | 28 | bool _f_flag; |
el17my | 10:559487aac60e | 29 | bool _r_flag; |
el17my | 10:559487aac60e | 30 | bool _start_flag; |
el17my | 10:559487aac60e | 31 | int _speed; |
el17my | 10:559487aac60e | 32 | int _jump_height; |
el17my | 10:559487aac60e | 33 | Player_direction _player_direction; |
el17my | 10:559487aac60e | 34 | Explorer_sprite _explorer_sprite; |
el17my | 10:559487aac60e | 35 | |
el17my | 10:559487aac60e | 36 | int main() { |
el17my | 10:559487aac60e | 37 | _player.init(); |
el17my | 10:559487aac60e | 38 | _start_flag = true; |
el17my | 10:559487aac60e | 39 | while(1) { |
el17my | 10:559487aac60e | 40 | |
el17my | 10:559487aac60e | 41 | // Y coordinate |
el17my | 10:559487aac60e | 42 | if (_f_flag == true) |
el17my | 10:559487aac60e | 43 | { |
el17my | 10:559487aac60e | 44 | _player.fall(_f_flag, gamepad); |
el17my | 10:559487aac60e | 45 | } else { |
el17my | 10:559487aac60e | 46 | _player.set_y_coordinate(false, _jump_height); } |
el17my | 10:559487aac60e | 47 | _f_flag = _player.get_fall_flag(); |
el17my | 10:559487aac60e | 48 | _player_y = _player.get_y(); |
el17my | 10:559487aac60e | 49 | _jump_height = _player.get_jump_height(); |
el17my | 10:559487aac60e | 50 | |
el17my | 10:559487aac60e | 51 | // X coordinate |
el17my | 10:559487aac60e | 52 | _player_x = _player.get_x(); |
el17my | 10:559487aac60e | 53 | _speed = _player.get_speed(); |
el17my | 10:559487aac60e | 54 | _player.set_x_coordinate(1, _speed, _player_direction); |
el17my | 10:559487aac60e | 55 | |
el17my | 10:559487aac60e | 56 | |
el17my | 10:559487aac60e | 57 | //change in to a new direction. |
el17my | 10:559487aac60e | 58 | _player_direction = _player.get_direction(); |
el17my | 10:559487aac60e | 59 | |
el17my | 10:559487aac60e | 60 | _r_flag = _player.get_reset_flag(); |
el17my | 10:559487aac60e | 61 | |
el17my | 10:559487aac60e | 62 | lcd.drawSprite(_player_x,_player_y,10,10,(int *)_player.get_form(_explorer_sprite));//draw the player |
el17my | 10:559487aac60e | 63 | } |
el17my | 10:559487aac60e | 64 | } |
el17my | 13:30330d61f09c | 65 | |
el17my | 10:559487aac60e | 66 | @endcode |
el17my | 10:559487aac60e | 67 | */ |
el17my | 13:30330d61f09c | 68 | |
el17my | 12:bb89733cc51a | 69 | #include "mbed.h" |
el17my | 12:bb89733cc51a | 70 | #include "Gamepad.h" |
el17my | 12:bb89733cc51a | 71 | #include "surface.h" |
el17my | 7:88c4ba6bb37b | 72 | //use the enum to define the value we need for the explorer |
el17my | 8:201ef0618b7d | 73 | enum Explorer_sprite {Move_right,Move_left,Stand_left, Stand_right}; |
el17my | 7:88c4ba6bb37b | 74 | //we have four sprite form so we can define the sprite on the screen by using these enum |
el17my | 7:88c4ba6bb37b | 75 | //the explorer's direction |
el17my | 7:88c4ba6bb37b | 76 | enum Player_direction {right,left}; |
el17my | 7:88c4ba6bb37b | 77 | |
el17my | 7:88c4ba6bb37b | 78 | class Explorer { |
el17my | 7:88c4ba6bb37b | 79 | public: |
el17my | 7:88c4ba6bb37b | 80 | Explorer(); |
el17my | 7:88c4ba6bb37b | 81 | //Constructor |
el17my | 7:88c4ba6bb37b | 82 | ~Explorer(); |
el17my | 7:88c4ba6bb37b | 83 | //Destructor |
el17my | 8:201ef0618b7d | 84 | void init(); |
el17my | 7:88c4ba6bb37b | 85 | void set_x_coordinate(float joy_x, int speed, Player_direction direction); |
el17my | 8:201ef0618b7d | 86 | void set_y_coordinate(bool ifjump, int jump_height); |
el17my | 7:88c4ba6bb37b | 87 | int get_y(); |
el17my | 7:88c4ba6bb37b | 88 | |
el17my | 7:88c4ba6bb37b | 89 | int get_x(); |
el17my | 7:88c4ba6bb37b | 90 | |
el17my | 7:88c4ba6bb37b | 91 | int get_speed(); |
el17my | 7:88c4ba6bb37b | 92 | |
el17my | 7:88c4ba6bb37b | 93 | int get_jump_height(); |
el17my | 7:88c4ba6bb37b | 94 | |
el17my | 7:88c4ba6bb37b | 95 | Player_direction get_direction(); |
el17my | 7:88c4ba6bb37b | 96 | |
el17my | 8:201ef0618b7d | 97 | Explorer_sprite get_explorer_sprite(); |
el17my | 7:88c4ba6bb37b | 98 | |
el17my | 8:201ef0618b7d | 99 | int * get_form(Explorer_sprite sprite); |
el17my | 7:88c4ba6bb37b | 100 | //this function is used to get the players form and print on the screen (same as the item file) |
el17my | 7:88c4ba6bb37b | 101 | |
el17my | 7:88c4ba6bb37b | 102 | void fall(bool f_flag, Gamepad &gamepad); |
el17my | 7:88c4ba6bb37b | 103 | //the fall flag need to add music to hint the player that the game is over |
el17my | 8:201ef0618b7d | 104 | void reset_flag(bool flag,Gamepad &gamepad); |
el17my | 7:88c4ba6bb37b | 105 | //the reset flag also need to add music to hint the player that the game has been reseted |
el17my | 7:88c4ba6bb37b | 106 | bool get_fall_flag(); |
el17my | 7:88c4ba6bb37b | 107 | |
el17my | 7:88c4ba6bb37b | 108 | bool get_reset_flag(); |
el17my | 7:88c4ba6bb37b | 109 | |
el17my | 7:88c4ba6bb37b | 110 | private: |
el17my | 7:88c4ba6bb37b | 111 | |
el17my | 7:88c4ba6bb37b | 112 | int _x; |
el17my | 7:88c4ba6bb37b | 113 | int _y; |
el17my | 7:88c4ba6bb37b | 114 | int _speed; |
el17my | 7:88c4ba6bb37b | 115 | int _jump_height; |
el17my | 7:88c4ba6bb37b | 116 | bool _f_flag; |
el17my | 7:88c4ba6bb37b | 117 | bool _r_flag; |
el17my | 12:bb89733cc51a | 118 | Line _line_1; |
el17my | 12:bb89733cc51a | 119 | Line _line_2; |
el17my | 12:bb89733cc51a | 120 | Line _line_3; |
el17my | 12:bb89733cc51a | 121 | Line _line_4; |
el17my | 12:bb89733cc51a | 122 | Line _line_5; |
el17my | 12:bb89733cc51a | 123 | Line _line_6; |
el17my | 12:bb89733cc51a | 124 | Player_direction _player_direction; |
el17my | 12:bb89733cc51a | 125 | Explorer_sprite _explorer_sprite; |
el17my | 7:88c4ba6bb37b | 126 | }; |
el17my | 7:88c4ba6bb37b | 127 | #endif |