![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Doxygen comments added
Dependencies: mbed Gamepad N5110
Revision 16:95e3706790e5, committed 2019-05-09
- Comitter:
- rafeh
- Date:
- Thu May 09 14:14:37 2019 +0000
- Parent:
- 15:fc6b40fceb4f
- Commit message:
- Final Submission. I have read and agreed with Statement of Academic Integrity.
Changed in this revision
Scoring/Scoring.h | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r fc6b40fceb4f -r 95e3706790e5 Scoring/Scoring.h --- a/Scoring/Scoring.h Thu May 09 13:46:01 2019 +0000 +++ b/Scoring/Scoring.h Thu May 09 14:14:37 2019 +0000 @@ -4,7 +4,7 @@ #include "mbed.h" #include "N5110.h" #include "Gamepad.h" -/** Class Scoring +/** Scoring Class @brief Class for counting,updating and checking scores @author Rafeh Ishtiaq @date May 2019
diff -r fc6b40fceb4f -r 95e3706790e5 main.cpp --- a/main.cpp Thu May 09 13:46:01 2019 +0000 +++ b/main.cpp Thu May 09 14:14:37 2019 +0000 @@ -23,40 +23,36 @@ Pipes pipes; Entrance entrance; Scoring flappy; -Pipes pipes2; /////////////////////////////Funcions//////////////////////////////////////////// +void init(); 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); //display the welcome page + init(); if (pad.check_event(Gamepad::START_PRESSED) == false) { lcd.clear(); ///////////////////////// Initialising Values//////////////////////////////////////////////////// - int yaxis=20; //y position of the bird + int bird_y=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 height2=0; //initialising the height of the second pipe (top part) int score = 0; //initialising the score int highscore = 0; //initialising the highscore /////////////////////////////////////////////////////////////////////////////////////////////////////// while(1) { - produce(xvalue,xvalue2,height,height2,BIRD_X,yaxis); //draw the pipes and the bird + produce(xvalue,xvalue2,height,height2,BIRD_X,bird_y); //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); + score=flappy.add_score(score,xvalue2,BIRD_X,PIPE_WIDTH); //check for both pipes 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) @@ -68,15 +64,15 @@ } wait(0.075); - yaxis=bird.get_position(yaxis,pad); //gets the new vertical position for the bird + bird_y=bird.get_position(bird_y,pad); //gets the new vertical position for the bird if(xvalue>2) { xvalue=xvalue-2; //moves the first pipes towards the left } if(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); // between the bird and both pipes +if ((flappy.check_collisions(bird_y,xvalue,height))||(flappy.check_collisions(bird_y,xvalue2,height2))) { //checking for collisions + wait(1); // between the bird and both the pipes if (flappy.check_for_highscore(score,highscore)) { //check if the score was highscore highscore=score;} @@ -90,7 +86,7 @@ } score=0; //initialising the values again for the new game xvalue=84; - yaxis=20; + bird_y=20; xvalue2=0; lcd.refresh(); } @@ -102,6 +98,18 @@ + + void init() { + lcd.init(); + pad.init(); + lcd.clear(); + lcd.setContrast(0.5); + entrance.welcome_page(lcd,pad); //display the welcome page + } + + + + 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) { @@ -109,8 +117,8 @@ pipes.draw(lcd); } if(pipex2>2){ //draw the second pipe - pipes2.init(pipex2,pipeheight2); - pipes2.draw(lcd); + pipes.init(pipex2,pipeheight2); + pipes.draw(lcd); } bird.init(birdx,birdy); //draw the bird bird.draw(lcd); @@ -123,4 +131,5 @@ sprintf(display,"%d",scored_points); lcd.printString(display,60,0); } - + +