Mochu Yao explorer game
Dependencies: mbed
Surface/surface.h@38:42ff379fa48c, 2020-05-15 (annotated)
- Committer:
- el17my
- Date:
- Fri May 15 02:47:10 2020 +0000
- Revision:
- 38:42ff379fa48c
- Parent:
- 29:2d592452e3fb
the latest version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17my | 11:6740108a0825 | 1 | #ifndef LINE_H |
el17my | 11:6740108a0825 | 2 | #define LINE_H |
el17my | 11:6740108a0825 | 3 | |
el17my | 11:6740108a0825 | 4 | #include "mbed.h" |
el17my | 28:4a1260ad0346 | 5 | /** Line struct */ |
el17my | 11:6740108a0825 | 6 | struct Line { |
el17my | 29:2d592452e3fb | 7 | int length;/**< the length of the line. */ |
el17my | 29:2d592452e3fb | 8 | int left;/**< the leftside of the line. */ |
el17my | 29:2d592452e3fb | 9 | int right;/**< the rightside of the line. */ |
el17my | 29:2d592452e3fb | 10 | int y;/**< the height of the line. */ |
el17my | 11:6740108a0825 | 11 | }; |
el17my | 23:7be9701fc1b8 | 12 | |
el17my | 27:354d91d59b6d | 13 | //the line structer will have four main elements |
el17my | 27:354d91d59b6d | 14 | |
el17my | 27:354d91d59b6d | 15 | /** surface Class |
el17my | 27:354d91d59b6d | 16 | * @1 the leftside of the line move toward right then the rightside should also move to the right to keep the length |
el17my | 27:354d91d59b6d | 17 | * @2 the line will be random length but must be suitable |
el17my | 27:354d91d59b6d | 18 | * @3 makesure there are two surface for player to stay |
el17my | 27:354d91d59b6d | 19 | * @date April 22th 2020 |
el17my | 27:354d91d59b6d | 20 | * @author Yaomochu |
el17my | 10:559487aac60e | 21 | |
el17my | 27:354d91d59b6d | 22 | @code |
el17my | 27:354d91d59b6d | 23 | |
el17my | 27:354d91d59b6d | 24 | #include "mbed.h" |
el17my | 27:354d91d59b6d | 25 | #include "N5110.h" |
el17my | 27:354d91d59b6d | 26 | #include "Gamepad.h" |
el17my | 27:354d91d59b6d | 27 | #include "surface.h" |
el17my | 27:354d91d59b6d | 28 | #include <cstdlib> |
el17my | 27:354d91d59b6d | 29 | #include <ctime> |
el17my | 27:354d91d59b6d | 30 | |
el17my | 27:354d91d59b6d | 31 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
el17my | 27:354d91d59b6d | 32 | Gamepad gamepad; |
el17my | 27:354d91d59b6d | 33 | Surface _surface; |
el17my | 27:354d91d59b6d | 34 | |
el17my | 27:354d91d59b6d | 35 | Line line_1_value; |
el17my | 27:354d91d59b6d | 36 | Line line_2_value; |
el17my | 27:354d91d59b6d | 37 | Line line_3_value; |
el17my | 27:354d91d59b6d | 38 | Line line_4_value; |
el17my | 27:354d91d59b6d | 39 | Line line_5_value; |
el17my | 27:354d91d59b6d | 40 | Line line_6_value; |
el17my | 27:354d91d59b6d | 41 | |
el17my | 27:354d91d59b6d | 42 | int main() { |
el17my | 27:354d91d59b6d | 43 | _surface.init(20,40); |
el17my | 27:354d91d59b6d | 44 | while(1) { |
el17my | 27:354d91d59b6d | 45 | //draw line 1 |
el17my | 27:354d91d59b6d | 46 | _surface.line_1(); |
el17my | 27:354d91d59b6d | 47 | line_1_value = _surface.getline_1(); |
el17my | 27:354d91d59b6d | 48 | lcd.drawLine(line_1_value.left,line_1_value.y,line_1_value.right,line_1_value.y,FILL_BLACK); |
el17my | 27:354d91d59b6d | 49 | //draw line 2 |
el17my | 27:354d91d59b6d | 50 | _surface.line_2(); |
el17my | 27:354d91d59b6d | 51 | line_2_value = _surface.getline_2(); |
el17my | 27:354d91d59b6d | 52 | lcd.drawLine(line_2_value.left,line_2_value.y,line_2_value.right,line_2_value.y,FILL_BLACK); |
el17my | 27:354d91d59b6d | 53 | //draw line 3 |
el17my | 27:354d91d59b6d | 54 | _surface.line_3(); |
el17my | 27:354d91d59b6d | 55 | line_3_value = _surface.getline_3(); |
el17my | 27:354d91d59b6d | 56 | lcd.drawLine(line_3_value.left,line_3_value.y,line_3_value.right,line_3_value.y,FILL_BLACK); |
el17my | 27:354d91d59b6d | 57 | //draw line 4 |
el17my | 27:354d91d59b6d | 58 | _surface.line_4(); |
el17my | 27:354d91d59b6d | 59 | line_4_value = _surface.getline_4(); |
el17my | 27:354d91d59b6d | 60 | lcd.drawLine(line_4_value.left,line_4_value.y,line_4_value.right,line_4_value.y,FILL_BLACK); |
el17my | 27:354d91d59b6d | 61 | //draw line 5 |
el17my | 27:354d91d59b6d | 62 | _surface.line_5(); |
el17my | 27:354d91d59b6d | 63 | line_3_value = _surface.getline_5(); |
el17my | 27:354d91d59b6d | 64 | lcd.drawLine(line_5_value.left,line_5_value.y,line_5_value.right,line_5_value.y,FILL_BLACK); |
el17my | 27:354d91d59b6d | 65 | //draw line 6 |
el17my | 27:354d91d59b6d | 66 | _surface.line_6(); |
el17my | 27:354d91d59b6d | 67 | line_6_value = _surface.getline_6(); |
el17my | 27:354d91d59b6d | 68 | lcd.drawLine(line_6_value.left,line_6_value.y,line_6_value.right,line_6_value.y,FILL_BLACK); |
el17my | 27:354d91d59b6d | 69 | } |
el17my | 27:354d91d59b6d | 70 | } |
el17my | 27:354d91d59b6d | 71 | |
el17my | 27:354d91d59b6d | 72 | @endcode |
el17my | 27:354d91d59b6d | 73 | */ |
el17my | 28:4a1260ad0346 | 74 | |
el17my | 21:349c70c8a7de | 75 | class Surface |
el17my | 7:88c4ba6bb37b | 76 | { |
el17my | 7:88c4ba6bb37b | 77 | public: |
el17my | 28:4a1260ad0346 | 78 | // Constructor and Destructor. |
el17my | 28:4a1260ad0346 | 79 | /** |
el17my | 28:4a1260ad0346 | 80 | * @brief Constructor @details Non user specified. |
el17my | 28:4a1260ad0346 | 81 | */ |
el17my | 7:88c4ba6bb37b | 82 | Surface(); |
el17my | 28:4a1260ad0346 | 83 | /** |
el17my | 28:4a1260ad0346 | 84 | * @brief Destructor @details Non user specified. |
el17my | 28:4a1260ad0346 | 85 | */ |
el17my | 7:88c4ba6bb37b | 86 | ~Surface(); |
el17my | 28:4a1260ad0346 | 87 | /** |
el17my | 28:4a1260ad0346 | 88 | * @brief init the line at first to set the initial position. |
el17my | 28:4a1260ad0346 | 89 | * @param y1 @details the lower line height. |
el17my | 28:4a1260ad0346 | 90 | * @param y2 @details the upper line height. |
el17my | 28:4a1260ad0346 | 91 | */ |
el17my | 8:201ef0618b7d | 92 | void init(int y1, int y2); |
el17my | 28:4a1260ad0346 | 93 | /** |
el17my | 28:4a1260ad0346 | 94 | * @brief set line1 movement. |
el17my | 28:4a1260ad0346 | 95 | */ |
el17my | 7:88c4ba6bb37b | 96 | void line_1(); |
el17my | 28:4a1260ad0346 | 97 | /** |
el17my | 28:4a1260ad0346 | 98 | * @brief set line2 movement. |
el17my | 28:4a1260ad0346 | 99 | */ |
el17my | 7:88c4ba6bb37b | 100 | void line_2(); |
el17my | 28:4a1260ad0346 | 101 | /** |
el17my | 28:4a1260ad0346 | 102 | * @brief set line3 movement. |
el17my | 28:4a1260ad0346 | 103 | */ |
el17my | 7:88c4ba6bb37b | 104 | void line_3(); |
el17my | 28:4a1260ad0346 | 105 | /** |
el17my | 28:4a1260ad0346 | 106 | * @brief set line4 movement. |
el17my | 28:4a1260ad0346 | 107 | */ |
el17my | 7:88c4ba6bb37b | 108 | void line_4(); |
el17my | 28:4a1260ad0346 | 109 | /** |
el17my | 28:4a1260ad0346 | 110 | * @brief set line5 movement. |
el17my | 28:4a1260ad0346 | 111 | */ |
el17my | 7:88c4ba6bb37b | 112 | void line_5(); |
el17my | 28:4a1260ad0346 | 113 | /** |
el17my | 28:4a1260ad0346 | 114 | * @brief set line6 movement. |
el17my | 28:4a1260ad0346 | 115 | */ |
el17my | 7:88c4ba6bb37b | 116 | void line_6(); |
el17my | 28:4a1260ad0346 | 117 | // Accessors. |
el17my | 28:4a1260ad0346 | 118 | /** |
el17my | 28:4a1260ad0346 | 119 | * @brief Gets line 1. |
el17my | 28:4a1260ad0346 | 120 | * @returns Line 1 (type: struct, Line) |
el17my | 28:4a1260ad0346 | 121 | */ |
el17my | 8:201ef0618b7d | 122 | Line getline_1(); |
el17my | 28:4a1260ad0346 | 123 | /** |
el17my | 28:4a1260ad0346 | 124 | * @brief Gets line 2. |
el17my | 28:4a1260ad0346 | 125 | * @returns Line 2 (type: struct, Line) |
el17my | 28:4a1260ad0346 | 126 | */ |
el17my | 8:201ef0618b7d | 127 | Line getline_2(); |
el17my | 28:4a1260ad0346 | 128 | /** |
el17my | 28:4a1260ad0346 | 129 | * @brief Gets line 3. |
el17my | 28:4a1260ad0346 | 130 | * @returns Line 3 (type: struct, Line) |
el17my | 28:4a1260ad0346 | 131 | */ |
el17my | 8:201ef0618b7d | 132 | Line getline_3(); |
el17my | 28:4a1260ad0346 | 133 | /** |
el17my | 28:4a1260ad0346 | 134 | * @brief Gets line 4. |
el17my | 28:4a1260ad0346 | 135 | * @returns Line 4 (type: struct, Line) |
el17my | 28:4a1260ad0346 | 136 | */ |
el17my | 8:201ef0618b7d | 137 | Line getline_4(); |
el17my | 28:4a1260ad0346 | 138 | /** |
el17my | 28:4a1260ad0346 | 139 | * @brief Gets line 5. |
el17my | 28:4a1260ad0346 | 140 | * @returns Line 5 (type: struct, Line) |
el17my | 28:4a1260ad0346 | 141 | */ |
el17my | 8:201ef0618b7d | 142 | Line getline_5(); |
el17my | 28:4a1260ad0346 | 143 | /** |
el17my | 28:4a1260ad0346 | 144 | * @brief Gets line 6. |
el17my | 28:4a1260ad0346 | 145 | * @returns Line 6 (type: struct, Line) |
el17my | 28:4a1260ad0346 | 146 | */ |
el17my | 8:201ef0618b7d | 147 | Line getline_6(); |
el17my | 7:88c4ba6bb37b | 148 | |
el17my | 7:88c4ba6bb37b | 149 | private: |
el17my | 7:88c4ba6bb37b | 150 | Line _line_1; |
el17my | 7:88c4ba6bb37b | 151 | Line _line_2; |
el17my | 7:88c4ba6bb37b | 152 | Line _line_3; |
el17my | 7:88c4ba6bb37b | 153 | Line _line_4; |
el17my | 7:88c4ba6bb37b | 154 | Line _line_5; |
el17my | 7:88c4ba6bb37b | 155 | Line _line_6; |
el17my | 7:88c4ba6bb37b | 156 | |
el17my | 7:88c4ba6bb37b | 157 | }; |
el17my | 7:88c4ba6bb37b | 158 | #endif |
el17my | 7:88c4ba6bb37b | 159 |