Mochu Yao explorer game

Dependencies:   mbed

Committer:
el17my
Date:
Mon Apr 27 14:29:06 2020 +0000
Revision:
10:559487aac60e
Parent:
8:201ef0618b7d
Child:
11:6740108a0825
add class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17my 7:88c4ba6bb37b 1 /** surface
el17my 7:88c4ba6bb37b 2 * @the surface file has three functions
el17my 7:88c4ba6bb37b 3 //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 4 //2 the line will be random length but must be suitable
el17my 7:88c4ba6bb37b 5 //3 makesure there are two surface for player to stay
el17my 7:88c4ba6bb37b 6 * @date April 22th 2020
el17my 7:88c4ba6bb37b 7 * @author Yaomochu
el17my 7:88c4ba6bb37b 8 */
el17my 10:559487aac60e 9
el17my 10:559487aac60e 10 /** Surface Class
el17my 10:559487aac60e 11
el17my 10:559487aac60e 12 @code
el17my 10:559487aac60e 13
el17my 10:559487aac60e 14 #include "mbed.h"
el17my 10:559487aac60e 15 #include "N5110.h"
el17my 10:559487aac60e 16 #include "Gamepad.h"
el17my 10:559487aac60e 17 #include "surface.h"
el17my 10:559487aac60e 18 #include <cstdlib>
el17my 10:559487aac60e 19 #include <ctime>
el17my 10:559487aac60e 20
el17my 10:559487aac60e 21 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
el17my 10:559487aac60e 22 Gamepad gamepad;
el17my 10:559487aac60e 23 Surface _surface;
el17my 10:559487aac60e 24
el17my 10:559487aac60e 25 Line line_1_value;
el17my 10:559487aac60e 26 Line line_2_value;
el17my 10:559487aac60e 27 Line line_3_value;
el17my 10:559487aac60e 28 Line line_4_value;
el17my 10:559487aac60e 29 Line line_5_value;
el17my 10:559487aac60e 30 Line line_6_value;
el17my 10:559487aac60e 31
el17my 10:559487aac60e 32 int main() {
el17my 10:559487aac60e 33 _surface.init(20,40);
el17my 10:559487aac60e 34 while(1) {
el17my 10:559487aac60e 35 //draw line 1
el17my 10:559487aac60e 36 _surface.line_1();
el17my 10:559487aac60e 37 line_1_value = _surface.getline_1();
el17my 10:559487aac60e 38 lcd.drawLine(line_1_value.left,line_1_value.y,line_1_value.right,line_1_value.y,FILL_BLACK);
el17my 10:559487aac60e 39 //draw line 2
el17my 10:559487aac60e 40 _surface.line_2();
el17my 10:559487aac60e 41 line_2_value = _surface.getline_2();
el17my 10:559487aac60e 42 lcd.drawLine(line_2_value.left,line_2_value.y,line_2_value.right,line_2_value.y,FILL_BLACK);
el17my 10:559487aac60e 43 //draw line 3
el17my 10:559487aac60e 44 _surface.line_3();
el17my 10:559487aac60e 45 line_3_value = _surface.getline_3();
el17my 10:559487aac60e 46 lcd.drawLine(line_3_value.left,line_3_value.y,line_3_value.right,line_3_value.y,FILL_BLACK);
el17my 10:559487aac60e 47 //draw line 4
el17my 10:559487aac60e 48 _surface.line_4();
el17my 10:559487aac60e 49 line_4_value = _surface.getline_4();
el17my 10:559487aac60e 50 lcd.drawLine(line_4_value.left,line_4_value.y,line_4_value.right,line_4_value.y,FILL_BLACK);
el17my 10:559487aac60e 51 //draw line 5
el17my 10:559487aac60e 52 _surface.line_5();
el17my 10:559487aac60e 53 line_3_value = _surface.getline_5();
el17my 10:559487aac60e 54 lcd.drawLine(line_5_value.left,line_5_value.y,line_5_value.right,line_5_value.y,FILL_BLACK);
el17my 10:559487aac60e 55 //draw line 6
el17my 10:559487aac60e 56 _surface.line_6();
el17my 10:559487aac60e 57 line_6_value = _surface.getline_6();
el17my 10:559487aac60e 58 lcd.drawLine(line_6_value.left,line_6_value.y,line_6_value.right,line_6_value.y,FILL_BLACK);
el17my 10:559487aac60e 59 }
el17my 10:559487aac60e 60 }
el17my 10:559487aac60e 61 @endcode
el17my 10:559487aac60e 62 */
el17my 10:559487aac60e 63
el17my 7:88c4ba6bb37b 64 #ifndef LINE_H
el17my 7:88c4ba6bb37b 65 #define LINE_H
el17my 7:88c4ba6bb37b 66
el17my 7:88c4ba6bb37b 67 #include "mbed.h"
el17my 7:88c4ba6bb37b 68 //the surface function is to creat the surface for player to stand on and move
el17my 7:88c4ba6bb37b 69 struct Line {
el17my 7:88c4ba6bb37b 70 int length;
el17my 7:88c4ba6bb37b 71 int left;
el17my 7:88c4ba6bb37b 72 int right;
el17my 7:88c4ba6bb37b 73 int y;
el17my 7:88c4ba6bb37b 74 };
el17my 7:88c4ba6bb37b 75 //the line structer will have four main elements
el17my 7:88c4ba6bb37b 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