Doxygen comments added

Dependencies:   mbed Gamepad N5110

Committer:
rafeh
Date:
Thu May 09 14:14:37 2019 +0000
Revision:
16:95e3706790e5
Parent:
15:fc6b40fceb4f
Final Submission. I have read and agreed with Statement of Academic Integrity.

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 9:b7a3ec1c7217 17 #include "Scoring.h"
rafeh 8:d91564c0f337 18 #define PIPE_WIDTH 8
rafeh 8:d91564c0f337 19 #define BIRD_X 25
rafeh 0:43364ffd7cf6 20 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
rafeh 0:43364ffd7cf6 21 Gamepad pad;
rafeh 6:bc580b480ac8 22 Bird bird;
rafeh 3:5409b50b01b0 23 Pipes pipes;
rafeh 7:05f433e196d6 24 Entrance entrance;
rafeh 9:b7a3ec1c7217 25 Scoring flappy;
rafeh 15:fc6b40fceb4f 26
rafeh 15:fc6b40fceb4f 27 /////////////////////////////Funcions////////////////////////////////////////////
rafeh 16:95e3706790e5 28 void init();
rafeh 15:fc6b40fceb4f 29 void produce(int pipex1, int pipex2,int pipeheight1,int pipeheight2,int birdx,int birdy);
rafeh 15:fc6b40fceb4f 30 void print_score(int scored_points);
rafeh 15:fc6b40fceb4f 31 /////////////////////////////////////////////////////////////////////////////
rafeh 3:5409b50b01b0 32
rafeh 0:43364ffd7cf6 33 int main() {
rafeh 16:95e3706790e5 34 init();
rafeh 2:9f5714571c41 35 if (pad.check_event(Gamepad::START_PRESSED) == false) {
rafeh 2:9f5714571c41 36 lcd.clear();
rafeh 2:9f5714571c41 37
rafeh 15:fc6b40fceb4f 38 ///////////////////////// Initialising Values////////////////////////////////////////////////////
rafeh 16:95e3706790e5 39 int bird_y=20; //y position of the bird
rafeh 15:fc6b40fceb4f 40 int xvalue=84; //initialising the x value of the first pipe (there will be two pipes on screen)
rafeh 15:fc6b40fceb4f 41 int xvalue2=0; //initialising the x value of the second pipe
rafeh 15:fc6b40fceb4f 42 int height = pipes.generate_height(); //initialising the height of the first pipe (top part of the pipe)
rafeh 16:95e3706790e5 43 int height2=0; //initialising the height of the second pipe (top part)
rafeh 15:fc6b40fceb4f 44 int score = 0; //initialising the score
rafeh 15:fc6b40fceb4f 45 int highscore = 0; //initialising the highscore
rafeh 15:fc6b40fceb4f 46
rafeh 15:fc6b40fceb4f 47 ///////////////////////////////////////////////////////////////////////////////////////////////////////
rafeh 2:9f5714571c41 48 while(1) {
rafeh 15:fc6b40fceb4f 49
rafeh 16:95e3706790e5 50 produce(xvalue,xvalue2,height,height2,BIRD_X,bird_y); //draw the pipes and the bird
rafeh 15:fc6b40fceb4f 51 print_score(score); //display the score on the top right
rafeh 8:d91564c0f337 52
rafeh 10:75de0f4da176 53 flappy.set_score(score);
rafeh 10:75de0f4da176 54 score=flappy.add_score(score,xvalue,BIRD_X,PIPE_WIDTH); //add score if the pipe has gone further left of the bird
rafeh 16:95e3706790e5 55 score=flappy.add_score(score,xvalue2,BIRD_X,PIPE_WIDTH); //check for both pipes
rafeh 15:fc6b40fceb4f 56
rafeh 15:fc6b40fceb4f 57 if(xvalue<29 && xvalue >27) { //generates a new pipe if the previous pipe has crossed a certain point
rafeh 14:9a9ac55616c4 58 height2=pipes.generate_height(); //a new height is generated for the new pipe (i.e. the placement of the gap is different)
rafeh 14:9a9ac55616c4 59 xvalue2=84;
rafeh 14:9a9ac55616c4 60 }
rafeh 15:fc6b40fceb4f 61 if(xvalue2<29 && xvalue2>27) { //does the same as above for the second pipe
rafeh 14:9a9ac55616c4 62 height=pipes.generate_height();
rafeh 3:5409b50b01b0 63 xvalue=84;
rafeh 14:9a9ac55616c4 64 }
rafeh 15:fc6b40fceb4f 65
rafeh 3:5409b50b01b0 66 wait(0.075);
rafeh 16:95e3706790e5 67 bird_y=bird.get_position(bird_y,pad); //gets the new vertical position for the bird
rafeh 14:9a9ac55616c4 68 if(xvalue>2) {
rafeh 15:fc6b40fceb4f 69 xvalue=xvalue-2; //moves the first pipes towards the left
rafeh 14:9a9ac55616c4 70 }
rafeh 14:9a9ac55616c4 71 if(xvalue2>2) {
rafeh 15:fc6b40fceb4f 72 xvalue2=xvalue2-2; //moves the second pipe towards the left
rafeh 14:9a9ac55616c4 73 }
rafeh 16:95e3706790e5 74 if ((flappy.check_collisions(bird_y,xvalue,height))||(flappy.check_collisions(bird_y,xvalue2,height2))) { //checking for collisions
rafeh 16:95e3706790e5 75 wait(1); // between the bird and both the pipes
rafeh 15:fc6b40fceb4f 76
rafeh 14:9a9ac55616c4 77 if (flappy.check_for_highscore(score,highscore)) { //check if the score was highscore
rafeh 10:75de0f4da176 78 highscore=score;}
rafeh 14:9a9ac55616c4 79 flappy.update_highscore(highscore); //update the highscore
rafeh 15:fc6b40fceb4f 80 flappy.display_score(lcd,pad);
rafeh 15:fc6b40fceb4f 81 wait(0.1);
rafeh 14:9a9ac55616c4 82 while (pad.check_event(Gamepad::A_PRESSED) == false) {
rafeh 10:75de0f4da176 83 lcd.clear();
rafeh 15:fc6b40fceb4f 84 flappy.display_score(lcd,pad); //display the score and highscore until button A is pressed
rafeh 14:9a9ac55616c4 85 if(pad.check_event(Gamepad::START_PRESSED) == false) { break;}
rafeh 10:75de0f4da176 86 }
rafeh 15:fc6b40fceb4f 87 score=0; //initialising the values again for the new game
rafeh 14:9a9ac55616c4 88 xvalue=84;
rafeh 16:95e3706790e5 89 bird_y=20;
rafeh 14:9a9ac55616c4 90 xvalue2=0;
rafeh 14:9a9ac55616c4 91 lcd.refresh();
rafeh 5:3a0948f56de0 92 }
rafeh 2:9f5714571c41 93 lcd.refresh();
rafeh 2:9f5714571c41 94 lcd.clear();
rafeh 2:9f5714571c41 95 }
rafeh 2:9f5714571c41 96 }
rafeh 10:75de0f4da176 97 }
rafeh 2:9f5714571c41 98
rafeh 15:fc6b40fceb4f 99
rafeh 15:fc6b40fceb4f 100
rafeh 16:95e3706790e5 101
rafeh 16:95e3706790e5 102 void init() {
rafeh 16:95e3706790e5 103 lcd.init();
rafeh 16:95e3706790e5 104 pad.init();
rafeh 16:95e3706790e5 105 lcd.clear();
rafeh 16:95e3706790e5 106 lcd.setContrast(0.5);
rafeh 16:95e3706790e5 107 entrance.welcome_page(lcd,pad); //display the welcome page
rafeh 16:95e3706790e5 108 }
rafeh 16:95e3706790e5 109
rafeh 16:95e3706790e5 110
rafeh 16:95e3706790e5 111
rafeh 16:95e3706790e5 112
rafeh 15:fc6b40fceb4f 113 void produce(int pipex1, int pipex2,int pipeheight1,int pipeheight2,int birdx,int birdy){
rafeh 15:fc6b40fceb4f 114 lcd.drawRect(0,45,84,3,FILL_BLACK); //draw the floor
rafeh 15:fc6b40fceb4f 115 if(pipex1>2) {
rafeh 15:fc6b40fceb4f 116 pipes.init(pipex1,pipeheight1); // draw the first pipes
rafeh 15:fc6b40fceb4f 117 pipes.draw(lcd);
rafeh 15:fc6b40fceb4f 118 }
rafeh 15:fc6b40fceb4f 119 if(pipex2>2){ //draw the second pipe
rafeh 16:95e3706790e5 120 pipes.init(pipex2,pipeheight2);
rafeh 16:95e3706790e5 121 pipes.draw(lcd);
rafeh 15:fc6b40fceb4f 122 }
rafeh 15:fc6b40fceb4f 123 bird.init(birdx,birdy); //draw the bird
rafeh 15:fc6b40fceb4f 124 bird.draw(lcd);
rafeh 15:fc6b40fceb4f 125 }
rafeh 15:fc6b40fceb4f 126
rafeh 15:fc6b40fceb4f 127
rafeh 10:75de0f4da176 128
rafeh 15:fc6b40fceb4f 129 void print_score(int scored_points) { //displays the score when the game is being played
rafeh 15:fc6b40fceb4f 130 char display[3];
rafeh 15:fc6b40fceb4f 131 sprintf(display,"%d",scored_points);
rafeh 15:fc6b40fceb4f 132 lcd.printString(display,60,0);
rafeh 15:fc6b40fceb4f 133 }
rafeh 16:95e3706790e5 134
rafeh 16:95e3706790e5 135