Doxygen comments added

Dependencies:   mbed Gamepad N5110

Committer:
rafeh
Date:
Mon May 06 22:55:38 2019 +0000
Revision:
7:05f433e196d6
Parent:
6:bc580b480ac8
Child:
8:d91564c0f337
udating FlappyBirdEngine class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rafeh 0:43364ffd7cf6 1 /*
rafeh 0:43364ffd7cf6 2 ELEC2645 Embedded Systems Project
rafeh 0:43364ffd7cf6 3 School of Electronic & Electrical Engineering
rafeh 0:43364ffd7cf6 4 University of Leeds
rafeh 0:43364ffd7cf6 5 Name: Rafeh Ishtiaq
rafeh 0:43364ffd7cf6 6 Username: el17ri
rafeh 0:43364ffd7cf6 7 Student ID Number: 201062291
rafeh 0:43364ffd7cf6 8 Date: 20/03/2019
rafeh 0:43364ffd7cf6 9 */
rafeh 0:43364ffd7cf6 10
rafeh 0:43364ffd7cf6 11 #include "mbed.h"
rafeh 0:43364ffd7cf6 12 #include "N5110.h"
rafeh 0:43364ffd7cf6 13 #include "Gamepad.h"
rafeh 3:5409b50b01b0 14 #include "Pipes.h"
rafeh 6:bc580b480ac8 15 #include "Bird.h"
rafeh 7:05f433e196d6 16 #include "Entrance.h"
rafeh 7:05f433e196d6 17 #include "FlappyBirdEngine.h"
rafeh 0:43364ffd7cf6 18 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
rafeh 0:43364ffd7cf6 19 Gamepad pad;
rafeh 6:bc580b480ac8 20 Bird bird;
rafeh 3:5409b50b01b0 21 Pipes pipes;
rafeh 7:05f433e196d6 22 Entrance entrance;
rafeh 7:05f433e196d6 23 FlappyBirdEngine flappy;
rafeh 3:5409b50b01b0 24
rafeh 7:05f433e196d6 25
rafeh 0:43364ffd7cf6 26
rafeh 0:43364ffd7cf6 27
rafeh 5:3a0948f56de0 28 bool check_collisions(int f, int xx, int yy);
rafeh 3:5409b50b01b0 29
rafeh 3:5409b50b01b0 30 int xaxis=25;
rafeh 7:05f433e196d6 31 int yaxis=20; //y position of the bird
rafeh 3:5409b50b01b0 32
rafeh 0:43364ffd7cf6 33 int main() {
rafeh 0:43364ffd7cf6 34 lcd.init();
rafeh 0:43364ffd7cf6 35 pad.init();
rafeh 0:43364ffd7cf6 36 lcd.clear();
rafeh 1:beceda7046fb 37 lcd.setContrast(0.5);
rafeh 7:05f433e196d6 38 entrance.welcome_page(lcd,pad);
rafeh 2:9f5714571c41 39 if (pad.check_event(Gamepad::START_PRESSED) == false) {
rafeh 2:9f5714571c41 40 lcd.clear();
rafeh 2:9f5714571c41 41
rafeh 3:5409b50b01b0 42 int xvalue=84;
rafeh 7:05f433e196d6 43 int height = pipes.generate_height();
rafeh 3:5409b50b01b0 44 int score = 0;
rafeh 7:05f433e196d6 45 int highscore = 0;
rafeh 3:5409b50b01b0 46 char scoredisplay[3];
rafeh 2:9f5714571c41 47 while(1) {
rafeh 7:05f433e196d6 48 lcd.drawRect(0,45,84,3,FILL_BLACK); //draw the floor
rafeh 3:5409b50b01b0 49
rafeh 7:05f433e196d6 50 pipes.init(xvalue,height); // draw the pipes
rafeh 3:5409b50b01b0 51 pipes.draw(lcd);
rafeh 7:05f433e196d6 52 //xvalue=xvalue-1;
rafeh 7:05f433e196d6 53 sprintf(scoredisplay,"%d",score);
rafeh 7:05f433e196d6 54 lcd.printString(scoredisplay,60,0); //display the score on the up right
rafeh 7:05f433e196d6 55
rafeh 7:05f433e196d6 56 if(xvalue<20 && xvalue>17) {
rafeh 3:5409b50b01b0 57 score=score+1;
rafeh 3:5409b50b01b0 58 }
rafeh 3:5409b50b01b0 59
rafeh 3:5409b50b01b0 60
rafeh 3:5409b50b01b0 61 if(xvalue<1) {
rafeh 7:05f433e196d6 62 height=pipes.generate_height();
rafeh 3:5409b50b01b0 63 xvalue=84;
rafeh 3:5409b50b01b0 64 }
rafeh 3:5409b50b01b0 65
rafeh 7:05f433e196d6 66
rafeh 6:bc580b480ac8 67 bird.init(xaxis,yaxis);
rafeh 6:bc580b480ac8 68 bird.draw(lcd);
rafeh 6:bc580b480ac8 69 yaxis=bird.get_position(yaxis,pad);
rafeh 3:5409b50b01b0 70 wait(0.075);
rafeh 7:05f433e196d6 71 xvalue=xvalue-2;
rafeh 5:3a0948f56de0 72 if (check_collisions(yaxis,xvalue,height)) {
rafeh 5:3a0948f56de0 73 wait(1);
rafeh 7:05f433e196d6 74 flappy.get_score(score);
rafeh 7:05f433e196d6 75 if (flappy.check_for_highscore(highscore)) {
rafeh 7:05f433e196d6 76 highscore=score;}
rafeh 7:05f433e196d6 77 flappy.update_highscore(highscore);
rafeh 7:05f433e196d6 78 flappy.display_score(lcd,pad);
rafeh 7:05f433e196d6 79 score=0;
rafeh 5:3a0948f56de0 80 }
rafeh 2:9f5714571c41 81 lcd.refresh();
rafeh 2:9f5714571c41 82 lcd.clear();
rafeh 2:9f5714571c41 83 }
rafeh 2:9f5714571c41 84 }
rafeh 3:5409b50b01b0 85
rafeh 3:5409b50b01b0 86
rafeh 2:9f5714571c41 87 }
rafeh 0:43364ffd7cf6 88
rafeh 2:9f5714571c41 89
rafeh 5:3a0948f56de0 90 bool check_collisions(int f, int xx, int yy) {
rafeh 7:05f433e196d6 91 if((xx>17 && xx<32)&&((f<(yy-3)) || (f>(yy+26))) || (f>45))
rafeh 5:3a0948f56de0 92 return true;
rafeh 5:3a0948f56de0 93 else
rafeh 5:3a0948f56de0 94 return false;
rafeh 5:3a0948f56de0 95 }
rafeh 5:3a0948f56de0 96
rafeh 7:05f433e196d6 97
rafeh 3:5409b50b01b0 98
rafeh 3:5409b50b01b0 99