Aiming Wu
/
2645_Assignment
Doxyjen of the Bird.h
Bird/Bird.h@0:0aea7b9ba421, 2019-05-05 (annotated)
- Committer:
- Wuuu
- Date:
- Sun May 05 16:27:50 2019 +0000
- Revision:
- 0:0aea7b9ba421
- Child:
- 5:abe12cabd0b7
Doxyjen of the Bird.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wuuu | 0:0aea7b9ba421 | 1 | #ifndef BIRD_H |
Wuuu | 0:0aea7b9ba421 | 2 | #define BIRD_H |
Wuuu | 0:0aea7b9ba421 | 3 | |
Wuuu | 0:0aea7b9ba421 | 4 | #include "mbed.h" |
Wuuu | 0:0aea7b9ba421 | 5 | #include "N5110.h" |
Wuuu | 0:0aea7b9ba421 | 6 | #include "Gamepad.h" |
Wuuu | 0:0aea7b9ba421 | 7 | #include "Bitmap.h" |
Wuuu | 0:0aea7b9ba421 | 8 | |
Wuuu | 0:0aea7b9ba421 | 9 | /** Bird class |
Wuuu | 0:0aea7b9ba421 | 10 | |
Wuuu | 0:0aea7b9ba421 | 11 | *@brief Library to draw the bird |
Wuuu | 0:0aea7b9ba421 | 12 | *@author Wu Aiming |
Wuuu | 0:0aea7b9ba421 | 13 | *@date May 2017 |
Wuuu | 0:0aea7b9ba421 | 14 | |
Wuuu | 0:0aea7b9ba421 | 15 | @code |
Wuuu | 0:0aea7b9ba421 | 16 | |
Wuuu | 0:0aea7b9ba421 | 17 | #include "mbed.h" |
Wuuu | 0:0aea7b9ba421 | 18 | #include "N5110.h" |
Wuuu | 0:0aea7b9ba421 | 19 | #include "Gamepad.h" |
Wuuu | 0:0aea7b9ba421 | 20 | #include "Game1.h" |
Wuuu | 0:0aea7b9ba421 | 21 | #include "Begin.h" |
Wuuu | 0:0aea7b9ba421 | 22 | |
Wuuu | 0:0aea7b9ba421 | 23 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
Wuuu | 0:0aea7b9ba421 | 24 | Gamepad pad; |
Wuuu | 0:0aea7b9ba421 | 25 | Game1 gam; |
Wuuu | 0:0aea7b9ba421 | 26 | Begin beg; |
Wuuu | 0:0aea7b9ba421 | 27 | |
Wuuu | 0:0aea7b9ba421 | 28 | void init(); |
Wuuu | 0:0aea7b9ba421 | 29 | void menu(); |
Wuuu | 0:0aea7b9ba421 | 30 | void welcome1(); |
Wuuu | 0:0aea7b9ba421 | 31 | void loading(); |
Wuuu | 0:0aea7b9ba421 | 32 | void game1(); |
Wuuu | 0:0aea7b9ba421 | 33 | void welcome2(); |
Wuuu | 0:0aea7b9ba421 | 34 | void game2(); |
Wuuu | 0:0aea7b9ba421 | 35 | void made(); |
Wuuu | 0:0aea7b9ba421 | 36 | |
Wuuu | 0:0aea7b9ba421 | 37 | int main() { |
Wuuu | 0:0aea7b9ba421 | 38 | while(1){ |
Wuuu | 0:0aea7b9ba421 | 39 | init(); |
Wuuu | 0:0aea7b9ba421 | 40 | menu(); |
Wuuu | 0:0aea7b9ba421 | 41 | if(pad.check_event(Gamepad::Y_PRESSED) == true){ |
Wuuu | 0:0aea7b9ba421 | 42 | while(pad.check_event(Gamepad::BACK_PRESSED) == false){ |
Wuuu | 0:0aea7b9ba421 | 43 | init(); |
Wuuu | 0:0aea7b9ba421 | 44 | welcome1(); |
Wuuu | 0:0aea7b9ba421 | 45 | if(pad.check_event(Gamepad::START_PRESSED) == true) { |
Wuuu | 0:0aea7b9ba421 | 46 | loading(); |
Wuuu | 0:0aea7b9ba421 | 47 | game1(); |
Wuuu | 0:0aea7b9ba421 | 48 | } |
Wuuu | 0:0aea7b9ba421 | 49 | wait(0.1); |
Wuuu | 0:0aea7b9ba421 | 50 | } |
Wuuu | 0:0aea7b9ba421 | 51 | } |
Wuuu | 0:0aea7b9ba421 | 52 | if(pad.check_event(Gamepad::A_PRESSED) == true){ |
Wuuu | 0:0aea7b9ba421 | 53 | while(pad.check_event(Gamepad::BACK_PRESSED) == false){ |
Wuuu | 0:0aea7b9ba421 | 54 | init(); |
Wuuu | 0:0aea7b9ba421 | 55 | welcome2(); |
Wuuu | 0:0aea7b9ba421 | 56 | if(pad.check_event(Gamepad::START_PRESSED) == true) { |
Wuuu | 0:0aea7b9ba421 | 57 | loading(); |
Wuuu | 0:0aea7b9ba421 | 58 | game2(); |
Wuuu | 0:0aea7b9ba421 | 59 | } |
Wuuu | 0:0aea7b9ba421 | 60 | wait(0.1); |
Wuuu | 0:0aea7b9ba421 | 61 | } |
Wuuu | 0:0aea7b9ba421 | 62 | } |
Wuuu | 0:0aea7b9ba421 | 63 | if(pad.check_event(Gamepad::B_PRESSED) == true){ |
Wuuu | 0:0aea7b9ba421 | 64 | made(); |
Wuuu | 0:0aea7b9ba421 | 65 | } |
Wuuu | 0:0aea7b9ba421 | 66 | wait(0.1); |
Wuuu | 0:0aea7b9ba421 | 67 | } |
Wuuu | 0:0aea7b9ba421 | 68 | } |
Wuuu | 0:0aea7b9ba421 | 69 | |
Wuuu | 0:0aea7b9ba421 | 70 | void init() |
Wuuu | 0:0aea7b9ba421 | 71 | { |
Wuuu | 0:0aea7b9ba421 | 72 | lcd.init(); |
Wuuu | 0:0aea7b9ba421 | 73 | pad.init(); |
Wuuu | 0:0aea7b9ba421 | 74 | gam.init(); |
Wuuu | 0:0aea7b9ba421 | 75 | beg.init(); |
Wuuu | 0:0aea7b9ba421 | 76 | } |
Wuuu | 0:0aea7b9ba421 | 77 | |
Wuuu | 0:0aea7b9ba421 | 78 | void menu() |
Wuuu | 0:0aea7b9ba421 | 79 | { |
Wuuu | 0:0aea7b9ba421 | 80 | lcd.clear(); |
Wuuu | 0:0aea7b9ba421 | 81 | lcd.printString("Press button",0,0); |
Wuuu | 0:0aea7b9ba421 | 82 | lcd.printString("to select",0,1); |
Wuuu | 0:0aea7b9ba421 | 83 | lcd.printString("Y: Copter",0,2); |
Wuuu | 0:0aea7b9ba421 | 84 | lcd.printString("A: FlappyBird",0,3); |
Wuuu | 0:0aea7b9ba421 | 85 | lcd.printString("B: Made by",0,4); |
Wuuu | 0:0aea7b9ba421 | 86 | lcd.refresh(); |
Wuuu | 0:0aea7b9ba421 | 87 | wait(0.3); |
Wuuu | 0:0aea7b9ba421 | 88 | } |
Wuuu | 0:0aea7b9ba421 | 89 | |
Wuuu | 0:0aea7b9ba421 | 90 | void made() |
Wuuu | 0:0aea7b9ba421 | 91 | { |
Wuuu | 0:0aea7b9ba421 | 92 | while(pad.check_event(Gamepad::BACK_PRESSED) == false){ |
Wuuu | 0:0aea7b9ba421 | 93 | lcd.clear(); |
Wuuu | 0:0aea7b9ba421 | 94 | lcd.printString(" Programme by:",0,1); |
Wuuu | 0:0aea7b9ba421 | 95 | lcd.printString(" Wu Aiming ",0,2); |
Wuuu | 0:0aea7b9ba421 | 96 | lcd.printString(" 201090185 ",0,3); |
Wuuu | 0:0aea7b9ba421 | 97 | lcd.printString(" 2016110323 ",0,4); |
Wuuu | 0:0aea7b9ba421 | 98 | lcd.refresh(); |
Wuuu | 0:0aea7b9ba421 | 99 | wait(0.5); |
Wuuu | 0:0aea7b9ba421 | 100 | } |
Wuuu | 0:0aea7b9ba421 | 101 | } |
Wuuu | 0:0aea7b9ba421 | 102 | |
Wuuu | 0:0aea7b9ba421 | 103 | void welcome1() { |
Wuuu | 0:0aea7b9ba421 | 104 | lcd.clear(); |
Wuuu | 0:0aea7b9ba421 | 105 | lcd.printString(" Copter! ",0,1); |
Wuuu | 0:0aea7b9ba421 | 106 | lcd.printString(" Press Start ",0,4); |
Wuuu | 0:0aea7b9ba421 | 107 | lcd.refresh(); |
Wuuu | 0:0aea7b9ba421 | 108 | |
Wuuu | 0:0aea7b9ba421 | 109 | pad.leds_on(); |
Wuuu | 0:0aea7b9ba421 | 110 | wait(0.1); |
Wuuu | 0:0aea7b9ba421 | 111 | pad.leds_off(); |
Wuuu | 0:0aea7b9ba421 | 112 | wait(0.1); |
Wuuu | 0:0aea7b9ba421 | 113 | |
Wuuu | 0:0aea7b9ba421 | 114 | } |
Wuuu | 0:0aea7b9ba421 | 115 | |
Wuuu | 0:0aea7b9ba421 | 116 | void loading(){ |
Wuuu | 0:0aea7b9ba421 | 117 | lcd.clear(); |
Wuuu | 0:0aea7b9ba421 | 118 | lcd.printString(" READY!!! ",0,3); |
Wuuu | 0:0aea7b9ba421 | 119 | lcd.refresh(); |
Wuuu | 0:0aea7b9ba421 | 120 | wait_ms(500); |
Wuuu | 0:0aea7b9ba421 | 121 | lcd.clear(); |
Wuuu | 0:0aea7b9ba421 | 122 | lcd.printString(" 3 ",0,3); |
Wuuu | 0:0aea7b9ba421 | 123 | lcd.refresh(); |
Wuuu | 0:0aea7b9ba421 | 124 | wait_ms(500); |
Wuuu | 0:0aea7b9ba421 | 125 | lcd.clear(); |
Wuuu | 0:0aea7b9ba421 | 126 | lcd.printString(" 2 ",0,3); |
Wuuu | 0:0aea7b9ba421 | 127 | lcd.refresh(); |
Wuuu | 0:0aea7b9ba421 | 128 | wait_ms(500); |
Wuuu | 0:0aea7b9ba421 | 129 | lcd.clear(); |
Wuuu | 0:0aea7b9ba421 | 130 | lcd.printString(" 1 ",0,3); |
Wuuu | 0:0aea7b9ba421 | 131 | lcd.refresh(); |
Wuuu | 0:0aea7b9ba421 | 132 | wait_ms(500); |
Wuuu | 0:0aea7b9ba421 | 133 | lcd.clear(); |
Wuuu | 0:0aea7b9ba421 | 134 | lcd.printString(" GO!!! ",0,3); |
Wuuu | 0:0aea7b9ba421 | 135 | lcd.refresh(); |
Wuuu | 0:0aea7b9ba421 | 136 | wait_ms(500); |
Wuuu | 0:0aea7b9ba421 | 137 | } |
Wuuu | 0:0aea7b9ba421 | 138 | |
Wuuu | 0:0aea7b9ba421 | 139 | void game1() |
Wuuu | 0:0aea7b9ba421 | 140 | { |
Wuuu | 0:0aea7b9ba421 | 141 | while(pad.check_event(Gamepad::BACK_PRESSED) == false) { |
Wuuu | 0:0aea7b9ba421 | 142 | lcd.clear(); |
Wuuu | 0:0aea7b9ba421 | 143 | int d = gam.draw(lcd, pad); |
Wuuu | 0:0aea7b9ba421 | 144 | if(d == 1) { |
Wuuu | 0:0aea7b9ba421 | 145 | int s = gam.get_score(); |
Wuuu | 0:0aea7b9ba421 | 146 | lcd.clear(); |
Wuuu | 0:0aea7b9ba421 | 147 | lcd.printString("Your score is", 0, 2); |
Wuuu | 0:0aea7b9ba421 | 148 | char buffer2[14]; |
Wuuu | 0:0aea7b9ba421 | 149 | sprintf(buffer2," %2d ",s); |
Wuuu | 0:0aea7b9ba421 | 150 | lcd.printString(buffer2,2,4); |
Wuuu | 0:0aea7b9ba421 | 151 | lcd.refresh(); |
Wuuu | 0:0aea7b9ba421 | 152 | wait(1); |
Wuuu | 0:0aea7b9ba421 | 153 | break; |
Wuuu | 0:0aea7b9ba421 | 154 | } |
Wuuu | 0:0aea7b9ba421 | 155 | lcd.refresh(); |
Wuuu | 0:0aea7b9ba421 | 156 | wait(0.8); |
Wuuu | 0:0aea7b9ba421 | 157 | } |
Wuuu | 0:0aea7b9ba421 | 158 | } |
Wuuu | 0:0aea7b9ba421 | 159 | |
Wuuu | 0:0aea7b9ba421 | 160 | void welcome2() { |
Wuuu | 0:0aea7b9ba421 | 161 | lcd.clear(); |
Wuuu | 0:0aea7b9ba421 | 162 | lcd.printString(" FlappyBird! ",0,1); |
Wuuu | 0:0aea7b9ba421 | 163 | lcd.printString(" Press Start ",0,4); |
Wuuu | 0:0aea7b9ba421 | 164 | lcd.refresh(); |
Wuuu | 0:0aea7b9ba421 | 165 | |
Wuuu | 0:0aea7b9ba421 | 166 | pad.leds_on(); |
Wuuu | 0:0aea7b9ba421 | 167 | wait(0.1); |
Wuuu | 0:0aea7b9ba421 | 168 | pad.leds_off(); |
Wuuu | 0:0aea7b9ba421 | 169 | wait(0.1); |
Wuuu | 0:0aea7b9ba421 | 170 | |
Wuuu | 0:0aea7b9ba421 | 171 | } |
Wuuu | 0:0aea7b9ba421 | 172 | |
Wuuu | 0:0aea7b9ba421 | 173 | void game2() |
Wuuu | 0:0aea7b9ba421 | 174 | { |
Wuuu | 0:0aea7b9ba421 | 175 | while(pad.check_event(Gamepad::BACK_PRESSED) == false) { |
Wuuu | 0:0aea7b9ba421 | 176 | lcd.clear(); |
Wuuu | 0:0aea7b9ba421 | 177 | int d = beg.draw(lcd, pad); |
Wuuu | 0:0aea7b9ba421 | 178 | if(d == 1) { |
Wuuu | 0:0aea7b9ba421 | 179 | int s = beg.get_score(lcd); |
Wuuu | 0:0aea7b9ba421 | 180 | lcd.clear(); |
Wuuu | 0:0aea7b9ba421 | 181 | lcd.printString("Your score is", 0, 2); |
Wuuu | 0:0aea7b9ba421 | 182 | char buffer2[14]; |
Wuuu | 0:0aea7b9ba421 | 183 | sprintf(buffer2," %2d ",s); |
Wuuu | 0:0aea7b9ba421 | 184 | lcd.printString(buffer2,2,4); |
Wuuu | 0:0aea7b9ba421 | 185 | lcd.refresh(); |
Wuuu | 0:0aea7b9ba421 | 186 | wait(1); |
Wuuu | 0:0aea7b9ba421 | 187 | break; |
Wuuu | 0:0aea7b9ba421 | 188 | } |
Wuuu | 0:0aea7b9ba421 | 189 | lcd.refresh(); |
Wuuu | 0:0aea7b9ba421 | 190 | wait(0.3); |
Wuuu | 0:0aea7b9ba421 | 191 | } |
Wuuu | 0:0aea7b9ba421 | 192 | } |
Wuuu | 0:0aea7b9ba421 | 193 | |
Wuuu | 0:0aea7b9ba421 | 194 | @endcode |
Wuuu | 0:0aea7b9ba421 | 195 | */ |
Wuuu | 0:0aea7b9ba421 | 196 | |
Wuuu | 0:0aea7b9ba421 | 197 | class Bird |
Wuuu | 0:0aea7b9ba421 | 198 | { |
Wuuu | 0:0aea7b9ba421 | 199 | public: |
Wuuu | 0:0aea7b9ba421 | 200 | /**Constructor*/ |
Wuuu | 0:0aea7b9ba421 | 201 | Bird(); |
Wuuu | 0:0aea7b9ba421 | 202 | /**Destructor*/ |
Wuuu | 0:0aea7b9ba421 | 203 | ~Bird(); |
Wuuu | 0:0aea7b9ba421 | 204 | /** |
Wuuu | 0:0aea7b9ba421 | 205 | *@brief Initialise all parameters of the bird |
Wuuu | 0:0aea7b9ba421 | 206 | */ |
Wuuu | 0:0aea7b9ba421 | 207 | void init(); |
Wuuu | 0:0aea7b9ba421 | 208 | /** |
Wuuu | 0:0aea7b9ba421 | 209 | *@brief Draw the bird |
Wuuu | 0:0aea7b9ba421 | 210 | *@param lcd, pad |
Wuuu | 0:0aea7b9ba421 | 211 | *@returns The position of bird |
Wuuu | 0:0aea7b9ba421 | 212 | *@details Use the method to use function within N5110.h and Gamepad.h file |
Wuuu | 0:0aea7b9ba421 | 213 | */ |
Wuuu | 0:0aea7b9ba421 | 214 | int draw(N5110 &lcd,Gamepad &pad); |
Wuuu | 0:0aea7b9ba421 | 215 | |
Wuuu | 0:0aea7b9ba421 | 216 | private: |
Wuuu | 0:0aea7b9ba421 | 217 | |
Wuuu | 0:0aea7b9ba421 | 218 | int _h; |
Wuuu | 0:0aea7b9ba421 | 219 | }; |
Wuuu | 0:0aea7b9ba421 | 220 | |
Wuuu | 0:0aea7b9ba421 | 221 | #endif |