Final Submission. I have read and agreed with Statement of Academic Integrity.

Dependencies:   mbed Gamepad FLAPPY_BIRD

Committer:
877963042
Date:
Sun May 05 14:57:07 2019 +0000
Revision:
0:bfd3317d7773
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
877963042 0:bfd3317d7773 1
877963042 0:bfd3317d7773 2 #include "Bird.h"
877963042 0:bfd3317d7773 3
877963042 0:bfd3317d7773 4 // parameter
877963042 0:bfd3317d7773 5 int _vb = 1;
877963042 0:bfd3317d7773 6
877963042 0:bfd3317d7773 7 // initialise the parameter
877963042 0:bfd3317d7773 8 void Bird::init(){
877963042 0:bfd3317d7773 9 _birdy = 1;
877963042 0:bfd3317d7773 10 _x1 = 45; // 21 space interval
877963042 0:bfd3317d7773 11 _x2 = 66;
877963042 0:bfd3317d7773 12 _x3 = 88;
877963042 0:bfd3317d7773 13 _x4 = 109;
877963042 0:bfd3317d7773 14 _y1 =rand()%18+2;
877963042 0:bfd3317d7773 15 _y2 =rand()%18+2;
877963042 0:bfd3317d7773 16 _y3 =rand()%18+2;
877963042 0:bfd3317d7773 17 _y4 =rand()%18+2;
877963042 0:bfd3317d7773 18 _score = 0;
877963042 0:bfd3317d7773 19 }
877963042 0:bfd3317d7773 20
877963042 0:bfd3317d7773 21 // welcome screen - FLAPPY BRID
877963042 0:bfd3317d7773 22 void Bird::welcome(N5110 &lcd)
877963042 0:bfd3317d7773 23 {
877963042 0:bfd3317d7773 24
877963042 0:bfd3317d7773 25 // // F 2*6+7*2+2*5+9*2
877963042 0:bfd3317d7773 26 int F[20][6] = {
877963042 0:bfd3317d7773 27 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 28 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 29 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 30 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 31 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 32 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 33 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 34 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 35 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 36 { 1,1,1,1,1,0 },
877963042 0:bfd3317d7773 37 { 1,1,1,1,1,0 },
877963042 0:bfd3317d7773 38 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 39 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 40 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 41 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 42 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 43 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 44 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 45 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 46 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 47
877963042 0:bfd3317d7773 48
877963042 0:bfd3317d7773 49 };
877963042 0:bfd3317d7773 50
877963042 0:bfd3317d7773 51 // L 18*2+2*6
877963042 0:bfd3317d7773 52 int L[20][6] = {
877963042 0:bfd3317d7773 53 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 54 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 55 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 56 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 57 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 58 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 59 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 60 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 61 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 62 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 63 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 64 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 65 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 66 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 67 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 68 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 69 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 70 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 71 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 72 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 73 };
877963042 0:bfd3317d7773 74
877963042 0:bfd3317d7773 75 // A 2*6+7*4+2*6+9*4
877963042 0:bfd3317d7773 76 int A[20][6] = {
877963042 0:bfd3317d7773 77 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 78 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 79 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 80 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 81 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 82 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 83 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 84 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 85 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 86 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 87 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 88 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 89 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 90 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 91 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 92 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 93 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 94 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 95 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 96 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 97 };
877963042 0:bfd3317d7773 98
877963042 0:bfd3317d7773 99 // P 2*6+7*4+2*6+9*2
877963042 0:bfd3317d7773 100 int P[20][6] = {
877963042 0:bfd3317d7773 101 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 102 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 103 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 104 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 105 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 106 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 107 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 108 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 109 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 110 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 111 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 112 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 113 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 114 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 115 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 116 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 117 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 118 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 119 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 120 { 1,1,0,0,0,0 },
877963042 0:bfd3317d7773 121 };
877963042 0:bfd3317d7773 122
877963042 0:bfd3317d7773 123 // Y 11*4+9*2
877963042 0:bfd3317d7773 124 int Y[20][6] = {
877963042 0:bfd3317d7773 125 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 126 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 127 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 128 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 129 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 130 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 131 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 132 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 133 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 134 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 135 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 136 { 0,0,1,1,0,0 },
877963042 0:bfd3317d7773 137 { 0,0,1,1,0,0 },
877963042 0:bfd3317d7773 138 { 0,0,1,1,0,0 },
877963042 0:bfd3317d7773 139 { 0,0,1,1,0,0 },
877963042 0:bfd3317d7773 140 { 0,0,1,1,0,0 },
877963042 0:bfd3317d7773 141 { 0,0,1,1,0,0 },
877963042 0:bfd3317d7773 142 { 0,0,1,1,0,0 },
877963042 0:bfd3317d7773 143 { 0,0,1,1,0,0 },
877963042 0:bfd3317d7773 144 { 0,0,1,1,0,0 },
877963042 0:bfd3317d7773 145 };
877963042 0:bfd3317d7773 146
877963042 0:bfd3317d7773 147 // B 1*4+1*5+1*5+ 5*4+1*5+2*5+1*5+5*4+1*5+1*5+1*4
877963042 0:bfd3317d7773 148 int B[20][6] = {
877963042 0:bfd3317d7773 149 { 1,1,1,1,0,0 },
877963042 0:bfd3317d7773 150 { 1,1,1,1,1,0 },
877963042 0:bfd3317d7773 151 { 1,1,0,1,1,1 },
877963042 0:bfd3317d7773 152 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 153 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 154 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 155 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 156 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 157 { 1,1,0,1,1,1 },
877963042 0:bfd3317d7773 158 { 1,1,1,1,1,0 },
877963042 0:bfd3317d7773 159 { 1,1,1,1,1,0 },
877963042 0:bfd3317d7773 160 { 1,1,0,1,1,1 },
877963042 0:bfd3317d7773 161 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 162 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 163 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 164 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 165 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 166 { 1,1,0,1,1,1 },
877963042 0:bfd3317d7773 167 { 1,1,1,1,1,0 },
877963042 0:bfd3317d7773 168 { 1,1,1,1,0,0 },
877963042 0:bfd3317d7773 169 };
877963042 0:bfd3317d7773 170
877963042 0:bfd3317d7773 171 // I 20*2
877963042 0:bfd3317d7773 172 int I[20][2] = {
877963042 0:bfd3317d7773 173 { 1,1 },
877963042 0:bfd3317d7773 174 { 1,1 },
877963042 0:bfd3317d7773 175 { 1,1 },
877963042 0:bfd3317d7773 176 { 1,1 },
877963042 0:bfd3317d7773 177 { 1,1 },
877963042 0:bfd3317d7773 178 { 1,1 },
877963042 0:bfd3317d7773 179 { 1,1 },
877963042 0:bfd3317d7773 180 { 1,1 },
877963042 0:bfd3317d7773 181 { 1,1 },
877963042 0:bfd3317d7773 182 { 1,1 },
877963042 0:bfd3317d7773 183 { 1,1 },
877963042 0:bfd3317d7773 184 { 1,1 },
877963042 0:bfd3317d7773 185 { 1,1 },
877963042 0:bfd3317d7773 186 { 1,1 },
877963042 0:bfd3317d7773 187 { 1,1 },
877963042 0:bfd3317d7773 188 { 1,1 },
877963042 0:bfd3317d7773 189 { 1,1 },
877963042 0:bfd3317d7773 190 { 1,1 },
877963042 0:bfd3317d7773 191 { 1,1 },
877963042 0:bfd3317d7773 192 { 1,1 },
877963042 0:bfd3317d7773 193 };
877963042 0:bfd3317d7773 194
877963042 0:bfd3317d7773 195 // R 2*6+7*4+2*6+1*4+1*5+1*5+6*4
877963042 0:bfd3317d7773 196 int R[20][6] = {
877963042 0:bfd3317d7773 197 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 198 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 199 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 200 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 201 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 202 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 203 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 204 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 205 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 206 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 207 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 208 { 1,1,1,1,0,0 },
877963042 0:bfd3317d7773 209 { 1,1,1,1,1,0 },
877963042 0:bfd3317d7773 210 { 1,1,0,1,1,1 },
877963042 0:bfd3317d7773 211 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 212 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 213 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 214 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 215 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 216 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 217 };
877963042 0:bfd3317d7773 218
877963042 0:bfd3317d7773 219 // D 1*4+1*5+1*5+14*4+1*5+1*5+1*4
877963042 0:bfd3317d7773 220 int D[20][6] = {
877963042 0:bfd3317d7773 221 { 1,1,1,1,0,0 },
877963042 0:bfd3317d7773 222 { 1,1,1,1,1,0 },
877963042 0:bfd3317d7773 223 { 1,1,0,1,1,1 },
877963042 0:bfd3317d7773 224 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 225 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 226 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 227 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 228 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 229 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 230 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 231 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 232 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 233 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 234 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 235 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 236 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 237 { 1,1,0,0,1,1 },
877963042 0:bfd3317d7773 238 { 1,1,0,1,1,1 },
877963042 0:bfd3317d7773 239 { 1,1,1,1,1,0 },
877963042 0:bfd3317d7773 240 { 1,1,1,1,0,0 },
877963042 0:bfd3317d7773 241 };
877963042 0:bfd3317d7773 242
877963042 0:bfd3317d7773 243 // // drawSprite(x_origin,y_origin,x_rows,y_coloums,sprite)
877963042 0:bfd3317d7773 244 lcd.drawSprite(4,2,20,6,(int *)F);
877963042 0:bfd3317d7773 245 lcd.drawSprite(12,2,20,6,(int *)L);
877963042 0:bfd3317d7773 246 lcd.drawSprite(20,2,20,6,(int *)A);
877963042 0:bfd3317d7773 247 lcd.drawSprite(28,2,20,6,(int *)P);
877963042 0:bfd3317d7773 248 lcd.drawSprite(36,2,20,6,(int *)P);
877963042 0:bfd3317d7773 249 lcd.drawSprite(44,2,20,6,(int *)Y);
877963042 0:bfd3317d7773 250 lcd.drawSprite(55,2,20,6,(int *)B);
877963042 0:bfd3317d7773 251 lcd.drawSprite(63,2,20,2,(int *)I);
877963042 0:bfd3317d7773 252 lcd.drawSprite(67,2,20,6,(int *)R);
877963042 0:bfd3317d7773 253 lcd.drawSprite(75,2,20,6,(int *)D);
877963042 0:bfd3317d7773 254 // draw a rectangular around the title
877963042 0:bfd3317d7773 255 lcd.drawRect(0,0,WIDTH,24,FILL_TRANSPARENT);
877963042 0:bfd3317d7773 256 lcd.printString(" Press Start ",0,4);
877963042 0:bfd3317d7773 257 lcd.printString(" To Play ",0,5);
877963042 0:bfd3317d7773 258
877963042 0:bfd3317d7773 259 }
877963042 0:bfd3317d7773 260
877963042 0:bfd3317d7773 261 // choosing difficulty
877963042 0:bfd3317d7773 262 void Bird::mode(N5110 &lcd, Gamepad &pad)
877963042 0:bfd3317d7773 263 {
877963042 0:bfd3317d7773 264 lcd.clear();
877963042 0:bfd3317d7773 265 lcd.printString("Difficulty !",5,0);
877963042 0:bfd3317d7773 266 lcd.printString("Joy to tune,",0,1);
877963042 0:bfd3317d7773 267 lcd.printString("A to select. ",0,2);
877963042 0:bfd3317d7773 268 lcd.printString("Slow",30,3);
877963042 0:bfd3317d7773 269 lcd.printString("Medium",29,4);
877963042 0:bfd3317d7773 270 lcd.printString("Fast",30,5);
877963042 0:bfd3317d7773 271 int select[5][6] = {
877963042 0:bfd3317d7773 272 { 1,1,1,1,0,0 },
877963042 0:bfd3317d7773 273 { 1,1,0,0,1,0 },
877963042 0:bfd3317d7773 274 { 1,1,0,0,0,1 },
877963042 0:bfd3317d7773 275 { 1,1,0,0,1,0 },
877963042 0:bfd3317d7773 276 { 1,1,1,1,0,0 },
877963042 0:bfd3317d7773 277 };
877963042 0:bfd3317d7773 278 Direction d = pad.get_direction();
877963042 0:bfd3317d7773 279 if (d == S){
877963042 0:bfd3317d7773 280 _vb = _vb+1;
877963042 0:bfd3317d7773 281 }
877963042 0:bfd3317d7773 282 else if (d == N) {
877963042 0:bfd3317d7773 283 _vb = _vb-1;
877963042 0:bfd3317d7773 284 }
877963042 0:bfd3317d7773 285 if (_vb > 3) {
877963042 0:bfd3317d7773 286 _vb = 1;
877963042 0:bfd3317d7773 287 }
877963042 0:bfd3317d7773 288 if (_vb < 1){
877963042 0:bfd3317d7773 289 _vb = 3;
877963042 0:bfd3317d7773 290 }
877963042 0:bfd3317d7773 291 lcd.drawSprite(20,_vb*8+17,5,6,(int *)select);
877963042 0:bfd3317d7773 292 lcd.refresh();
877963042 0:bfd3317d7773 293 wait(0.3);
877963042 0:bfd3317d7773 294 }
877963042 0:bfd3317d7773 295
877963042 0:bfd3317d7773 296 // display score
877963042 0:bfd3317d7773 297 void Bird::score(N5110 &lcd){
877963042 0:bfd3317d7773 298 if(_x1+4 > 14-_vb && _x1+4 < 15){
877963042 0:bfd3317d7773 299 _score = _score +1;
877963042 0:bfd3317d7773 300 }
877963042 0:bfd3317d7773 301 if(_x2+4 > 14-_vb && _x2+4 < 15){
877963042 0:bfd3317d7773 302 _score = _score +1;
877963042 0:bfd3317d7773 303 }
877963042 0:bfd3317d7773 304 if(_x3+4 > 14-_vb && _x3+4 < 15){
877963042 0:bfd3317d7773 305 _score = _score +1;
877963042 0:bfd3317d7773 306 }
877963042 0:bfd3317d7773 307 if(_x4+4 > 14-_vb && _x4+4 < 15){
877963042 0:bfd3317d7773 308 _score = _score +1;
877963042 0:bfd3317d7773 309 }
877963042 0:bfd3317d7773 310 char buffer1[14];
877963042 0:bfd3317d7773 311 sprintf(buffer1,"%2d",_score);
877963042 0:bfd3317d7773 312 lcd.printString(buffer1,0,1);
877963042 0:bfd3317d7773 313
877963042 0:bfd3317d7773 314 }
877963042 0:bfd3317d7773 315
877963042 0:bfd3317d7773 316 // pause display
877963042 0:bfd3317d7773 317 void Bird::pause(N5110 &lcd, Gamepad &pad){
877963042 0:bfd3317d7773 318 if ( pad.check_event(Gamepad::BACK_PRESSED) ){
877963042 0:bfd3317d7773 319 while ( pad.check_event(Gamepad::BACK_PRESSED) == false ){
877963042 0:bfd3317d7773 320 lcd.clear();
877963042 0:bfd3317d7773 321 lcd.printString("PAUSE",25,3);
877963042 0:bfd3317d7773 322 lcd.refresh();
877963042 0:bfd3317d7773 323 }
877963042 0:bfd3317d7773 324 lcd.clear();
877963042 0:bfd3317d7773 325 lcd.printString("GO !",30,4);
877963042 0:bfd3317d7773 326 lcd.refresh();
877963042 0:bfd3317d7773 327 wait(1.0);
877963042 0:bfd3317d7773 328 }
877963042 0:bfd3317d7773 329 }
877963042 0:bfd3317d7773 330
877963042 0:bfd3317d7773 331 // first figure
877963042 0:bfd3317d7773 332 void Bird::stru(N5110 &lcd){
877963042 0:bfd3317d7773 333
877963042 0:bfd3317d7773 334 lcd.drawRect(0,0,WIDTH,HEIGHT-3,FILL_TRANSPARENT);
877963042 0:bfd3317d7773 335 lcd.drawRect(0,45,WIDTH,3,FILL_BLACK);
877963042 0:bfd3317d7773 336 for (int i=0; i<17; i++){
877963042 0:bfd3317d7773 337 lcd.setPixel(0,i,false);
877963042 0:bfd3317d7773 338 lcd.setPixel(13,i,true);
877963042 0:bfd3317d7773 339 }
877963042 0:bfd3317d7773 340 for (int i=0; i<14; i++){
877963042 0:bfd3317d7773 341 lcd.setPixel(i,0,false);
877963042 0:bfd3317d7773 342 lcd.setPixel(i,17,true);
877963042 0:bfd3317d7773 343 lcd.setPixel(13,0,true);
877963042 0:bfd3317d7773 344 }
877963042 0:bfd3317d7773 345 }
877963042 0:bfd3317d7773 346
877963042 0:bfd3317d7773 347 // Ready screen
877963042 0:bfd3317d7773 348 void Bird::ready(N5110 &lcd){
877963042 0:bfd3317d7773 349 char buffer[14];
877963042 0:bfd3317d7773 350 int number3 = 3;
877963042 0:bfd3317d7773 351 int number2 = 2;
877963042 0:bfd3317d7773 352 int number1 = 1;
877963042 0:bfd3317d7773 353 lcd.clear();
877963042 0:bfd3317d7773 354 stru(lcd);
877963042 0:bfd3317d7773 355 sprintf(buffer,"%1d",number3);
877963042 0:bfd3317d7773 356 lcd.printString(buffer,40,4);
877963042 0:bfd3317d7773 357 lcd.refresh();
877963042 0:bfd3317d7773 358 wait(1.0);
877963042 0:bfd3317d7773 359 lcd.clear();
877963042 0:bfd3317d7773 360 stru(lcd);
877963042 0:bfd3317d7773 361 sprintf(buffer,"%1d",number2);
877963042 0:bfd3317d7773 362 lcd.printString(buffer,40,4);
877963042 0:bfd3317d7773 363 lcd.refresh();
877963042 0:bfd3317d7773 364 wait(1.0);
877963042 0:bfd3317d7773 365 lcd.clear();
877963042 0:bfd3317d7773 366 stru(lcd);
877963042 0:bfd3317d7773 367 sprintf(buffer,"%1d",number1);
877963042 0:bfd3317d7773 368 lcd.printString(buffer,40,4);
877963042 0:bfd3317d7773 369 lcd.refresh();
877963042 0:bfd3317d7773 370 wait(1.0);
877963042 0:bfd3317d7773 371 lcd.clear();
877963042 0:bfd3317d7773 372 stru(lcd);
877963042 0:bfd3317d7773 373 lcd.printString("GO !",30,4);
877963042 0:bfd3317d7773 374 lcd.refresh();
877963042 0:bfd3317d7773 375 wait(0.5);
877963042 0:bfd3317d7773 376
877963042 0:bfd3317d7773 377
877963042 0:bfd3317d7773 378
877963042 0:bfd3317d7773 379 }
877963042 0:bfd3317d7773 380
877963042 0:bfd3317d7773 381 // Game play
877963042 0:bfd3317d7773 382 void Bird::barrier(N5110 &lcd){
877963042 0:bfd3317d7773 383 stru(lcd);
877963042 0:bfd3317d7773 384 check();
877963042 0:bfd3317d7773 385 // 1-th barrier
877963042 0:bfd3317d7773 386 lcd.drawRect(_x1,1,4,_y1,FILL_BLACK);
877963042 0:bfd3317d7773 387 lcd.drawRect(_x1-1,_y1+1,6,2,FILL_BLACK); // 20 pixel interval between upper
877963042 0:bfd3317d7773 388 lcd.drawRect(_x1-1,_y1+20,6,2,FILL_BLACK); // and lower side
877963042 0:bfd3317d7773 389 lcd.drawRect(_x1,_y1+22,4,22-_y1,FILL_BLACK);
877963042 0:bfd3317d7773 390 _x1 = _x1 - _vb;
877963042 0:bfd3317d7773 391 // 2-th barrier
877963042 0:bfd3317d7773 392 lcd.drawRect(_x2,1,4,_y2,FILL_BLACK);
877963042 0:bfd3317d7773 393 lcd.drawRect(_x2-1,_y2+1,6,2,FILL_BLACK); // 20 pixel interval between upper
877963042 0:bfd3317d7773 394 lcd.drawRect(_x2-1,_y2+20,6,2,FILL_BLACK); // and lower side
877963042 0:bfd3317d7773 395 lcd.drawRect(_x2,_y2+22,4,22-_y2,FILL_BLACK);
877963042 0:bfd3317d7773 396 _x2 = _x2 - _vb;
877963042 0:bfd3317d7773 397 // 3-th barrier
877963042 0:bfd3317d7773 398 lcd.drawRect(_x3,1,4,_y3,FILL_BLACK);
877963042 0:bfd3317d7773 399 lcd.drawRect(_x3-1,_y3+1,6,2,FILL_BLACK); // 20 pixel interval between upper
877963042 0:bfd3317d7773 400 lcd.drawRect(_x3-1,_y3+20,6,2,FILL_BLACK); // and lower side
877963042 0:bfd3317d7773 401 lcd.drawRect(_x3,_y3+22,4,22-_y3,FILL_BLACK);
877963042 0:bfd3317d7773 402 _x3 = _x3 - _vb;
877963042 0:bfd3317d7773 403 // 4-th barrier
877963042 0:bfd3317d7773 404 lcd.drawRect(_x4,1,4,_y4,FILL_BLACK);
877963042 0:bfd3317d7773 405 lcd.drawRect(_x4-1,_y4+1,6,2,FILL_BLACK); // 20 pixel interval between upper
877963042 0:bfd3317d7773 406 lcd.drawRect(_x4-1,_y4+20,6,2,FILL_BLACK); // and lower side
877963042 0:bfd3317d7773 407 lcd.drawRect(_x4,_y4+22,4,22-_y4,FILL_BLACK);
877963042 0:bfd3317d7773 408 _x4 = _x4 - _vb;
877963042 0:bfd3317d7773 409
877963042 0:bfd3317d7773 410
877963042 0:bfd3317d7773 411 }
877963042 0:bfd3317d7773 412
877963042 0:bfd3317d7773 413 // bird flyup
877963042 0:bfd3317d7773 414 void Bird::flyup(N5110 &lcd){
877963042 0:bfd3317d7773 415 int bird[3][6] = {
877963042 0:bfd3317d7773 416 { 0,1,1,0,0,0 },
877963042 0:bfd3317d7773 417 { 1,1,1,1,0,0 },
877963042 0:bfd3317d7773 418 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 419 };
877963042 0:bfd3317d7773 420 _birdy = _birdy - 2;
877963042 0:bfd3317d7773 421 _birdh = _birdy*3+9;
877963042 0:bfd3317d7773 422 lcd.drawSprite(15,_birdh,3,6,(int *)bird);
877963042 0:bfd3317d7773 423 }
877963042 0:bfd3317d7773 424
877963042 0:bfd3317d7773 425 // bird fly down
877963042 0:bfd3317d7773 426 void Bird::flydown(N5110 &lcd){
877963042 0:bfd3317d7773 427 int bird[3][6] = {
877963042 0:bfd3317d7773 428 { 1,1,1,1,1,1 },
877963042 0:bfd3317d7773 429 { 1,1,1,1,0,0 },
877963042 0:bfd3317d7773 430 { 0,1,1,0,0,0 },
877963042 0:bfd3317d7773 431 };
877963042 0:bfd3317d7773 432 _birdy = _birdy + 1;
877963042 0:bfd3317d7773 433 _birdh = _birdy*3+10;
877963042 0:bfd3317d7773 434 lcd.drawSprite(15,_birdh,3,6,(int *)bird);
877963042 0:bfd3317d7773 435 }
877963042 0:bfd3317d7773 436
877963042 0:bfd3317d7773 437 // check if x is smaller than 0
877963042 0:bfd3317d7773 438 void Bird::check(){
877963042 0:bfd3317d7773 439 if(_x1 < -2){
877963042 0:bfd3317d7773 440 _x1 = 85;
877963042 0:bfd3317d7773 441 _y1 = rand()%18+2;
877963042 0:bfd3317d7773 442 }
877963042 0:bfd3317d7773 443 if(_x2 < -2){
877963042 0:bfd3317d7773 444 _x2 = 85;
877963042 0:bfd3317d7773 445 _y2 = rand()%18+2;
877963042 0:bfd3317d7773 446 }
877963042 0:bfd3317d7773 447 if(_x3 < -2){
877963042 0:bfd3317d7773 448 _x3 = 85;
877963042 0:bfd3317d7773 449 _y3 = rand()%18+2;
877963042 0:bfd3317d7773 450 }
877963042 0:bfd3317d7773 451 if(_x4 < -2){
877963042 0:bfd3317d7773 452 _x4 = 85;
877963042 0:bfd3317d7773 453 _y4 = rand()%18+2;
877963042 0:bfd3317d7773 454 }
877963042 0:bfd3317d7773 455 }
877963042 0:bfd3317d7773 456
877963042 0:bfd3317d7773 457 // display failure screen if fail
877963042 0:bfd3317d7773 458 void Bird::fail(N5110 &lcd, Gamepad &pad){
877963042 0:bfd3317d7773 459 if (coll()){
877963042 0:bfd3317d7773 460 while ( pad.check_event(Gamepad::START_PRESSED ) == false ){
877963042 0:bfd3317d7773 461 lcd.clear();
877963042 0:bfd3317d7773 462 lcd.printString(" You've lost ! ",0,0);
877963042 0:bfd3317d7773 463 char buffer[14];
877963042 0:bfd3317d7773 464 sprintf(buffer,"You scored: %d", _score);
877963042 0:bfd3317d7773 465 lcd.printString(buffer, 0,1);
877963042 0:bfd3317d7773 466 lcd.printString(" BACK: Author",0,3);
877963042 0:bfd3317d7773 467 lcd.printString(" Press Start",0,4);
877963042 0:bfd3317d7773 468 lcd.printString("to play again",0,5);
877963042 0:bfd3317d7773 469 lcd.refresh();
877963042 0:bfd3317d7773 470 if ( pad.check_event(Gamepad::BACK_PRESSED )){
877963042 0:bfd3317d7773 471 while ( pad.check_event(Gamepad::BACK_PRESSED ) == false ){
877963042 0:bfd3317d7773 472 lcd.clear();
877963042 0:bfd3317d7773 473 lcd.printString(" Author: ",0,1);
877963042 0:bfd3317d7773 474 lcd.printString(" Yang Junyao",10,2);
877963042 0:bfd3317d7773 475 lcd.printString(" ID: 201090191",0,4);
877963042 0:bfd3317d7773 476 lcd.refresh();
877963042 0:bfd3317d7773 477 }
877963042 0:bfd3317d7773 478 }
877963042 0:bfd3317d7773 479 }
877963042 0:bfd3317d7773 480 lcd.init();
877963042 0:bfd3317d7773 481 init();
877963042 0:bfd3317d7773 482 pad.init();
877963042 0:bfd3317d7773 483 }
877963042 0:bfd3317d7773 484 }
877963042 0:bfd3317d7773 485
877963042 0:bfd3317d7773 486 // return 1 if collided
877963042 0:bfd3317d7773 487 bool Bird::coll(){
877963042 0:bfd3317d7773 488 if ( _x1 < 21 && _x1+4 > 14 ){
877963042 0:bfd3317d7773 489 if( _y1+2 >= _birdh || _y1+20 <= _birdh+2 ){
877963042 0:bfd3317d7773 490 return true;
877963042 0:bfd3317d7773 491 }
877963042 0:bfd3317d7773 492 else {return false; }
877963042 0:bfd3317d7773 493 }
877963042 0:bfd3317d7773 494 if ( _x2 < 21 && _x2+4 > 14 ){
877963042 0:bfd3317d7773 495 if( _y2+2 >= _birdh || _y2+20 <= _birdh+2 ){
877963042 0:bfd3317d7773 496 return true;
877963042 0:bfd3317d7773 497 }
877963042 0:bfd3317d7773 498 else {return false; }
877963042 0:bfd3317d7773 499 }
877963042 0:bfd3317d7773 500 if ( _x3 < 21 && _x3+4 > 14 ){
877963042 0:bfd3317d7773 501 if( _y3+2 >= _birdh || _y3+20 <= _birdh+2 ){
877963042 0:bfd3317d7773 502 return true;
877963042 0:bfd3317d7773 503 }
877963042 0:bfd3317d7773 504 else {return false; }
877963042 0:bfd3317d7773 505 }
877963042 0:bfd3317d7773 506 if ( _x4 < 21 && _x4+4 > 14 ){
877963042 0:bfd3317d7773 507 if( _y4+2 >= _birdh || _y4+20 <= _birdh+2 ){
877963042 0:bfd3317d7773 508 return true;
877963042 0:bfd3317d7773 509 }
877963042 0:bfd3317d7773 510 else {return false; }
877963042 0:bfd3317d7773 511 }
877963042 0:bfd3317d7773 512 if ( _birdh < 2 || _birdh > 42 ){
877963042 0:bfd3317d7773 513 return true;
877963042 0:bfd3317d7773 514 }
877963042 0:bfd3317d7773 515 else { return false; }
877963042 0:bfd3317d7773 516 }