Doxygen comments added
Dependencies: mbed Gamepad N5110
main.cpp@14:9a9ac55616c4, 2019-05-09 (annotated)
- Committer:
- rafeh
- Date:
- Thu May 09 10:25:47 2019 +0000
- Revision:
- 14:9a9ac55616c4
- Parent:
- 10:75de0f4da176
- Child:
- 15:fc6b40fceb4f
can now generate two pipes on screen at the same time
Who changed what in which revision?
User | Revision | Line number | New 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 | 14:9a9ac55616c4 | 26 | Pipes pipes2; |
rafeh | 14:9a9ac55616c4 | 27 | float cont = pad.read_pot(); |
rafeh | 7:05f433e196d6 | 28 | int yaxis=20; //y position of the bird |
rafeh | 3:5409b50b01b0 | 29 | |
rafeh | 0:43364ffd7cf6 | 30 | int main() { |
rafeh | 0:43364ffd7cf6 | 31 | lcd.init(); |
rafeh | 0:43364ffd7cf6 | 32 | pad.init(); |
rafeh | 0:43364ffd7cf6 | 33 | lcd.clear(); |
rafeh | 14:9a9ac55616c4 | 34 | lcd.setContrast(0.5); |
rafeh | 10:75de0f4da176 | 35 | entrance.welcome_page(lcd,pad); |
rafeh | 2:9f5714571c41 | 36 | if (pad.check_event(Gamepad::START_PRESSED) == false) { |
rafeh | 2:9f5714571c41 | 37 | lcd.clear(); |
rafeh | 2:9f5714571c41 | 38 | |
rafeh | 10:75de0f4da176 | 39 | int xvalue=84; //initialising the x value of the pipes |
rafeh | 14:9a9ac55616c4 | 40 | int xvalue2=0; |
rafeh | 10:75de0f4da176 | 41 | int height = pipes.generate_height(); //initialising the height of the top pipe |
rafeh | 14:9a9ac55616c4 | 42 | int height2=0; |
rafeh | 3:5409b50b01b0 | 43 | int score = 0; |
rafeh | 7:05f433e196d6 | 44 | int highscore = 0; |
rafeh | 14:9a9ac55616c4 | 45 | char scoredisplay[3]; //to display score |
rafeh | 2:9f5714571c41 | 46 | while(1) { |
rafeh | 10:75de0f4da176 | 47 | |
rafeh | 14:9a9ac55616c4 | 48 | pad.tone(5000,0.2); |
rafeh | 7:05f433e196d6 | 49 | lcd.drawRect(0,45,84,3,FILL_BLACK); //draw the floor |
rafeh | 14:9a9ac55616c4 | 50 | if(xvalue>2) { |
rafeh | 7:05f433e196d6 | 51 | pipes.init(xvalue,height); // draw the pipes |
rafeh | 14:9a9ac55616c4 | 52 | pipes.draw(lcd); |
rafeh | 14:9a9ac55616c4 | 53 | } |
rafeh | 14:9a9ac55616c4 | 54 | if(xvalue2>2){ |
rafeh | 14:9a9ac55616c4 | 55 | pipes2.init(xvalue2,height2); |
rafeh | 14:9a9ac55616c4 | 56 | pipes2.draw(lcd); |
rafeh | 14:9a9ac55616c4 | 57 | } |
rafeh | 10:75de0f4da176 | 58 | bird.init(BIRD_X,yaxis); //draw the bird |
rafeh | 10:75de0f4da176 | 59 | bird.draw(lcd); |
rafeh | 7:05f433e196d6 | 60 | sprintf(scoredisplay,"%d",score); |
rafeh | 10:75de0f4da176 | 61 | lcd.printString(scoredisplay,60,0); //display the score on the top right |
rafeh | 8:d91564c0f337 | 62 | |
rafeh | 10:75de0f4da176 | 63 | flappy.set_score(score); |
rafeh | 10:75de0f4da176 | 64 | score=flappy.add_score(score,xvalue,BIRD_X,PIPE_WIDTH); //add score if the pipe has gone further left of the bird |
rafeh | 14:9a9ac55616c4 | 65 | score=flappy.add_score(score,xvalue2,BIRD_X,PIPE_WIDTH); |
rafeh | 3:5409b50b01b0 | 66 | |
rafeh | 14:9a9ac55616c4 | 67 | if(xvalue<25 && xvalue >23) { //generates a new pipe |
rafeh | 14:9a9ac55616c4 | 68 | 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 | 69 | xvalue2=84; |
rafeh | 14:9a9ac55616c4 | 70 | } |
rafeh | 14:9a9ac55616c4 | 71 | if(xvalue<25 && xvalue >23) { //generates a new pipe |
rafeh | 14:9a9ac55616c4 | 72 | 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 | 73 | xvalue2=84; |
rafeh | 14:9a9ac55616c4 | 74 | } |
rafeh | 14:9a9ac55616c4 | 75 | if(xvalue2<25 && xvalue2>23) { |
rafeh | 14:9a9ac55616c4 | 76 | height=pipes.generate_height(); |
rafeh | 3:5409b50b01b0 | 77 | xvalue=84; |
rafeh | 14:9a9ac55616c4 | 78 | } |
rafeh | 3:5409b50b01b0 | 79 | |
rafeh | 7:05f433e196d6 | 80 | |
rafeh | 3:5409b50b01b0 | 81 | wait(0.075); |
rafeh | 10:75de0f4da176 | 82 | yaxis=bird.get_position(yaxis,pad); //gets new vertical position for the bird |
rafeh | 14:9a9ac55616c4 | 83 | if(xvalue>2) { |
rafeh | 10:75de0f4da176 | 84 | xvalue=xvalue-2; //moves the pipes towards the left |
rafeh | 14:9a9ac55616c4 | 85 | } |
rafeh | 14:9a9ac55616c4 | 86 | if(xvalue2>2) { |
rafeh | 14:9a9ac55616c4 | 87 | xvalue2=xvalue2-2; |
rafeh | 14:9a9ac55616c4 | 88 | } |
rafeh | 14:9a9ac55616c4 | 89 | if ((flappy.check_collisions(yaxis,xvalue,height))||(flappy.check_collisions(yaxis,xvalue2,height2))) { //checking for collisions |
rafeh | 5:3a0948f56de0 | 90 | wait(1); |
rafeh | 14:9a9ac55616c4 | 91 | if (flappy.check_for_highscore(score,highscore)) { //check if the score was highscore |
rafeh | 10:75de0f4da176 | 92 | highscore=score;} |
rafeh | 14:9a9ac55616c4 | 93 | flappy.update_highscore(highscore); //update the highscore |
rafeh | 14:9a9ac55616c4 | 94 | while (pad.check_event(Gamepad::A_PRESSED) == false) { |
rafeh | 10:75de0f4da176 | 95 | lcd.clear(); |
rafeh | 14:9a9ac55616c4 | 96 | flappy.display_score(lcd,pad); // |
rafeh | 14:9a9ac55616c4 | 97 | if(pad.check_event(Gamepad::START_PRESSED) == false) { break;} |
rafeh | 10:75de0f4da176 | 98 | } |
rafeh | 7:05f433e196d6 | 99 | score=0; |
rafeh | 14:9a9ac55616c4 | 100 | xvalue=84; |
rafeh | 14:9a9ac55616c4 | 101 | yaxis=20; |
rafeh | 14:9a9ac55616c4 | 102 | xvalue2=0; |
rafeh | 14:9a9ac55616c4 | 103 | lcd.refresh(); |
rafeh | 5:3a0948f56de0 | 104 | } |
rafeh | 2:9f5714571c41 | 105 | lcd.refresh(); |
rafeh | 2:9f5714571c41 | 106 | lcd.clear(); |
rafeh | 2:9f5714571c41 | 107 | } |
rafeh | 2:9f5714571c41 | 108 | } |
rafeh | 10:75de0f4da176 | 109 | } |
rafeh | 2:9f5714571c41 | 110 | |
rafeh | 10:75de0f4da176 | 111 | |
rafeh | 10:75de0f4da176 | 112 | |
rafeh | 10:75de0f4da176 | 113 |