Doxygen comments added
Dependencies: mbed Gamepad N5110
Diff: main.cpp
- Revision:
- 5:3a0948f56de0
- Parent:
- 4:e98b22e5d5e8
- Child:
- 6:bc580b480ac8
--- a/main.cpp Wed May 01 22:01:10 2019 +0000 +++ b/main.cpp Thu May 02 18:42:43 2019 +0000 @@ -77,7 +77,8 @@ void welcome(); void checkcollisions(int hor, int ver); - +int generate_height(); +bool check_collisions(int f, int xx, int yy); int xaxis=25; int yaxis=20; @@ -92,15 +93,13 @@ lcd.clear(); int xvalue=84; - int height = rand() % (19 + 1 - 0) + 0; + //int height = rand() % (19 + 1 - 0) + 0; + int height = generate_height(); int score = 0; char scoredisplay[3]; while(1) { lcd.drawRect(0,45,84,3,FILL_BLACK); - //lcd.drawRect(xvalue,0,5,height,FILL_BLACK); - //lcd.drawRect(xvalue,(height+20),5,(84-(height+20)),FILL_BLACK); - //pipes.init(xvalue,height); pipes.init(xvalue,height); pipes.draw(lcd); xvalue=xvalue-1; @@ -113,7 +112,8 @@ if(xvalue<1) { - height=rand() % (19 + 1 - 0) + 0; + //height=rand() % (19 + 1 - 0) + 0; + height=generate_height(); xvalue=84; } @@ -128,7 +128,10 @@ wait(0.075); xvalue=xvalue-1; - +if (check_collisions(yaxis,xvalue,height)) { + wait(1); + welcome(); + } //checkcollisions(xaxis,yaxis); //wait(0.1); lcd.refresh(); @@ -156,12 +159,16 @@ } } -void checkcollisions(int hor , int ver) { - if(lcd.getPixel((hor+3),ver)|| lcd.getPixel(hor+4,ver)) { welcome();} - if(lcd.getPixel((hor+1),(ver+1)) || lcd.getPixel((hor+4),(ver+1))) { welcome();} - if(lcd.getPixel((hor),(ver+2)) || lcd.getPixel((hor+5),(ver+2))) {welcome();} - if(lcd.getPixel((hor),(ver+3)) || lcd.getPixel((hor+4),(ver+3))) {welcome();} - if(lcd.getPixel((hor+1),(ver+4)) || lcd.getPixel((hor+4),(ver+4))) {welcome();} + bool check_collisions(int f, int xx, int yy) { + if((xx>17 && xx<32)&&((f<(yy)) || (f>(yy+26)))) + return true; + else + return false; + } + + int generate_height() { + int random_height=rand() % (19 + 1 - 0) + 0; + return random_height; } \ No newline at end of file