Doxygen comments added
Dependencies: mbed Gamepad N5110
Diff: main.cpp
- Revision:
- 7:05f433e196d6
- Parent:
- 6:bc580b480ac8
- Child:
- 8:d91564c0f337
--- a/main.cpp Mon May 06 10:57:08 2019 +0000 +++ b/main.cpp Mon May 06 22:55:38 2019 +0000 @@ -13,128 +13,71 @@ #include "Gamepad.h" #include "Pipes.h" #include "Bird.h" - +#include "Entrance.h" +#include "FlappyBirdEngine.h" N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Gamepad pad; Bird bird; Pipes pipes; +Entrance entrance; +FlappyBirdEngine flappy; - const int intro [40][40] = - { -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,0,1,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1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0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + -}; -const int moving [6][6] = -{ - 0,0,1,1,0,0, - 0,1,0,1,1,0, - 1,0,1,1,1,1, - 1,1,1,1,1,0, - 0,1,1,1,1,0, - 0,0,0,0,0,0, - - }; - -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; +int yaxis=20; //y position of the bird int main() { lcd.init(); pad.init(); lcd.clear(); lcd.setContrast(0.5); - welcome(); + entrance.welcome_page(lcd,pad); if (pad.check_event(Gamepad::START_PRESSED) == false) { lcd.clear(); int xvalue=84; - //int height = rand() % (19 + 1 - 0) + 0; - int height = generate_height(); - int height2 = generate_height(); + int height = pipes.generate_height(); int score = 0; + int highscore = 0; char scoredisplay[3]; while(1) { - lcd.drawRect(0,45,84,3,FILL_BLACK); + lcd.drawRect(0,45,84,3,FILL_BLACK); //draw the floor - pipes.init(xvalue,height); + pipes.init(xvalue,height); // draw the pipes pipes.draw(lcd); - xvalue=xvalue-1; - sprintf(scoredisplay,"%d",score); - lcd.printString(scoredisplay,60,0); - - if(xvalue<20 && xvalue>17) { + //xvalue=xvalue-1; + sprintf(scoredisplay,"%d",score); + lcd.printString(scoredisplay,60,0); //display the score on the up right + + if(xvalue<20 && xvalue>17) { score=score+1; } if(xvalue<1) { - //height=rand() % (19 + 1 - 0) + 0; - height=generate_height(); + height=pipes.generate_height(); xvalue=84; } - //pipes(xvalue,height); + bird.init(xaxis,yaxis); bird.draw(lcd); - //lcd.drawSprite(xaxis,yaxis,6,6,(int*)moving); - //yaxis=yaxis+2; - //if (pad.check_event(Gamepad::A_PRESSED) == true) { - //yaxis=yaxis-14; - //} yaxis=bird.get_position(yaxis,pad); wait(0.075); - xvalue=xvalue-1; + xvalue=xvalue-2; if (check_collisions(yaxis,xvalue,height)) { wait(1); - welcome(); + flappy.get_score(score); + if (flappy.check_for_highscore(highscore)) { + highscore=score;} + flappy.update_highscore(highscore); + flappy.display_score(lcd,pad); + score=0; } - //checkcollisions(xaxis,yaxis); - //wait(0.1); lcd.refresh(); lcd.clear(); } @@ -144,32 +87,13 @@ } - -void welcome() { - lcd.drawSprite(0,0,40,40,(int*)intro); - lcd.printString(" Flappy ",40,0); - lcd.printString(" Bird ",40,1); - lcd.printString(" Press ",40,3); - lcd.printString(" Start ",40,4); - lcd.refresh(); - while ( pad.check_event(Gamepad::START_PRESSED) == false) { - pad.leds_on(); - wait(0.1); - pad.leds_off(); - wait(0.1); - } - } - bool check_collisions(int f, int xx, int yy) { - if((xx>17 && xx<32)&&((f<(yy)) || (f>(yy+26)))) + if((xx>17 && xx<32)&&((f<(yy-3)) || (f>(yy+26))) || (f>45)) return true; else return false; } - int generate_height() { - int random_height=rand() % (25 + 1 - 0) + 0; - return random_height; - } + \ No newline at end of file