ZIWEI LIU / Mbed 2 deprecated ELEC2645_Project_el19z2l

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Block.cpp Source File

Block.cpp

00001 #include "Block.h"
00002 
00003 Block::Block(){}
00004 Block::~Block(){}
00005 
00006 
00007 //initiate the position of the block
00008 void Block::blockinit(int x1up, int y1up, int x1down, int y1down, int x2up, int y2up, int x2down, int y2down){
00009     x1_up = x1up;
00010     y1_up = y1up;
00011     x1_down = x1down;
00012     y1_down = y1down;
00013     x2_up = x2up;
00014     y2_up = y2up;
00015     x2_down = x2down;
00016     y2_down = y2down;
00017     score = 0;
00018 }
00019 
00020 //draw the upper and lower walls
00021 void Block::draw_block(N5110 &lcd){
00022     lcd.drawLine(x1_up, y1_up, x1_down, y1_down,1);
00023     lcd.drawLine(x2_up, y2_up, x2_down, y2_down,1);
00024 }
00025 
00026 //level 1, the movenment of the walls
00027 void Block::blockupgrate(){
00028     
00029     if(x1_up < 1){
00030         
00031         x1_up = 83;
00032         x1_down =83;
00033         x2_up = 83;
00034         x2_down = 83;
00035     }
00036     else{
00037         
00038         x1_up = x1_up - 3;
00039         x1_down = x2_down - 3;
00040         x2_up = x2_up - 3;
00041         x2_down = x2_down - 3;
00042     }
00043 }
00044 
00045 //level 2, the movemnet of the walls
00046 void Block::blockupgrate2(){
00047     
00048     if(x1_up < 1){
00049         
00050         x1_up = 83;
00051         x1_down =83;
00052         x2_up = 83;
00053         x2_down = 83;
00054     }
00055     else{
00056         
00057         x1_up = x1_up - 5;
00058         x1_down = x2_down - 5;
00059         x2_up = x2_up - 5;
00060         x2_down = x2_down - 5;
00061     }
00062 }
00063 
00064 //level 3, the movement of the walls
00065 void Block::blockupgrate3(){
00066     
00067     if(x1_up < 1){
00068         
00069         x1_up = 83;
00070         x1_down =83;
00071         x2_up = 83;
00072         x2_down = 83;
00073     }
00074     else{
00075         
00076         x1_up = x1_up - 7;
00077         x1_down = x2_down - 7;
00078         x2_up = x2_up - 7;
00079         x2_down = x2_down - 7;
00080     }
00081 }
00082 
00083 //the movement of the y posiition of the walls
00084 //which means the space that character can pass
00085 //10 times is a period
00086 //whcih means in each level, the position is the same
00087 //for example, 1.1 = 2.1 = 3.1 = 4.1
00088 void Block::y_update(){
00089      
00090         int updatescore;
00091         updatescore = get_score();
00092         if(updatescore == 1 || updatescore == 11 || updatescore == 21 || updatescore == 31){
00093             y1_down = 5;
00094             y2_up = 25;
00095         }
00096         else if(updatescore == 2 || updatescore == 12 || updatescore == 22 || updatescore == 32){
00097             y1_down = 10;
00098             y2_up = 30;
00099         }
00100         else if(updatescore == 3 || updatescore == 13 || updatescore == 23 || updatescore == 33){
00101             y1_down = 25;
00102             y2_up = 45;
00103         }
00104         else if(updatescore == 4 || updatescore == 14 || updatescore == 24 || updatescore == 34){
00105             y1_down = 15;
00106             y2_up = 35;
00107         }
00108         else if(updatescore == 5 || updatescore == 15 || updatescore == 25 || updatescore == 35){
00109             y1_down = 1;
00110             y2_up = 21;
00111         }
00112         else if(updatescore == 6 || updatescore == 16 || updatescore == 26 || updatescore == 36){
00113             y1_down = 15;
00114             y2_up = 35;
00115         }
00116         else if(updatescore == 7 || updatescore == 17 || updatescore == 27 || updatescore == 37){
00117             y1_down = 25;
00118             y2_up = 45;
00119         }
00120         else if(updatescore == 8 || updatescore == 18 || updatescore == 28 || updatescore == 38){
00121             y1_down = 3;
00122             y2_up = 23;
00123         }
00124         else if(updatescore == 9 || updatescore == 19 || updatescore == 29 || updatescore == 39){
00125             y1_down = 11;
00126             y2_up = 31;
00127         }
00128         else if(updatescore == 10 || updatescore == 20 || updatescore == 30 || updatescore == 40){
00129             y1_down = 19;
00130             y2_up = 39;
00131         }
00132 }
00133     
00134 //level 4, the movement of the walls
00135 void Block::blockupgrate4(){
00136     
00137     if(x1_up < 1){
00138         
00139         x1_up = 83;
00140         x1_down =83;
00141         x2_up = 83;
00142         x2_down = 83;
00143     }
00144     else{
00145         
00146         x1_up = x1_up - 9;
00147         x1_down = x2_down - 9;
00148         x2_up = x2_up - 9;
00149         x2_down = x2_down - 9;
00150     }
00151 }
00152 
00153 //the vector to get the upper coordinates of upper wall
00154 Vector2D Block::getposition1(){
00155     Vector2D p1 = {x1_up, y1_up};
00156     return p1;
00157 }
00158 
00159 //the vector to get the lower coordinates of upper wall
00160 Vector2D Block::getposition2(){
00161     Vector2D p2 = {x1_down, y1_down};
00162     return p2;
00163 }
00164 
00165 //the vector to get the upper coordinates of lower wall
00166 Vector2D Block::getposition3(){
00167     Vector2D p3 = {x2_up, y2_up};
00168     return p3;
00169 }
00170 
00171 //the vector to get the lower coordinates of lower wall
00172 Vector2D Block::getposition4(){
00173     Vector2D p4 = {x2_down, y2_down};
00174     return p4;
00175 }
00176 
00177 //function to add score by 1
00178 void Block::add_score(){
00179     score = score + 1;
00180 }
00181 
00182 //get the score
00183 int Block::get_score(){
00184     return score;
00185 }
00186     
00187 
00188