From 438dfeea08b735c85af5f1f20b96d9213a7f34e5 Mon Sep 17 00:00:00 2001 From: iridiumR Date: Thu, 9 Jun 2022 12:52:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(MCU=E8=AF=BE=E8=AE=BE):=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=96=B9=E5=9D=97=E6=97=8B=E8=BD=AC=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MCU/MCU_REAL_FINAL/IMG/方块.psd | Bin 21050 -> 22758 bytes MCU/MCU_REAL_FINAL/IMG/箭头.bmp | Bin 0 -> 248 bytes MCU/MCU_REAL_FINAL/block.c | 139 +++++++++++++++++++++++++------- MCU/MCU_REAL_FINAL/block.h | 1 + MCU/MCU_REAL_FINAL/img.h | 4 + MCU/MCU_REAL_FINAL/main.c | 2 +- MCU/MCU_REAL_FINAL/menu.c | 43 +++++++--- 7 files changed, 150 insertions(+), 39 deletions(-) create mode 100644 MCU/MCU_REAL_FINAL/IMG/箭头.bmp diff --git a/MCU/MCU_REAL_FINAL/IMG/方块.psd b/MCU/MCU_REAL_FINAL/IMG/方块.psd index 742434fe3318d022e76239427f983d7f157cd549..5c18c42a82867f42fea92aa3e75c51f644c9994e 100644 GIT binary patch delta 1629 zcmb_bO=uHQ5PolW6Kkwks%SxlSX1mJBb>1HU!*K zya*z~>d8~pgO`GJPnM!o@TNyW#G6n&2~{tGHolonC9M@w>)W08=9_sl^XA*POONR4 zBE92`4POsQ193qhF!mhd2w^WlTL;=&KCO*?^{lkbKd59DUMX*v(B}eQ$g?>3jdO%Y ze7=YnjEG^QpYN`RxA}@o@ymg*sGN3tMJ4DC`21aNIUuIoX>Y)v3s*xtg_c60DtE7$tINOEk%FVeUf$H{IcFr4^fhE9U73Wcxu!e+w394)PLas{oF(g3Kk=gbEn?27gvd&(!>gC$x!t zJywg8=^EaT`I0K+hnhG-($#@@aXbe_`k7corivxYP5f+SoFWG-ESDRwmc6Q6 zP8CM7xs;NhO7y;ad}Sp!y@m%#&lDyh*6^Jf-dX?;v0PU6$+nPo>VY+)8J)h?K|3je|EZ(=Y0A7-x|-pcGjqcYrM zl!qk{ow7T+>G@vW{2;3^!FK@SV8uTeOrQWnI|57Jn9+@a5QU0mg1rpuyHBx`4Dbyv i$R)g}pr1AGonNK8b--J4E4 delta 257 zcmaF1k#W}&#t8~q{z(>2p1v%q3?Lu?CXooRoC-+5tYTx_7pBQP%wm%>m<_=6I_CVz z_gK{?&tqZR?8!2jY4c=`U;3N-EFzdU|FM>3oE&azq-+n=%7$bh2apZItm#@A>@#LC z=rR~iE(jE#e9x9=^GVw>epN=Wl{_FVOg2D*5yXIEkVc>rnG`ms_zE!zoc+(RegDk= z4Dr7Xd7l^Z^xxd!&%?-Ns$gVjWn^Y$Y`l4101G1<;|HKFhRqgX?-?gEhdMy9JpdAu BI(q;B diff --git a/MCU/MCU_REAL_FINAL/IMG/箭头.bmp b/MCU/MCU_REAL_FINAL/IMG/箭头.bmp new file mode 100644 index 0000000000000000000000000000000000000000..fbac6e990fbde2bc390bd6298d56d1700d0520de GIT binary patch literal 248 zcmZ?r{lNeMWp?JB07(4D1|X7XG7!aRTHst{EpS1g32<>_ VLAW@YAhI}IBg7dHE*c3|4*)1&bpZeX literal 0 HcmV?d00001 diff --git a/MCU/MCU_REAL_FINAL/block.c b/MCU/MCU_REAL_FINAL/block.c index 334dfd3..432ddcd 100644 --- a/MCU/MCU_REAL_FINAL/block.c +++ b/MCU/MCU_REAL_FINAL/block.c @@ -7,7 +7,8 @@ #include extern unsigned int bestScore[]; -char base[MAX_X][MAX_Y] = {0}; //x*y //0Ϊ 1Ϊ 2Ϊ +char base[MAX_X][MAX_Y] = {0}; //x*y //0Ϊ 1Ϊ 2Ϊ 3Ϊתĵ +char mask[MAX_X][MAX_Y] = {0}; //ת extern unsigned int score; extern enum OPR opr; enum GS blockGameStatus = __idle; @@ -15,7 +16,7 @@ enum GS blockGameStatus = __idle; void blockInit() { score = 0; - srand((unsigned)TL0); + srand((unsigned)TL0); blockGameStatus = start; } @@ -65,7 +66,7 @@ void genPiece() //δɵķ for(i = 0; i < MAX_X; i++) for(j = 0; j < MAX_Y; j++) - if(base[i][j] == 2) + if(base[i][j] >= 2) return; // @@ -77,12 +78,12 @@ void genPiece() // if(random >= 7 && random <= 15) { - base[4][9] = 2; // + base[4][9] = 3; // base[4][10] = 2; // } else if(random >= 16 && random <= 22) { - base[3][9] = 2; //// + base[3][9] = 3; //// base[4][9] = 2; } @@ -91,37 +92,37 @@ void genPiece() { base[4][11] = 2; - base[4][10] = 2; + base[4][10] = 3; base[4][9] = 2; } else if(random >= 32 && random <= 38) { base[3][9] = 2; - base[4][9] = 2; + base[4][9] = 3; base[5][9] = 2; } else if(random >= 39 && random <= 47) { base[3][10] = 2; - base[3][9] = 2; + base[3][9] = 3; base[4][9] = 2; } else if (random >= 48 && random <= 55) { base[4][10] = 2; base[3][9] = 2; - base[4][9] = 2; + base[4][9] = 3; } - else if (random >= 56 && random <= 63) + else if (random >= 56 && random <= 63) { base[4][9] = 2; base[3][10] = 2; - base[4][10] = 2; + base[4][10] = 3; } - else if (random >= 64 && random <= 69) + else if (random >= 64 && random <= 69) { base[3][9] = 2; - base[3][10] = 2; + base[3][10] = 3; base[4][10] = 2; } @@ -133,31 +134,31 @@ void genPiece() base[3][9] = 2; base[4][9] = 2; } - else if(random >= 80 && random <= 84) + else if(random >= 80 && random <= 84) { base[3][10] = 2; - base[4][10] = 2; + base[4][10] = 3; base[3][9] = 2; base[4][11] = 2; } - else if(random >= 85 && random <= 89) + else if(random >= 85 && random <= 89) { base[3][10] = 2; - base[4][10] = 2; + base[4][10] = 3; base[3][11] = 2; base[4][9] = 2; } - else if(random >= 90 && random <= 94) + else if(random >= 90 && random <= 94) { base[3][10] = 2; - base[4][10] = 2; + base[4][10] = 3; base[4][9] = 2; base[5][9] = 2; } - else if(random >= 95 && random <= 99) + else if(random >= 95 && random <= 99) { base[3][10] = 2; - base[4][10] = 2; + base[4][10] = 3; base[3][9] = 2; base[4][9] = 2; } @@ -196,7 +197,7 @@ void dropPiece() { if(flag == 1) break; - if(base[i][j] == 2) + if(base[i][j] >= 2) { //, if(flag == 0 && (base[i][j - 1] == 1 || j == 0)) @@ -215,12 +216,12 @@ void dropPiece() { for(j = 0; j < MAX_Y; j++) { - if(base[i][j] == 2) + if(base[i][j] >= 2) { //ޱ if(flag == 0 && isIegal(i, j - 1)) { - base[i][j - 1] = 2; + base[i][j - 1] = base[i][j]; base[i][j] = 0; } //бת @@ -250,14 +251,13 @@ void moveLeftPiece() } for(i = 0; i < MAX_X; i++) for(j = 0; j < MAX_Y; j++) - if(base[i][j] == 2) + if(base[i][j] >= 2) { - base[i - 1][j] = 2; + base[i - 1][j] = base[i][j]; base[i][j] = 0; } } void moveRightPiece() - { char i, j; if(blockGameStatus == over) @@ -270,9 +270,9 @@ void moveRightPiece() } for(i = MAX_X - 1; i >= 0; i--) for(j = MAX_Y - 1; j >= 0; j--) - if(base[i][j] == 2 ) + if(base[i][j] >= 2 ) { - base[i + 1][j] = 2; + base[i + 1][j] = base[i][j]; base[i][j] = 0; } } @@ -337,6 +337,7 @@ void blockGameOver() } } +//ж߷ unsigned int addBest(unsigned int s) { int i, j; @@ -351,3 +352,83 @@ unsigned int addBest(unsigned int s) } return 0; } + +unsigned int rotateBlock(enum OPR opr) +{ + char i, j, cy, cx, flag = 0; + //Ѱתĵ + for(i = 0; i < MAX_X; i++) + for(j = 0; j < MAX_Y; j++) + { + if(base[i][j] == 3) + { + flag = 1; + cx = i; + cy = j; + break; + } + } + + if(!flag) + return 0; //ûҵֱӷ + if(opr == right) + { + //жǷϷ Ϸת + for(i = - 1; i <= 1; i++) + for(j = - 1; j <= 1; j++) + if(base[cx + i][cy + j] == 2) + if(isIegal(j + cx, -i + cy)) + { + //ɻ + mask[j + cx][-i + cy] = base[cx + i][cy + j]; + } + else + { + memset(mask, 0, sizeof(mask)); + return 0; + } + //в + for(i = 0; i < MAX_X; i++) + for(j = 0; j < MAX_Y; j++) + if(base[i][j] == 2) + base[i][j] = 0; + + //㸲 + for(i = -1; i <= 1; i++) + for(j = -1; j <= 1; j++) + if(mask[cx + i][cy + j] == 2) + base[cx + i][cy + j] = mask[cx + i][cy + j]; + } + + if(opr == left) + { + //жǷϷ Ϸת + for(i = - 1; i <= 1; i++) + for(j = - 1; j <= 1; j++) + if(base[cx + i][cy + j] == 2) + if(isIegal(-j + cx, i + cy)) + { + //ɻ + mask[-j + cx][i + cy] = base[cx + i][cy + j]; + } + else + { + memset(mask, 0, sizeof(mask)); + return 0; + } + //в + for(i = 0; i < MAX_X; i++) + for(j = 0; j < MAX_Y; j++) + if(base[i][j] == 2) + base[i][j] = 0; + + //㸲 + for(i = -1; i <= 1; i++) + for(j = -1; j <= 1; j++) + if(mask[cx + i][cy + j] == 2) + base[cx + i][cy + j] = mask[cx + i][cy + j]; + } + memset(mask, 0, sizeof(mask)); + return 1; +} + diff --git a/MCU/MCU_REAL_FINAL/block.h b/MCU/MCU_REAL_FINAL/block.h index 7b3da10..dbef21c 100644 --- a/MCU/MCU_REAL_FINAL/block.h +++ b/MCU/MCU_REAL_FINAL/block.h @@ -23,4 +23,5 @@ void blockGameOver(); void saveBest(); void readBest(); unsigned int addBest(unsigned int s); +unsigned int rotateBlock(enum OPR opr); #endif \ No newline at end of file diff --git a/MCU/MCU_REAL_FINAL/img.h b/MCU/MCU_REAL_FINAL/img.h index c760358..3dfb29c 100644 --- a/MCU/MCU_REAL_FINAL/img.h +++ b/MCU/MCU_REAL_FINAL/img.h @@ -92,6 +92,10 @@ code unsigned char SUPER_NUM1[]={ code unsigned char IMG_BLOCK[]={ 0x81,0x7E,0x7E,0x7E,0x7A,0x72,0x7E,0x81, }; +//תͷ +code unsigned char IMG_ROTATE[]={ +0x7F,0x1F,0x07,0x0B,0x13,0x21,0x41,0x80, +}; //÷ code unsigned char FONT_SCORE0[]={ 0x00,0x10,0x88,0xC4,0x33,0x00,0xBE,0xAA,0xAA,0xAA,0xAA,0xAA,0xBE,0x80,0x00,0x00, diff --git a/MCU/MCU_REAL_FINAL/main.c b/MCU/MCU_REAL_FINAL/main.c index 9b5302f..2fd9069 100644 --- a/MCU/MCU_REAL_FINAL/main.c +++ b/MCU/MCU_REAL_FINAL/main.c @@ -40,7 +40,7 @@ void time() interrupt 1 // if(PIN_4 == 0) { - delayms(15); + delayms(9); if(PIN_4 == 0) { opr = confirm; diff --git a/MCU/MCU_REAL_FINAL/menu.c b/MCU/MCU_REAL_FINAL/menu.c index 2a42860..c1744f7 100644 --- a/MCU/MCU_REAL_FINAL/menu.c +++ b/MCU/MCU_REAL_FINAL/menu.c @@ -27,7 +27,7 @@ Menu* LAST = NULL; // code unsigned int ver _at_ 0x7ffe; enum OPR opr = idle; -static unsigned int local[5] = {0}; +static unsigned int local[5] = {0}; //˵ʹ0,1๫ unsigned int score; unsigned int bestScore[10]; unsigned int mBestScore[10]; @@ -106,30 +106,47 @@ void m_block(struct _menu* this) if(LAST != &M_BLOCK) { LAST = &M_BLOCK; - drawVerticalDottedLine(64); - drawBLOCKSCORE(); blockInit(); + local[2] = 0; //Ŀǰ״̬ 0ƽ 1ת } // if(opr == confirm) { opr = idle; - clear(); - blockDestroy(); - NOW = &M_MAINMENU; + if(blockGameStatus == over) + { + clear(); + local[2] = 0; + blockDestroy(); + NOW = &M_MAINMENU; + return; + } + local[2] = ~local[2]; return; } if(opr == left) { + if(local[2]) + { + rotateBlock(opr); + local[2] = 0; + } + else + moveLeftPiece(); opr = idle; - moveLeftPiece(); drawBlock(); return; } if(opr == right) { + if(local[2]) + { + rotateBlock(opr); + local[2] = 0; + } + else + moveRightPiece(); opr = idle; - moveRightPiece(); drawBlock(); return; } @@ -147,17 +164,25 @@ void m_block(struct _menu* this) drawVOID8(70, 4, 40); drawVOID8(70, 6, 32); } + drawVerticalDottedLine(64); + drawBLOCKSCORE(); drawSUPNUM(70, 2, score / 10000); //Ʒ drawSUPNUM(79, 2, (score % 10000) / 1000); drawSUPNUM(88, 2, (score % 1000) / 100); drawSUPNUM(97, 2, (score % 100) / 10); drawSUPNUM(106, 2, score % 10); +// if(local[2]) +// placeIMG_ROTATE(115, 6); +// else +// placeRIMG_BLOCK(115, 6); + + blockGameOver(); //ǷϷ genPiece(); //Ҫ¿ dropPiece(); //Ҫ judgeBlock(); //Ҫһ drawBlock(); //ƽ - delayms(400); + delayms(1500); }