■Stairs_of_infinty■
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | #include<time.h> #include<stdlib.h> #include "2450addr.h" #include "my_lib.h" #include "macro.h" void MMU_Init(void); #include "./Images/BLOCK.H" #include "./Images/CLOUD.H" #include "./Images/TITLE1.H" #include "./Images/TITLE2.H" #include "./Images/ICON.H" #include "./Images/ENDGAME.H" #include "./Images/RPENGUIN.H" #include "./Images/LPENGUIN.H" #include "./Images/RHEDGE.H" #include "./Images/LHEDGE.H" #include "./Images/RDINO.H" #include "./Images/LDINO.H" // Color Define #define BLACK 0x0000 #define WHITE 0xfffe #define BLUE 0x003e #define GREEN 0x07c0 #define RED 0xf800 #define YELLOW 0xffc0 // ISR Functions declaration #define LCD_XSIZE (480) #define LCD_YSIZE (272) // Functions Declaration void HW_Initial(void); void Show_Welcome(char * msg); // Global Variables Declaration volatile int Touch_pressed = 0; volatile int ADC_x=0, ADC_y=0; volatile int Cal_x1=848; volatile int Cal_y1=656; volatile int Cal_x2=186; volatile int Cal_y2=349; volatile int Touch_x, Touch_y; volatile unsigned int Touch_config=1; /**************************************************************************************************/ typedef struct _Block{ int x; int y; }Block; void Lcd_Make_Bmp_Buffer (int x, int y, const unsigned char *fp); void Make_Buffer(int x,int y,int color); void Creat_Block(void); void Print_Block(void); void touch_block(void); void CountPrintf(void); void ScorePrintf(void); unsigned int bmp_buffer[272][480]; static unsigned int Fbuf[2] = {0x33800000, 0x33c00000}; unsigned short bfType; unsigned int bfSize; unsigned int bfOffbits; unsigned int biWidth, biWidth2; unsigned int biHeight; /**************************************************************************************************/ void Touch_ISR(void) __attribute__ ((interrupt ("IRQ"))); void Touch_ISR() { rINTSUBMSK |= (0x1<<9); rINTMSK1 |= (0x1<<31); /* TO DO: Pendng Clear on Touch */ rSUBSRCPND |= (0x1<<9); rSRCPND1 |= (0x1<<31); rINTPND1 |= (0x1<<31); // Touch UP if(rADCTSC&0x100) { rADCTSC&=0xff; Touch_pressed = 0; } // Touch Down else { rADCTSC=(0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(1<<3)|(1<<2)|(0); // SADC_ylus Down,Don't care,Don't care,Don't care,Don't care,XP pullup Dis,Auto,No operation rADCCON|=0x1; while(rADCCON & 0x1); while(!(0x8000&rADCCON)); ADC_x=(int)(0x3ff&rADCDAT0); ADC_y=(int)(0x3ff&rADCDAT1); // Touch calibration complete if(Touch_config) { Touch_y=(ADC_y-Cal_y1)*(LCD_YSIZE-10)/(Cal_y2-Cal_y1)+5; Touch_x=(ADC_x-Cal_x2)*(LCD_XSIZE-10)/(Cal_x1-Cal_x2)+5; Touch_x=LCD_XSIZE-Touch_x; if(Touch_x<0) Touch_x=0; if(Touch_x>=LCD_XSIZE) Touch_x=LCD_XSIZE-1; if(Touch_y<0) Touch_y=0; if(Touch_y>=LCD_YSIZE) Touch_y=LCD_YSIZE-1; } // before calibration else { Touch_x = ADC_x; Touch_y = ADC_y; } rADCTSC=(1<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3); // SADC_ylus Up,Don't care,Don't care,Don't care,Don't care,XP pullup En,Normal,Waiting mode Touch_pressed = 1; } rINTSUBMSK &= ~(0x1<<9); rINTMSK1 &= ~(0x1<<31); } // Lower Layer Functions void HW_Initial(void) { Exception_Init(); Uart_Init(115200); // Led_Init(); Buzzer_Init(); Timer0_Init(); Graphic_Init(); Touch_Isr_Init(Touch_ISR); MMU_Init(); } /***********************************************************************************************/ void Show_Welcome(char * msg) { Uart_Printf("\n%s\n", msg); Lcd_Draw_BMP(0,0, title1); //Flushing Timer0_Delay(3000); Lcd_Draw_BMP(0,0, title2); Timer0_Delay(3000); } /********** Background Save **************************************************************************/ void Make_Buffer(int x,int y,int color) { bmp_buffer[y][x] = (unsigned short int)color; } void Lcd_Make_Bmp_Buffer (int x, int y, const unsigned char *fp) { int xx=0, yy=0; unsigned int tmp; unsigned char tmpR, tmpG, tmpB; bfType=*(unsigned short *)(fp+0); bfSize=*(unsigned short *)(fp+2); tmp=*(unsigned short *)(fp+4); bfSize=(tmp<<16)+bfSize; bfOffbits=*(unsigned short *)(fp+10); biWidth=*(unsigned short *)(fp+18); biHeight=*(unsigned short *)(fp+22); biWidth2=(bfSize-bfOffbits)/biHeight; for(yy=0;yy<biHeight;yy++) { for(xx=0;xx<biWidth;xx++) { tmpB=*(unsigned char *)(fp+bfOffbits+(biHeight-yy-1)*biWidth*3+xx*3+0); tmpG=*(unsigned char *)(fp+bfOffbits+(biHeight-yy-1)*biWidth*3+xx*3+1); tmpR=*(unsigned char *)(fp+bfOffbits+(biHeight-yy-1)*biWidth*3+xx*3+2); tmpR>>=3; tmpG>>=3; tmpB>>=3; if(xx<biWidth2) Make_Buffer(x+xx,y+yy,(tmpR<<10)+(tmpG<<5)+(tmpB<<0)); } } } /*************************************************************************************************/ void Lcd_Display_Frame_Buffer(unsigned int id) { Lcd_Set_Address(Fbuf[id]); } void Lcd_Set_Address(unsigned int fp) { rVIDW00ADD0B0 = fp; rVIDW00ADD1B0 = 0; rVIDW00ADD2B0 = (0<<13)|((LCD_XSIZE*4*2)&0x1fff); rVIDW00ADD1B0 = 0+(LCD_XSIZE*LCD_YSIZE); } /*************************************************************************************************/ int random; int icon_flag=0; int game_enable =1; int Survival_count=20;//Survival time int character_pose = 0;//0 : Right, 1 : Left int size = 15; //init block count Block block_ary[15]; int blockS_x = 390, blockS_y = 120; //start point int block_cnt = 0; void Creat_Block(void) //height : 28 , width : 48 ; block { int i; int position_x,position_y; block_ary[0].x=blockS_x; block_ary[0].y=blockS_y; position_x = blockS_x; position_y = blockS_y; for(i=1;i<size;i++) { random =rand()%5; if(random>2) { block_ary[i].x = position_x-28; block_ary[i].y = position_y-48; position_x = block_ary[i].x; position_y = block_ary[i].y; } else { block_ary[i].x = position_x-28; block_ary[i].y = position_y+48; position_x = block_ary[i].x; position_y = block_ary[i].y; } } } void Print_Block(void) { int i; Lcd_Select_Frame_Buffer(0); for(i=0;i<size;i++) Lcd_Draw_BMP(block_ary[i].x,block_ary[i].y, block); Lcd_Draw_BMP(432,0, icon); if(icon_flag==0){ if(character_pose== 0) Lcd_Draw_BMP(362,130, Rpenguin); else Lcd_Draw_BMP(362,130, Lpenguin); } if(icon_flag==1){ if(character_pose== 0) Lcd_Draw_BMP(362,130, Rhedge); else Lcd_Draw_BMP(362,130, Lhedge); } if(icon_flag==2){ if(character_pose== 0) Lcd_Draw_BMP(362,130, Rdino); else Lcd_Draw_BMP(362,130, Ldino); } } void touch_block(void) { int i; int x,y; if(!game_enable && Touch_pressed) //game end { block_cnt = 0; Survival_count=20; for(i=0;i<size;i++) for(x=block_ary[i].x;x<block_ary[i].x+28;x++) for(y=block_ary[i].y ;y<block_ary[i].y+48 ;y++) Lcd_Put_Pixel(x,y,bmp_buffer[y][x]); Creat_Block(); /*clear end bar, score bar*******************/ for(x=150;x<150 +32;x++) for(y=0 ;y<272;y++) Lcd_Put_Pixel(x,y,bmp_buffer[y][x]); for(x=450;x<450 +32;x++) for(y=0 ;y<272 + 10;y++) Lcd_Put_Pixel(x,y,bmp_buffer[y][x]); /*************************************/ game_enable =1; //game restart } else if(game_enable&&Touch_pressed) //game start { Uart_Printf("\nX:%d, Y:%d", Touch_x, Touch_y); Jumpsound(); //buzzer /*difficulty control*************************/ if(block_cnt <10) Survival_count=20; else Survival_count=14; //2sec.. /*************************************/ if(Touch_x>200 &&Touch_x<450&& Touch_y>140){ block_cnt++; /*clear block image from background*******************/ for(i=0;i<size;i++) for(x=block_ary[i].x;x<block_ary[i].x+28;x++) for(y=block_ary[i].y ;y<block_ary[i].y+48 ;y++) Lcd_Put_Pixel(x,y,bmp_buffer[y][x]); /************************************************/ Uart_Printf("<<<<<<<<Left Click ... <<<<<<<<<<<<\n"); for(i=0;i<size;i++) { block_ary[i].x+=28; block_ary[i].y-=48; } /*first block delete and create end block*******************/ for(i=0;i<size-1;i++) { block_ary[i].x = block_ary[i+1].x; block_ary[i].y = block_ary[i+1].y; } random =rand()%5; if(random>2) { block_ary[size-1].x = block_ary[size-2].x - 28; block_ary[size-1].y = block_ary[size-2].y - 48; } else { block_ary[size-1].x = block_ary[size-2].x - 28; block_ary[size-1].y = block_ary[size-2].y + 48; } /*get off the block ***********************************/ if(blockS_x != block_ary[0].x || blockS_y != block_ary[0].y){ Lcd_Draw_BMP(150,0, endgame); game_enable=0; } /************************************************/ character_pose = 1; } else if(Touch_x>200 &&Touch_x<450&& Touch_y<140){ block_cnt++; for(i=0;i<size;i++) for(x=block_ary[i].x;x<block_ary[i].x+28;x++) for(y=block_ary[i].y ;y<block_ary[i].y+48 ;y++) Lcd_Put_Pixel(x,y,bmp_buffer[y][x]); Uart_Printf(">>>>>>>>>Right Click ... >>>>>>>>>>>>>\n"); for(i=0;i<size;i++) { block_ary[i].x+=28; block_ary[i].y+=48; } /*first block delete and create end block*******************/ for(i=0;i<size-1;i++) { block_ary[i].x = block_ary[i+1].x; block_ary[i].y = block_ary[i+1].y; } random =rand()%5; if(random<3) { block_ary[size-1].x = block_ary[size-2].x - 28; block_ary[size-1].y = block_ary[size-2].y - 48; } else { block_ary[size-1].x = block_ary[size-2].x - 28; block_ary[size-1].y = block_ary[size-2].y + 48; } /*get off the block ***********************************/ if(blockS_x != block_ary[0].x || blockS_y != block_ary[0].y){ Lcd_Draw_BMP(150,0, endgame); game_enable=0; } /************************************************/ character_pose= 0; } /*character change icon ***********************************/ else if(Touch_x>430 &&Touch_x<480&& Touch_y<100) { icon_flag++; icon_flag = (icon_flag ==3) ? (icon_flag%3) : icon_flag; } } } void ScorePrintf() { Lcd_Printf(170,450, RED, BLACK, 1,1,"Score : %d", block_cnt); } void CountPrintf() { Survival_count--; if(Survival_count<0)// 3sec.. { Survival_count++; Lcd_Draw_BMP(150,0, endgame); game_enable = 0 ;//gram end } Lcd_Printf(200,430, RED, BLACK, 1,1,"Survival time : %d",Survival_count/7); } void Main(void) { Uart_Init(115200); HW_Initial(); Show_Welcome("Stairs of infinity"); Creat_Block(); Lcd_Select_Frame_Buffer(1); Lcd_Draw_BMP(0,0, cloud); Lcd_Copy(1,0); Lcd_Display_Frame_Buffer(0); srand(time(NULL)); Lcd_Make_Bmp_Buffer(0,0,cloud); while(1){ CountPrintf(); Touch_ISR_Enable(1); touch_block(); if(game_enable) Print_Block(); ScorePrintf(); } } | cs |
'ARM Device' 카테고리의 다른 글
[ARM 디바이스 제어_Day5]Touch Screen (0) | 2018.11.18 |
---|---|
[ARM 디바이스 제어_Day4]DMA+Timer,DMA+Uart (0) | 2018.11.18 |
[ARM 디바이스 제어_Day3]DMA (0) | 2018.11.18 |
[ARM 디바이스 제어_Day2]key, Uart interrupt (0) | 2018.11.18 |
[ARM 디바이스 제어_Day1]Timer (0) | 2018.11.18 |