Mochu Yao explorer game

Dependencies:   mbed

Committer:
el17my
Date:
Tue Apr 28 17:58:00 2020 +0000
Revision:
27:354d91d59b6d
Parent:
26:4d193529b447
Child:
28:4a1260ad0346
4.29

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 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 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 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