Mochu Yao explorer game
Dependencies: mbed
Surface/surface.h@24:d7a794fd1228, 2020-04-28 (annotated)
- Committer:
- el17my
- Date:
- Tue Apr 28 17:24:20 2020 +0000
- Revision:
- 24:d7a794fd1228
- Parent:
- 23:7be9701fc1b8
- Child:
- 26:4d193529b447
4.29
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 | 10:559487aac60e | 5 | |
el17my | 11:6740108a0825 | 6 | struct Line { |
el17my | 11:6740108a0825 | 7 | int length; |
el17my | 11:6740108a0825 | 8 | int left; |
el17my | 11:6740108a0825 | 9 | int right; |
el17my | 11:6740108a0825 | 10 | int y; |
el17my | 11:6740108a0825 | 11 | }; |
el17my | 11:6740108a0825 | 12 | //the line structer will have four main elements |
el17my | 11:6740108a0825 | 13 | |
el17my | 23:7be9701fc1b8 | 14 | /** surface Class |
el17my | 23:7be9701fc1b8 | 15 | * @1 the leftside of the line move toward right then the rightside should also move to the right to keep the length |
el17my | 23:7be9701fc1b8 | 16 | * @2 the line will be random length but must be suitable |
el17my | 23:7be9701fc1b8 | 17 | * @3 makesure there are two surface for player to stay |
el17my | 23:7be9701fc1b8 | 18 | * @date April 22th 2020 |
el17my | 23:7be9701fc1b8 | 19 | * @author Yaomochu |
el17my | 23:7be9701fc1b8 | 20 | |
el17my | 24:d7a794fd1228 | 21 | @code |
el17my | 10:559487aac60e | 22 | |
el17my | 10:559487aac60e | 23 | #include "mbed.h" |
el17my | 10:559487aac60e | 24 | #include "N5110.h" |
el17my | 10:559487aac60e | 25 | #include "Gamepad.h" |
el17my | 10:559487aac60e | 26 | #include "surface.h" |
el17my | 10:559487aac60e | 27 | #include <cstdlib> |
el17my | 10:559487aac60e | 28 | #include <ctime> |
el17my | 10:559487aac60e | 29 | |
el17my | 10:559487aac60e | 30 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
el17my | 10:559487aac60e | 31 | Gamepad gamepad; |
el17my | 10:559487aac60e | 32 | Surface _surface; |
el17my | 10:559487aac60e | 33 | |
el17my | 10:559487aac60e | 34 | Line line_1_value; |
el17my | 10:559487aac60e | 35 | Line line_2_value; |
el17my | 10:559487aac60e | 36 | Line line_3_value; |
el17my | 10:559487aac60e | 37 | Line line_4_value; |
el17my | 10:559487aac60e | 38 | Line line_5_value; |
el17my | 10:559487aac60e | 39 | Line line_6_value; |
el17my | 10:559487aac60e | 40 | |
el17my | 10:559487aac60e | 41 | int main() { |
el17my | 10:559487aac60e | 42 | _surface.init(20,40); |
el17my | 10:559487aac60e | 43 | while(1) { |
el17my | 10:559487aac60e | 44 | //draw line 1 |
el17my | 10:559487aac60e | 45 | _surface.line_1(); |
el17my | 10:559487aac60e | 46 | line_1_value = _surface.getline_1(); |
el17my | 10:559487aac60e | 47 | lcd.drawLine(line_1_value.left,line_1_value.y,line_1_value.right,line_1_value.y,FILL_BLACK); |
el17my | 10:559487aac60e | 48 | //draw line 2 |
el17my | 10:559487aac60e | 49 | _surface.line_2(); |
el17my | 10:559487aac60e | 50 | line_2_value = _surface.getline_2(); |
el17my | 10:559487aac60e | 51 | lcd.drawLine(line_2_value.left,line_2_value.y,line_2_value.right,line_2_value.y,FILL_BLACK); |
el17my | 10:559487aac60e | 52 | //draw line 3 |
el17my | 10:559487aac60e | 53 | _surface.line_3(); |
el17my | 10:559487aac60e | 54 | line_3_value = _surface.getline_3(); |
el17my | 10:559487aac60e | 55 | lcd.drawLine(line_3_value.left,line_3_value.y,line_3_value.right,line_3_value.y,FILL_BLACK); |
el17my | 10:559487aac60e | 56 | //draw line 4 |
el17my | 10:559487aac60e | 57 | _surface.line_4(); |
el17my | 10:559487aac60e | 58 | line_4_value = _surface.getline_4(); |
el17my | 10:559487aac60e | 59 | lcd.drawLine(line_4_value.left,line_4_value.y,line_4_value.right,line_4_value.y,FILL_BLACK); |
el17my | 10:559487aac60e | 60 | //draw line 5 |
el17my | 10:559487aac60e | 61 | _surface.line_5(); |
el17my | 10:559487aac60e | 62 | line_3_value = _surface.getline_5(); |
el17my | 10:559487aac60e | 63 | lcd.drawLine(line_5_value.left,line_5_value.y,line_5_value.right,line_5_value.y,FILL_BLACK); |
el17my | 10:559487aac60e | 64 | //draw line 6 |
el17my | 10:559487aac60e | 65 | _surface.line_6(); |
el17my | 10:559487aac60e | 66 | line_6_value = _surface.getline_6(); |
el17my | 10:559487aac60e | 67 | lcd.drawLine(line_6_value.left,line_6_value.y,line_6_value.right,line_6_value.y,FILL_BLACK); |
el17my | 10:559487aac60e | 68 | } |
el17my | 10:559487aac60e | 69 | } |
el17my | 23:7be9701fc1b8 | 70 | |
el17my | 24:d7a794fd1228 | 71 | @endcode |
el17my | 10:559487aac60e | 72 | */ |
el17my | 10:559487aac60e | 73 | |
el17my | 7:88c4ba6bb37b | 74 | //the surface function is to creat the surface for player to stand on and move |
el17my | 21:349c70c8a7de | 75 | class Surface |
el17my | 7:88c4ba6bb37b | 76 | { |
el17my | 7:88c4ba6bb37b | 77 | public: |
el17my | 7:88c4ba6bb37b | 78 | Surface(); |
el17my | 7:88c4ba6bb37b | 79 | ~Surface(); |
el17my | 8:201ef0618b7d | 80 | void init(int y1, int y2); |
el17my | 7:88c4ba6bb37b | 81 | //init the line at first to set the initial position |
el17my | 7:88c4ba6bb37b | 82 | void line_1(); |
el17my | 7:88c4ba6bb37b | 83 | void line_2(); |
el17my | 7:88c4ba6bb37b | 84 | void line_3(); |
el17my | 7:88c4ba6bb37b | 85 | void line_4(); |
el17my | 7:88c4ba6bb37b | 86 | void line_5(); |
el17my | 7:88c4ba6bb37b | 87 | void line_6(); |
el17my | 8:201ef0618b7d | 88 | Line getline_1(); |
el17my | 8:201ef0618b7d | 89 | Line getline_2(); |
el17my | 8:201ef0618b7d | 90 | Line getline_3(); |
el17my | 8:201ef0618b7d | 91 | Line getline_4(); |
el17my | 8:201ef0618b7d | 92 | Line getline_5(); |
el17my | 8:201ef0618b7d | 93 | Line getline_6(); |
el17my | 7:88c4ba6bb37b | 94 | |
el17my | 7:88c4ba6bb37b | 95 | private: |
el17my | 7:88c4ba6bb37b | 96 | Line _line_1; |
el17my | 7:88c4ba6bb37b | 97 | Line _line_2; |
el17my | 7:88c4ba6bb37b | 98 | Line _line_3; |
el17my | 7:88c4ba6bb37b | 99 | Line _line_4; |
el17my | 7:88c4ba6bb37b | 100 | Line _line_5; |
el17my | 7:88c4ba6bb37b | 101 | Line _line_6; |
el17my | 7:88c4ba6bb37b | 102 | |
el17my | 7:88c4ba6bb37b | 103 | }; |
el17my | 7:88c4ba6bb37b | 104 | #endif |
el17my | 7:88c4ba6bb37b | 105 |