Mochu Yao explorer game
Dependencies: mbed
Surface/surface.cpp@8:201ef0618b7d, 2020-04-27 (annotated)
- Committer:
- el17my
- Date:
- Mon Apr 27 08:41:29 2020 +0000
- Revision:
- 8:201ef0618b7d
- Parent:
- line/surface.cpp@7:88c4ba6bb37b
- Child:
- 17:1b4ecc01b79f
creating the menu
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17my | 7:88c4ba6bb37b | 1 | #include "surface.h" |
el17my | 7:88c4ba6bb37b | 2 | |
el17my | 7:88c4ba6bb37b | 3 | // Constructor and destructor. |
el17my | 7:88c4ba6bb37b | 4 | Surface::Surface() {} |
el17my | 7:88c4ba6bb37b | 5 | Surface::~Surface() {} |
el17my | 7:88c4ba6bb37b | 6 | |
el17my | 8:201ef0618b7d | 7 | void Surface::init(int y1, int y2) { |
el17my | 7:88c4ba6bb37b | 8 | //makesure that each line can not be constant or it will be too easy |
el17my | 7:88c4ba6bb37b | 9 | _line_1.left = 0; |
el17my | 7:88c4ba6bb37b | 10 | _line_1.right = 25; |
el17my | 7:88c4ba6bb37b | 11 | _line_1.y = y1; |
el17my | 7:88c4ba6bb37b | 12 | _line_1.length = 25; |
el17my | 7:88c4ba6bb37b | 13 | _line_2.left = 30; |
el17my | 7:88c4ba6bb37b | 14 | _line_2.right = 50; |
el17my | 7:88c4ba6bb37b | 15 | _line_2.y = y1; |
el17my | 7:88c4ba6bb37b | 16 | _line_2.length = 20; |
el17my | 7:88c4ba6bb37b | 17 | _line_3.left = 65; |
el17my | 7:88c4ba6bb37b | 18 | _line_3.right = 80; |
el17my | 7:88c4ba6bb37b | 19 | _line_3.y = y1; |
el17my | 7:88c4ba6bb37b | 20 | _line_3.length = 15; |
el17my | 7:88c4ba6bb37b | 21 | //the line 1 to line 3 is on the lower level and than the line 4 to line 5 is on the upper level |
el17my | 7:88c4ba6bb37b | 22 | // ---line 4--- ---line 5--- ---line 6--- |
el17my | 7:88c4ba6bb37b | 23 | // ---line 3--- ---line 2--- ---line 1--- |
el17my | 7:88c4ba6bb37b | 24 | _line_4.left = 0; |
el17my | 7:88c4ba6bb37b | 25 | _line_4.right = 20; |
el17my | 7:88c4ba6bb37b | 26 | _line_4.y = y2; |
el17my | 7:88c4ba6bb37b | 27 | _line_4.length = 20; |
el17my | 7:88c4ba6bb37b | 28 | _line_5.left = 25; |
el17my | 7:88c4ba6bb37b | 29 | _line_5.right = 50; |
el17my | 7:88c4ba6bb37b | 30 | _line_5.y = y2; |
el17my | 7:88c4ba6bb37b | 31 | _line_5.length = 25; |
el17my | 7:88c4ba6bb37b | 32 | _line_6.left = 60; |
el17my | 7:88c4ba6bb37b | 33 | _line_6.right = 80; |
el17my | 7:88c4ba6bb37b | 34 | _line_6.y = y2; |
el17my | 7:88c4ba6bb37b | 35 | _line_6.length = 20; |
el17my | 7:88c4ba6bb37b | 36 | }; |
el17my | 7:88c4ba6bb37b | 37 | //the line need to move form right to left so the line_1 function should have these functions |
el17my | 7:88c4ba6bb37b | 38 | //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 | 39 | //2 the line will be random length but must be suitable |
el17my | 7:88c4ba6bb37b | 40 | //3 makesure there are two surface for player to stay |
el17my | 8:201ef0618b7d | 41 | void Surface::line_1() { |
el17my | 7:88c4ba6bb37b | 42 | if(_line_1.left > 0) { |
el17my | 7:88c4ba6bb37b | 43 | _line_1.left-- ;} |
el17my | 7:88c4ba6bb37b | 44 | //the left side will keep moving until it disappear on the screen which also means equal to zero |
el17my | 7:88c4ba6bb37b | 45 | if (_line_1.left + _line_1.length < 80) { |
el17my | 7:88c4ba6bb37b | 46 | _line_1.right-- ;} |
el17my | 7:88c4ba6bb37b | 47 | //this line is mainly for regeneration of the line because I want the line to first disapper and then appear on the another edge |
el17my | 7:88c4ba6bb37b | 48 | if (_line_1.right <= 0) { |
el17my | 7:88c4ba6bb37b | 49 | _line_1.right--; |
el17my | 7:88c4ba6bb37b | 50 | _line_1.left = 0; } |
el17my | 7:88c4ba6bb37b | 51 | //if the left edge of the line is zero it will keep zero until the right edge equals to zero |
el17my | 7:88c4ba6bb37b | 52 | if (_line_1.right <= 0) { |
el17my | 7:88c4ba6bb37b | 53 | _line_1.left = 80; |
el17my | 7:88c4ba6bb37b | 54 | _line_1.right = 80;} |
el17my | 7:88c4ba6bb37b | 55 | _line_1.length = (rand() %15) + 10; } |
el17my | 7:88c4ba6bb37b | 56 | |
el17my | 8:201ef0618b7d | 57 | void Surface::line_2() { |
el17my | 7:88c4ba6bb37b | 58 | if(_line_2.left > 0) { |
el17my | 7:88c4ba6bb37b | 59 | _line_2.left-- ;} |
el17my | 7:88c4ba6bb37b | 60 | //the left side will keep moving until it disappear on the screen which also means equal to zero |
el17my | 7:88c4ba6bb37b | 61 | if (_line_2.left + _line_1.length < 80) { |
el17my | 7:88c4ba6bb37b | 62 | _line_2.right-- ;} |
el17my | 7:88c4ba6bb37b | 63 | //this line is mainly for regeneration of the line because I want the line to first disapper and then appear on the another edge |
el17my | 7:88c4ba6bb37b | 64 | if (_line_2.right <= 0) { |
el17my | 7:88c4ba6bb37b | 65 | _line_2.right--; |
el17my | 7:88c4ba6bb37b | 66 | _line_2.left = 0; } |
el17my | 7:88c4ba6bb37b | 67 | //if the left edge of the line is zero it will keep zero until the right edge equals to zero |
el17my | 7:88c4ba6bb37b | 68 | if (_line_2.right <= 0) { |
el17my | 7:88c4ba6bb37b | 69 | _line_2.left = 80; |
el17my | 7:88c4ba6bb37b | 70 | _line_2.right = 80;} |
el17my | 7:88c4ba6bb37b | 71 | _line_2.length = (rand() %15) + 10; } |
el17my | 7:88c4ba6bb37b | 72 | |
el17my | 8:201ef0618b7d | 73 | void Surface::line_3() { |
el17my | 7:88c4ba6bb37b | 74 | if(_line_3.left > 0) { |
el17my | 7:88c4ba6bb37b | 75 | _line_3.left-- ;} |
el17my | 7:88c4ba6bb37b | 76 | //the left side will keep moving until it disappear on the screen which also means equal to zero |
el17my | 7:88c4ba6bb37b | 77 | if (_line_3.left + _line_1.length < 80) { |
el17my | 7:88c4ba6bb37b | 78 | _line_3.right-- ;} |
el17my | 7:88c4ba6bb37b | 79 | //this line is mainly for regeneration of the line because I want the line to first disapper and then appear on the another edge |
el17my | 7:88c4ba6bb37b | 80 | if (_line_3.right <= 0) { |
el17my | 7:88c4ba6bb37b | 81 | _line_3.right--; |
el17my | 7:88c4ba6bb37b | 82 | _line_3.left = 0; } |
el17my | 7:88c4ba6bb37b | 83 | //if the left edge of the line is zero it will keep zero until the right edge equals to zero |
el17my | 7:88c4ba6bb37b | 84 | if (_line_3.right <= 0) { |
el17my | 7:88c4ba6bb37b | 85 | _line_3.left = 80; |
el17my | 7:88c4ba6bb37b | 86 | _line_3.right = 80;} |
el17my | 7:88c4ba6bb37b | 87 | _line_3.length = (rand() %15) + 10; } |
el17my | 7:88c4ba6bb37b | 88 | |
el17my | 8:201ef0618b7d | 89 | void Surface::line_4() { |
el17my | 7:88c4ba6bb37b | 90 | if(_line_4.left > 0) { |
el17my | 7:88c4ba6bb37b | 91 | _line_4.left-- ;} |
el17my | 7:88c4ba6bb37b | 92 | //the left side will keep moving until it disappear on the screen which also means equal to zero |
el17my | 7:88c4ba6bb37b | 93 | if (_line_4.left + _line_1.length < 80) { |
el17my | 7:88c4ba6bb37b | 94 | _line_4.right-- ;} |
el17my | 7:88c4ba6bb37b | 95 | //this line is mainly for regeneration of the line because I want the line to first disapper and then appear on the another edge |
el17my | 7:88c4ba6bb37b | 96 | if (_line_4.right <= 0) { |
el17my | 7:88c4ba6bb37b | 97 | _line_4.right--; |
el17my | 7:88c4ba6bb37b | 98 | _line_4.left = 0; } |
el17my | 7:88c4ba6bb37b | 99 | //if the left edge of the line is zero it will keep zero until the right edge equals to zero |
el17my | 7:88c4ba6bb37b | 100 | if (_line_4.right <= 0) { |
el17my | 7:88c4ba6bb37b | 101 | _line_4.left = 80; |
el17my | 7:88c4ba6bb37b | 102 | _line_4.right = 80;} |
el17my | 7:88c4ba6bb37b | 103 | _line_4.length = (rand() %15) + 10; } |
el17my | 7:88c4ba6bb37b | 104 | |
el17my | 8:201ef0618b7d | 105 | void Surface::line_5() { |
el17my | 7:88c4ba6bb37b | 106 | if(_line_5.left > 0) { |
el17my | 7:88c4ba6bb37b | 107 | _line_5.left-- ;} |
el17my | 7:88c4ba6bb37b | 108 | //the left side will keep moving until it disappear on the screen which also means equal to zero |
el17my | 7:88c4ba6bb37b | 109 | if (_line_5.left + _line_1.length < 80) { |
el17my | 7:88c4ba6bb37b | 110 | _line_5.right-- ;} |
el17my | 7:88c4ba6bb37b | 111 | //this line is mainly for regeneration of the line because I want the line to first disapper and then appear on the another edge |
el17my | 7:88c4ba6bb37b | 112 | if (_line_5.right <= 0) { |
el17my | 7:88c4ba6bb37b | 113 | _line_5.right--; |
el17my | 7:88c4ba6bb37b | 114 | _line_5.left = 0; } |
el17my | 7:88c4ba6bb37b | 115 | //if the left edge of the line is zero it will keep zero until the right edge equals to zero |
el17my | 7:88c4ba6bb37b | 116 | if (_line_5.right <= 0) { |
el17my | 7:88c4ba6bb37b | 117 | _line_5.left = 80; |
el17my | 7:88c4ba6bb37b | 118 | _line_5.right = 80;} |
el17my | 7:88c4ba6bb37b | 119 | _line_5.length = (rand() %15) + 10; } |
el17my | 7:88c4ba6bb37b | 120 | |
el17my | 8:201ef0618b7d | 121 | void Surface::line_6() { |
el17my | 7:88c4ba6bb37b | 122 | if(_line_6.left > 0) { |
el17my | 7:88c4ba6bb37b | 123 | _line_6.left-- ;} |
el17my | 7:88c4ba6bb37b | 124 | //the left side will keep moving until it disappear on the screen which also means equal to zero |
el17my | 7:88c4ba6bb37b | 125 | if (_line_6.left + _line_1.length < 80) { |
el17my | 7:88c4ba6bb37b | 126 | _line_6.right-- ;} |
el17my | 7:88c4ba6bb37b | 127 | //this line is mainly for regeneration of the line because I want the line to first disapper and then appear on the another edge |
el17my | 7:88c4ba6bb37b | 128 | if (_line_6.right <= 0) { |
el17my | 7:88c4ba6bb37b | 129 | _line_6.right--; |
el17my | 7:88c4ba6bb37b | 130 | _line_6.left = 0; } |
el17my | 7:88c4ba6bb37b | 131 | //if the left edge of the line is zero it will keep zero until the right edge equals to zero |
el17my | 7:88c4ba6bb37b | 132 | if (_line_6.right <= 0) { |
el17my | 7:88c4ba6bb37b | 133 | _line_6.left = 80; |
el17my | 7:88c4ba6bb37b | 134 | _line_6.right = 80;} |
el17my | 7:88c4ba6bb37b | 135 | _line_6.length = (rand() %15) + 10; } |
el17my | 7:88c4ba6bb37b | 136 | |
el17my | 7:88c4ba6bb37b | 137 | Line Surface::getline_1(){return _line_1;} |
el17my | 7:88c4ba6bb37b | 138 | Line Surface::getline_2(){return _line_2;} |
el17my | 7:88c4ba6bb37b | 139 | Line Surface::getline_3(){return _line_3;} |
el17my | 7:88c4ba6bb37b | 140 | Line Surface::getline_4(){return _line_4;} |
el17my | 7:88c4ba6bb37b | 141 | Line Surface::getline_5(){return _line_5;} |
el17my | 7:88c4ba6bb37b | 142 | Line Surface::getline_6(){return _line_6;} |
el17my | 7:88c4ba6bb37b | 143 | |
el17my | 7:88c4ba6bb37b | 144 | |
el17my | 7:88c4ba6bb37b | 145 | |
el17my | 7:88c4ba6bb37b | 146 | |
el17my | 7:88c4ba6bb37b | 147 |