Doxygen comments added
Dependencies: mbed Gamepad N5110
Diff: main.cpp
- Revision:
- 15:fc6b40fceb4f
- Parent:
- 14:9a9ac55616c4
- Child:
- 16:95e3706790e5
diff -r 9a9ac55616c4 -r fc6b40fceb4f main.cpp --- a/main.cpp Thu May 09 10:25:47 2019 +0000 +++ b/main.cpp Thu May 09 13:46:01 2019 +0000 @@ -24,79 +24,71 @@ Entrance entrance; Scoring flappy; Pipes pipes2; -float cont = pad.read_pot(); -int yaxis=20; //y position of the bird + +/////////////////////////////Funcions//////////////////////////////////////////// +void produce(int pipex1, int pipex2,int pipeheight1,int pipeheight2,int birdx,int birdy); +void print_score(int scored_points); +///////////////////////////////////////////////////////////////////////////// int main() { lcd.init(); pad.init(); lcd.clear(); lcd.setContrast(0.5); - entrance.welcome_page(lcd,pad); + entrance.welcome_page(lcd,pad); //display the welcome page if (pad.check_event(Gamepad::START_PRESSED) == false) { lcd.clear(); - int xvalue=84; //initialising the x value of the pipes - int xvalue2=0; - int height = pipes.generate_height(); //initialising the height of the top pipe - int height2=0; - int score = 0; - int highscore = 0; - char scoredisplay[3]; //to display score + ///////////////////////// Initialising Values//////////////////////////////////////////////////// + int yaxis=20; //y position of the bird + int xvalue=84; //initialising the x value of the first pipe (there will be two pipes on screen) + int xvalue2=0; //initialising the x value of the second pipe + int height = pipes.generate_height(); //initialising the height of the first pipe (top part of the pipe) + int height2=0; //initialising the height of the second pipe + int score = 0; //initialising the score + int highscore = 0; //initialising the highscore + + /////////////////////////////////////////////////////////////////////////////////////////////////////// while(1) { - - pad.tone(5000,0.2); - lcd.drawRect(0,45,84,3,FILL_BLACK); //draw the floor - if(xvalue>2) { - pipes.init(xvalue,height); // draw the pipes - pipes.draw(lcd); - } - if(xvalue2>2){ - pipes2.init(xvalue2,height2); - pipes2.draw(lcd); - } - bird.init(BIRD_X,yaxis); //draw the bird - bird.draw(lcd); - sprintf(scoredisplay,"%d",score); - lcd.printString(scoredisplay,60,0); //display the score on the top right + + produce(xvalue,xvalue2,height,height2,BIRD_X,yaxis); //draw the pipes and the bird + print_score(score); //display the score on the top right 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 score=flappy.add_score(score,xvalue2,BIRD_X,PIPE_WIDTH); - - if(xvalue<25 && xvalue >23) { //generates a new pipe + + if(xvalue<29 && xvalue >27) { //generates a new pipe if the previous pipe has crossed a certain point height2=pipes.generate_height(); //a new height is generated for the new pipe (i.e. the placement of the gap is different) xvalue2=84; } - if(xvalue<25 && xvalue >23) { //generates a new pipe - height2=pipes.generate_height(); //a new height is generated for the new pipe (i.e. the placement of the gap is different) - xvalue2=84; - } - if(xvalue2<25 && xvalue2>23) { + if(xvalue2<29 && xvalue2>27) { //does the same as above for the second pipe height=pipes.generate_height(); xvalue=84; } - - + wait(0.075); - yaxis=bird.get_position(yaxis,pad); //gets new vertical position for the bird + yaxis=bird.get_position(yaxis,pad); //gets the new vertical position for the bird if(xvalue>2) { - xvalue=xvalue-2; //moves the pipes towards the left + xvalue=xvalue-2; //moves the first pipes towards the left } if(xvalue2>2) { - xvalue2=xvalue2-2; + xvalue2=xvalue2-2; //moves the second pipe towards the left } -if ((flappy.check_collisions(yaxis,xvalue,height))||(flappy.check_collisions(yaxis,xvalue2,height2))) { //checking for collisions - wait(1); +if ((flappy.check_collisions(yaxis,xvalue,height))||(flappy.check_collisions(yaxis,xvalue2,height2))) { //checking for collisions + wait(1); // between the bird and both pipes + if (flappy.check_for_highscore(score,highscore)) { //check if the score was highscore highscore=score;} flappy.update_highscore(highscore); //update the highscore + flappy.display_score(lcd,pad); + wait(0.1); while (pad.check_event(Gamepad::A_PRESSED) == false) { lcd.clear(); - flappy.display_score(lcd,pad); // + flappy.display_score(lcd,pad); //display the score and highscore until button A is pressed if(pad.check_event(Gamepad::START_PRESSED) == false) { break;} } - score=0; + score=0; //initialising the values again for the new game xvalue=84; yaxis=20; xvalue2=0; @@ -108,6 +100,27 @@ } } - + + +void produce(int pipex1, int pipex2,int pipeheight1,int pipeheight2,int birdx,int birdy){ + lcd.drawRect(0,45,84,3,FILL_BLACK); //draw the floor + if(pipex1>2) { + pipes.init(pipex1,pipeheight1); // draw the first pipes + pipes.draw(lcd); + } + if(pipex2>2){ //draw the second pipe + pipes2.init(pipex2,pipeheight2); + pipes2.draw(lcd); + } + bird.init(birdx,birdy); //draw the bird + bird.draw(lcd); + } + + - +void print_score(int scored_points) { //displays the score when the game is being played + char display[3]; + sprintf(display,"%d",scored_points); + lcd.printString(display,60,0); + } +