Doxygen comments added
Dependencies: mbed Gamepad N5110
Diff: main.cpp
- Revision:
- 10:75de0f4da176
- Parent:
- 9:b7a3ec1c7217
- Child:
- 14:9a9ac55616c4
--- a/main.cpp Tue May 07 22:39:48 2019 +0000 +++ b/main.cpp Wed May 08 20:59:02 2019 +0000 @@ -25,11 +25,6 @@ Scoring flappy; - - -bool check_collisions(int f, int xx, int yy); - -int xaxis=25; int yaxis=20; //y position of the bird int main() { @@ -37,62 +32,62 @@ pad.init(); lcd.clear(); lcd.setContrast(0.5); - entrance.welcome_page(lcd,pad); + entrance.welcome_page(lcd,pad); if (pad.check_event(Gamepad::START_PRESSED) == false) { lcd.clear(); - int xvalue=84; - int height = pipes.generate_height(); + int xvalue=84; //initialising the x value of the pipes + int height = pipes.generate_height(); //initialising the height of the top pipe int score = 0; int highscore = 0; - char scoredisplay[3]; + char scoredisplay[3]; //to display while(1) { + + lcd.drawRect(0,45,84,3,FILL_BLACK); //draw the floor pipes.init(xvalue,height); // draw the pipes pipes.draw(lcd); + bird.init(BIRD_X,yaxis); //draw the bird + bird.draw(lcd); //xvalue=xvalue-1; sprintf(scoredisplay,"%d",score); - lcd.printString(scoredisplay,60,0); //display the score on the up right + lcd.printString(scoredisplay,60,0); //display the score on the top right - flappy.get_score(score); - score=flappy.add_score(score,xvalue,BIRD_X,PIPE_WIDTH); + flappy.set_score(score); + score=flappy.add_score(score,xvalue,BIRD_X,PIPE_WIDTH); //add score if the pipe has gone further left of the bird - if(xvalue<1) { - height=pipes.generate_height(); + if(xvalue<1) { //generates a new pipe + height=pipes.generate_height(); //a new height is generated for the new pipe (i.e. the placement of the gap is different) xvalue=84; } - bird.init(xaxis,yaxis); - bird.draw(lcd); - yaxis=bird.get_position(yaxis,pad); wait(0.075); - xvalue=xvalue-2; -if (check_collisions(yaxis,xvalue,height)) { + yaxis=bird.get_position(yaxis,pad); //gets new vertical position for the bird + xvalue=xvalue-2; //moves the pipes towards the left + +if (flappy.check_collisions(yaxis,xvalue,height)) { //checking for collisions wait(1); if (flappy.check_for_highscore(highscore)) { - highscore=score;} + highscore=score;} flappy.update_highscore(highscore); + while (pad.check_event(Gamepad::START_PRESSED) == false) { + lcd.clear(); flappy.display_score(lcd,pad); + lcd.refresh(); + wait(0.05); + } score=0; } lcd.refresh(); lcd.clear(); } } - + } - } - + - bool check_collisions(int f, int xx, int yy) { - if((xx>17 && xx<32)&&((f<(yy-3)) || (f>(yy+26))) || (f>45)) - return true; - else - return false; - } - - - - \ No newline at end of file + + +