Mochu Yao explorer game

Dependencies:   mbed

Committer:
el17my
Date:
Wed Apr 29 12:19:12 2020 +0000
Revision:
32:47d98959b4ef
Parent:
17:1b4ecc01b79f
Child:
33:ea83f08fa466
4.29

Who changed what in which revision?

UserRevisionLine numberNew 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 32:47d98959b4ef 43 _line_1.left-- ;
el17my 32:47d98959b4ef 44 wait(1);}
el17my 7:88c4ba6bb37b 45 //the left side will keep moving until it disappear on the screen which also means equal to zero
el17my 7:88c4ba6bb37b 46 if (_line_1.left + _line_1.length < 80) {
el17my 32:47d98959b4ef 47 _line_1.right-- ; wait(1);}
el17my 7:88c4ba6bb37b 48 //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 49 if (_line_1.right <= 0) {
el17my 32:47d98959b4ef 50 _line_1.right--; wait(1)
el17my 7:88c4ba6bb37b 51 _line_1.left = 0; }
el17my 7:88c4ba6bb37b 52 //if the left edge of the line is zero it will keep zero until the right edge equals to zero
el17my 7:88c4ba6bb37b 53 if (_line_1.right <= 0) {
el17my 7:88c4ba6bb37b 54 _line_1.left = 80;
el17my 7:88c4ba6bb37b 55 _line_1.right = 80;}
el17my 32:47d98959b4ef 56 _line_1.length = (rand() %10) + 5; }
el17my 7:88c4ba6bb37b 57
el17my 8:201ef0618b7d 58 void Surface::line_2() {
el17my 7:88c4ba6bb37b 59 if(_line_2.left > 0) {
el17my 32:47d98959b4ef 60 _line_2.left-- ; wait(1);}
el17my 7:88c4ba6bb37b 61 //the left side will keep moving until it disappear on the screen which also means equal to zero
el17my 7:88c4ba6bb37b 62 if (_line_2.left + _line_1.length < 80) {
el17my 32:47d98959b4ef 63 _line_2.right-- ;wait(1);}
el17my 7:88c4ba6bb37b 64 //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 65 if (_line_2.right <= 0) {
el17my 7:88c4ba6bb37b 66 _line_2.right--;
el17my 32:47d98959b4ef 67 _line_2.left = 0;wait(1);}
el17my 7:88c4ba6bb37b 68 //if the left edge of the line is zero it will keep zero until the right edge equals to zero
el17my 7:88c4ba6bb37b 69 if (_line_2.right <= 0) {
el17my 7:88c4ba6bb37b 70 _line_2.left = 80;
el17my 7:88c4ba6bb37b 71 _line_2.right = 80;}
el17my 7:88c4ba6bb37b 72 _line_2.length = (rand() %15) + 10; }
el17my 7:88c4ba6bb37b 73
el17my 8:201ef0618b7d 74 void Surface::line_3() {
el17my 7:88c4ba6bb37b 75 if(_line_3.left > 0) {
el17my 32:47d98959b4ef 76 _line_3.left-- ;wait(1);}
el17my 7:88c4ba6bb37b 77 //the left side will keep moving until it disappear on the screen which also means equal to zero
el17my 7:88c4ba6bb37b 78 if (_line_3.left + _line_1.length < 80) {
el17my 32:47d98959b4ef 79 _line_3.right-- ;wait(1);}
el17my 7:88c4ba6bb37b 80 //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 81 if (_line_3.right <= 0) {
el17my 7:88c4ba6bb37b 82 _line_3.right--;
el17my 32:47d98959b4ef 83 _line_3.left = 0; wait(1);}
el17my 7:88c4ba6bb37b 84 //if the left edge of the line is zero it will keep zero until the right edge equals to zero
el17my 7:88c4ba6bb37b 85 if (_line_3.right <= 0) {
el17my 7:88c4ba6bb37b 86 _line_3.left = 80;
el17my 7:88c4ba6bb37b 87 _line_3.right = 80;}
el17my 32:47d98959b4ef 88 _line_3.length = (rand() %10) + 10; }
el17my 7:88c4ba6bb37b 89
el17my 8:201ef0618b7d 90 void Surface::line_4() {
el17my 7:88c4ba6bb37b 91 if(_line_4.left > 0) {
el17my 32:47d98959b4ef 92 _line_4.left-- ;wait(1);}
el17my 7:88c4ba6bb37b 93 //the left side will keep moving until it disappear on the screen which also means equal to zero
el17my 7:88c4ba6bb37b 94 if (_line_4.left + _line_1.length < 80) {
el17my 32:47d98959b4ef 95 _line_4.right-- ;wait(1);}
el17my 7:88c4ba6bb37b 96 //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 97 if (_line_4.right <= 0) {
el17my 7:88c4ba6bb37b 98 _line_4.right--;
el17my 32:47d98959b4ef 99 _line_4.left = 0;wait(1);}
el17my 7:88c4ba6bb37b 100 //if the left edge of the line is zero it will keep zero until the right edge equals to zero
el17my 7:88c4ba6bb37b 101 if (_line_4.right <= 0) {
el17my 7:88c4ba6bb37b 102 _line_4.left = 80;
el17my 7:88c4ba6bb37b 103 _line_4.right = 80;}
el17my 32:47d98959b4ef 104 _line_4.length = (rand() %10) + 10; }
el17my 7:88c4ba6bb37b 105
el17my 8:201ef0618b7d 106 void Surface::line_5() {
el17my 7:88c4ba6bb37b 107 if(_line_5.left > 0) {
el17my 7:88c4ba6bb37b 108 _line_5.left-- ;}
el17my 7:88c4ba6bb37b 109 //the left side will keep moving until it disappear on the screen which also means equal to zero
el17my 7:88c4ba6bb37b 110 if (_line_5.left + _line_1.length < 80) {
el17my 32:47d98959b4ef 111 _line_5.right-- ;wait(1);}
el17my 7:88c4ba6bb37b 112 //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 113 if (_line_5.right <= 0) {
el17my 7:88c4ba6bb37b 114 _line_5.right--;
el17my 32:47d98959b4ef 115 _line_5.left = 0;wait(1);}
el17my 7:88c4ba6bb37b 116 //if the left edge of the line is zero it will keep zero until the right edge equals to zero
el17my 7:88c4ba6bb37b 117 if (_line_5.right <= 0) {
el17my 7:88c4ba6bb37b 118 _line_5.left = 80;
el17my 7:88c4ba6bb37b 119 _line_5.right = 80;}
el17my 32:47d98959b4ef 120 _line_5.length = (rand() %10) + 5; }
el17my 7:88c4ba6bb37b 121
el17my 8:201ef0618b7d 122 void Surface::line_6() {
el17my 7:88c4ba6bb37b 123 if(_line_6.left > 0) {
el17my 32:47d98959b4ef 124 _line_6.left-- ;wait(1);}
el17my 7:88c4ba6bb37b 125 //the left side will keep moving until it disappear on the screen which also means equal to zero
el17my 7:88c4ba6bb37b 126 if (_line_6.left + _line_1.length < 80) {
el17my 32:47d98959b4ef 127 _line_6.right-- ;wait(1);}
el17my 7:88c4ba6bb37b 128 //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 129 if (_line_6.right <= 0) {
el17my 7:88c4ba6bb37b 130 _line_6.right--;
el17my 32:47d98959b4ef 131 _line_6.left = 0;wait(1);}
el17my 7:88c4ba6bb37b 132 //if the left edge of the line is zero it will keep zero until the right edge equals to zero
el17my 7:88c4ba6bb37b 133 if (_line_6.right <= 0) {
el17my 7:88c4ba6bb37b 134 _line_6.left = 80;
el17my 7:88c4ba6bb37b 135 _line_6.right = 80;}
el17my 32:47d98959b4ef 136 _line_6.length = (rand() %10) + 10; }
el17my 7:88c4ba6bb37b 137
el17my 7:88c4ba6bb37b 138 Line Surface::getline_1(){return _line_1;}
el17my 7:88c4ba6bb37b 139 Line Surface::getline_2(){return _line_2;}
el17my 7:88c4ba6bb37b 140 Line Surface::getline_3(){return _line_3;}
el17my 7:88c4ba6bb37b 141 Line Surface::getline_4(){return _line_4;}
el17my 7:88c4ba6bb37b 142 Line Surface::getline_5(){return _line_5;}
el17my 7:88c4ba6bb37b 143 Line Surface::getline_6(){return _line_6;}
el17my 7:88c4ba6bb37b 144
el17my 7:88c4ba6bb37b 145
el17my 7:88c4ba6bb37b 146
el17my 7:88c4ba6bb37b 147
el17my 7:88c4ba6bb37b 148