updating stuff
Fork of Pokittris by
Diff: tetris.cpp
- Revision:
- 4:e861ad5ad42d
- Parent:
- 3:8540039d1eed
--- a/tetris.cpp Sun Oct 15 18:03:18 2017 +0000 +++ b/tetris.cpp Tue Oct 17 14:36:03 2017 +0000 @@ -20,6 +20,8 @@ bool splodeOK=0; byte animSplode=0; +int sX,sY,sX1,sY1; + /**************************************************************************/ #define HELD 0 @@ -96,12 +98,12 @@ game.display.load565Palette(curPal); } -void drawShape(byte x1, signed char y1, byte shape, byte frame) { +void drawShape(byte x1, signed char y1, byte shape, byte frame, bool bg=0) { for (char y = 0; y < 4; y++) { if (y1 + y > 1) { for (char x = 0; x < 4; x++) { byte mt = pgm_read_byte(shapeMap + (x + 4 * y) + shape * 64 + (frame * 16)); - if (mt > 1) { + if (mt > 1 || bg==1) { game.display.drawBitmap((x1 + x)*8, (y1 + y)*8, tile_gfx[(mt-1)+shape*6]); } } @@ -158,7 +160,18 @@ } void drawPlayfield() { - drawBackground(); + + if(frameNumber==1){ + drawBackground(); + } + + + for (char y = 2; y < 19; y++) { + for (char x = 8; x < 18; x++) { + byte mt = bg_map[x + 28 * y + (616*bgNum)]; + game.display.drawBitmap(x*8, y*8, bg_gfx[mt]); + } + } for (char y = 1; y < 19; y++) { for (char x = 3; x < 13; x++) { @@ -172,7 +185,7 @@ drawShape(px+5, py+1, ps, pr); } // next shape? - drawShape(19, 14, nextTile, 0); +// drawShape(19, 14, nextTile, 0); char text[] = " "; sprintf(text, "%05d", score); @@ -188,8 +201,6 @@ } - - void checkLine() { for(char t=0; t<19; t++){ @@ -233,13 +244,13 @@ // mess with the palette - + // remove because it's incompatible with the new draw routines. +/* int percent = 100; int diff = topLine; - unsigned short *p; palNum = 0;//level & 31; - p=pallet+(palNum*4); + unsigned short *p=pallet+(palNum*4); unsigned short curPal[4]; curPal[0] = pallet[(palNum*4)]; @@ -267,6 +278,7 @@ } game.display.load565Palette(curPal); +*/ } @@ -314,15 +326,10 @@ } } -int y=48; - if(frameNumber<=64){ + float y=48; + if(frameNumber<=32){ // time, start, distance, duration - #ifdef POK_SIM - y = easeOutBounce(frameNumber, -48, 48+48, 64); - #else - y = easeOutBounce(frameNumber*4, -48, 48+48, 64); - if (y>48) y=48; - #endif + y = easeOutElastic(frameNumber, -48, 48+48, 32); } drawMyBitmap(16, y, title_bitmap, title_mask); @@ -341,6 +348,7 @@ } loadPal(0); // default green palette + frameNumber=0; gameMode = 1; } @@ -355,10 +363,10 @@ } } - int y=48; - if(frameNumber<=64){ + float y=48; + if(frameNumber<=32){ // time, start, distance, duration - y = easeOutBounce(frameNumber, -48, 48+48, 64); + y = easeOutElastic(frameNumber, -48, 48+48, 32); } drawMyBitmap(1, y, gameover_bitmap, gameover_mask); @@ -424,7 +432,8 @@ stamp(px, py, ps, pr); checkLine(); py = 0; px = 6; ps = nextTile; nextTile = random(6); pr = 0; - } + drawShape(19, 14, nextTile, 0,1); + } } if (_Up[NEW] && splodeOK==1) { splodeOK=0; @@ -462,9 +471,15 @@ } animCount=0; + sX=(px + 4)*8; + sY=py*8; + sX1=((px+4)*8)+48; + sY1=(py*8)+48; + if(sY1>176)sY1=176; } if(linesToRemove!=0){ + sX=0; sY=0; sX1=220; sY1=176; // remove some lines for(byte t=0; t<19; t++){ if(removeLine[t]==1){ @@ -489,6 +504,10 @@ if(animSplode!=0){ if(animSplode<6){ + sX=0; + sY=0; + sX1=220; + sY1=176; for (char y = 0; y < 4; y++) { if (py + y >= 0) { for (char x = 0; x < 4; x++) { @@ -515,6 +534,10 @@ py = 0; px = 6; ps = nextTile; nextTile = random(6); pr = 0; animSplode=0; + sX=0; + sY=0; + sX1=220; + sY1=176; } } @@ -523,8 +546,6 @@ } - - int main(){ game.begin(); @@ -546,6 +567,9 @@ splodeOK=0; animSplode=0; + sX=0; sY=0; + sX1=220; sY1=176; + while (game.isRunning()) { // if it is time to update the screen @@ -570,14 +594,13 @@ gameOver(); break; } - - if(gameMode==1){ - // render only the playing area - //game.display.updateRegion(64,16,144,160); - game.display.updateRegion((px + 4)*8, py*8,((px+4)*8)+48,(py*8)+48); - }else{ - game.display.updateRegion(0,0,220,176); + if(frameNumber==1){ + sX=0; sY=0; + sX1=220; sY1=176; } + + game.display.updateRegion(sX,sY,sX1,sY1); + game.display.updateRegion(152,112,184,144); // next tile // } } return 0;