Mochu Yao explorer game

Dependencies:   mbed

Committer:
el17my
Date:
Tue Apr 28 14:26:47 2020 +0000
Revision:
21:349c70c8a7de
Parent:
11:6740108a0825
Child:
23:7be9701fc1b8
4.28

Who changed what in which revision?

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