Mochu Yao explorer game
Dependencies: mbed
Surface/surface.cpp@38:42ff379fa48c, 2020-05-15 (annotated)
- Committer:
- el17my
- Date:
- Fri May 15 02:47:10 2020 +0000
- Revision:
- 38:42ff379fa48c
- Parent:
- 33:ea83f08fa466
the latest version
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 | 33:ea83f08fa466 | 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 | 33:ea83f08fa466 | 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 | 33:ea83f08fa466 | 48 | if (_line_1.left <= 0) { |
el17my | 7:88c4ba6bb37b | 49 | _line_1.left = 0; } |
el17my | 7:88c4ba6bb37b | 50 | //if the left edge of the line is zero it will keep zero until the right edge equals to zero |
el17my | 7:88c4ba6bb37b | 51 | if (_line_1.right <= 0) { |
el17my | 7:88c4ba6bb37b | 52 | _line_1.left = 80; |
el17my | 7:88c4ba6bb37b | 53 | _line_1.right = 80;} |
el17my | 33:ea83f08fa466 | 54 | _line_1.length = (rand() %10) + 10; } |
el17my | 7:88c4ba6bb37b | 55 | |
el17my | 8:201ef0618b7d | 56 | void Surface::line_2() { |
el17my | 7:88c4ba6bb37b | 57 | if(_line_2.left > 0) { |
el17my | 33:ea83f08fa466 | 58 | _line_2.left-- ;} |
el17my | 7:88c4ba6bb37b | 59 | //the left side will keep moving until it disappear on the screen which also means equal to zero |
el17my | 7:88c4ba6bb37b | 60 | if (_line_2.left + _line_1.length < 80) { |
el17my | 33:ea83f08fa466 | 61 | _line_2.right-- ;} |
el17my | 7:88c4ba6bb37b | 62 | //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 | 33:ea83f08fa466 | 63 | if (_line_2.left <= 0) { |
el17my | 33:ea83f08fa466 | 64 | _line_2.left = 0;} |
el17my | 7:88c4ba6bb37b | 65 | //if the left edge of the line is zero it will keep zero until the right edge equals to zero |
el17my | 7:88c4ba6bb37b | 66 | if (_line_2.right <= 0) { |
el17my | 7:88c4ba6bb37b | 67 | _line_2.left = 80; |
el17my | 7:88c4ba6bb37b | 68 | _line_2.right = 80;} |
el17my | 33:ea83f08fa466 | 69 | _line_2.length = (rand() %10) + 10; } |
el17my | 7:88c4ba6bb37b | 70 | |
el17my | 8:201ef0618b7d | 71 | void Surface::line_3() { |
el17my | 7:88c4ba6bb37b | 72 | if(_line_3.left > 0) { |
el17my | 33:ea83f08fa466 | 73 | _line_3.left-- ;} |
el17my | 7:88c4ba6bb37b | 74 | //the left side will keep moving until it disappear on the screen which also means equal to zero |
el17my | 7:88c4ba6bb37b | 75 | if (_line_3.left + _line_1.length < 80) { |
el17my | 33:ea83f08fa466 | 76 | _line_3.right-- ;} |
el17my | 7:88c4ba6bb37b | 77 | //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 | 33:ea83f08fa466 | 78 | if (_line_3.left <= 0) { |
el17my | 33:ea83f08fa466 | 79 | _line_3.left = 0;} |
el17my | 7:88c4ba6bb37b | 80 | //if the left edge of the line is zero it will keep zero until the right edge equals to zero |
el17my | 7:88c4ba6bb37b | 81 | if (_line_3.right <= 0) { |
el17my | 7:88c4ba6bb37b | 82 | _line_3.left = 80; |
el17my | 7:88c4ba6bb37b | 83 | _line_3.right = 80;} |
el17my | 32:47d98959b4ef | 84 | _line_3.length = (rand() %10) + 10; } |
el17my | 7:88c4ba6bb37b | 85 | |
el17my | 8:201ef0618b7d | 86 | void Surface::line_4() { |
el17my | 7:88c4ba6bb37b | 87 | if(_line_4.left > 0) { |
el17my | 33:ea83f08fa466 | 88 | _line_4.left-- ;} |
el17my | 7:88c4ba6bb37b | 89 | //the left side will keep moving until it disappear on the screen which also means equal to zero |
el17my | 7:88c4ba6bb37b | 90 | if (_line_4.left + _line_1.length < 80) { |
el17my | 33:ea83f08fa466 | 91 | _line_4.right-- ;} |
el17my | 7:88c4ba6bb37b | 92 | //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 | 33:ea83f08fa466 | 93 | if (_line_4.left <= 0) { |
el17my | 33:ea83f08fa466 | 94 | _line_4.left = 0;} |
el17my | 7:88c4ba6bb37b | 95 | //if the left edge of the line is zero it will keep zero until the right edge equals to zero |
el17my | 7:88c4ba6bb37b | 96 | if (_line_4.right <= 0) { |
el17my | 7:88c4ba6bb37b | 97 | _line_4.left = 80; |
el17my | 7:88c4ba6bb37b | 98 | _line_4.right = 80;} |
el17my | 32:47d98959b4ef | 99 | _line_4.length = (rand() %10) + 10; } |
el17my | 7:88c4ba6bb37b | 100 | |
el17my | 8:201ef0618b7d | 101 | void Surface::line_5() { |
el17my | 7:88c4ba6bb37b | 102 | if(_line_5.left > 0) { |
el17my | 7:88c4ba6bb37b | 103 | _line_5.left-- ;} |
el17my | 7:88c4ba6bb37b | 104 | //the left side will keep moving until it disappear on the screen which also means equal to zero |
el17my | 7:88c4ba6bb37b | 105 | if (_line_5.left + _line_1.length < 80) { |
el17my | 33:ea83f08fa466 | 106 | _line_5.right-- ;} |
el17my | 7:88c4ba6bb37b | 107 | //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 | 33:ea83f08fa466 | 108 | if (_line_5.left <= 0) { |
el17my | 33:ea83f08fa466 | 109 | _line_5.left = 0;} |
el17my | 7:88c4ba6bb37b | 110 | //if the left edge of the line is zero it will keep zero until the right edge equals to zero |
el17my | 7:88c4ba6bb37b | 111 | if (_line_5.right <= 0) { |
el17my | 7:88c4ba6bb37b | 112 | _line_5.left = 80; |
el17my | 7:88c4ba6bb37b | 113 | _line_5.right = 80;} |
el17my | 33:ea83f08fa466 | 114 | _line_5.length = (rand() %10) + 10; } |
el17my | 7:88c4ba6bb37b | 115 | |
el17my | 8:201ef0618b7d | 116 | void Surface::line_6() { |
el17my | 7:88c4ba6bb37b | 117 | if(_line_6.left > 0) { |
el17my | 33:ea83f08fa466 | 118 | _line_6.left-- ;} |
el17my | 7:88c4ba6bb37b | 119 | //the left side will keep moving until it disappear on the screen which also means equal to zero |
el17my | 7:88c4ba6bb37b | 120 | if (_line_6.left + _line_1.length < 80) { |
el17my | 33:ea83f08fa466 | 121 | _line_6.right-- ;} |
el17my | 7:88c4ba6bb37b | 122 | //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 | 33:ea83f08fa466 | 123 | if (_line_6.left <= 0) { |
el17my | 33:ea83f08fa466 | 124 | _line_6.left = 0;} |
el17my | 7:88c4ba6bb37b | 125 | //if the left edge of the line is zero it will keep zero until the right edge equals to zero |
el17my | 7:88c4ba6bb37b | 126 | if (_line_6.right <= 0) { |
el17my | 7:88c4ba6bb37b | 127 | _line_6.left = 80; |
el17my | 7:88c4ba6bb37b | 128 | _line_6.right = 80;} |
el17my | 32:47d98959b4ef | 129 | _line_6.length = (rand() %10) + 10; } |
el17my | 7:88c4ba6bb37b | 130 | |
el17my | 7:88c4ba6bb37b | 131 | Line Surface::getline_1(){return _line_1;} |
el17my | 7:88c4ba6bb37b | 132 | Line Surface::getline_2(){return _line_2;} |
el17my | 7:88c4ba6bb37b | 133 | Line Surface::getline_3(){return _line_3;} |
el17my | 7:88c4ba6bb37b | 134 | Line Surface::getline_4(){return _line_4;} |
el17my | 7:88c4ba6bb37b | 135 | Line Surface::getline_5(){return _line_5;} |
el17my | 7:88c4ba6bb37b | 136 | Line Surface::getline_6(){return _line_6;} |
el17my | 7:88c4ba6bb37b | 137 | |
el17my | 7:88c4ba6bb37b | 138 | |
el17my | 7:88c4ba6bb37b | 139 | |
el17my | 7:88c4ba6bb37b | 140 | |
el17my | 7:88c4ba6bb37b | 141 |