Tetris for the RA8875, derived from another users implementation.
Fork of Tetris by
Tetris, adapted to the RA8875 graphics library and display.
As currently implemented, this version is defined for the 800x480 display. A number of macros can adapt it for other screen resolutions.
Further, while presently configured for landscape mode, it should be fairly easy to reconfigure it for portrait mode.
Diff: main.cpp
- Revision:
- 5:5ce8976cd303
- Parent:
- 4:107d1d5a642e
- Child:
- 6:d2aa47c92687
--- a/main.cpp Sat Mar 18 14:45:16 2017 +0000 +++ b/main.cpp Sat Mar 18 22:30:32 2017 +0000 @@ -10,49 +10,72 @@ #include "Field.h" #include "Define.h" +Serial pc(USBTX, USBRX); // Not required for display + int main() { int score = 0; int period = SPEED; bool flag; clock_t start_s; + pc.baud(460800); //I like a snappy terminal, so crank it up! + pc.printf("\r\nTetris - Build " __DATE__ " " __TIME__ "\r\n"); + int playState = 0; // 0=init, 1=newBlock, 2=game over TFTInit(); - drawFrame(); - drawMap(); + while (1) { - Block NewBlock; - flag = false; - drawMap(); - drawScore(score); - drawNextBlock(NewBlock); - while( !flag ) { - drawMap(); - drawBlock(NewBlock); - start_s = clock(); - while( start_s + period > clock() ) { - if ( TouchStatus() ) { - clrBlock(NewBlock); - NewBlock = doGest(NewBlock); + switch (playState) { + case 0: { // init + score = 0; + period = SPEED; + ReInitGame(); + drawFrame(); + drawMap(); + playState++; + // break; // fall thru + } + case 1: { + Block NewBlock; + flag = false; + drawScore(score); + drawNextBlock(NewBlock); + while( !flag ) { + drawMap(); drawBlock(NewBlock); - wait_ms(50); + start_s = clock(); + while( start_s + period > clock() ) { + if ( TouchStatus() ) { + clrBlock(NewBlock); + NewBlock = doGest(NewBlock); + drawBlock(NewBlock); + wait_ms(80); + } + } + if ( NewBlock.CheckBottom() ) { + saveToField(NewBlock); + flag = true; + } else { + clrBlock(NewBlock); + NewBlock.y += 1; + drawBlock(NewBlock); + } + } + score += checkLine(); + if ( score < 3200 ) + period = SPEED - score / 50; + clrNextBlock(NewBlock); + if ( checkGameOver() ) { + playState++; + gameOver(score); + } + break; + } + case 2: { + if (ReplayTouched()) { + playState = 0; // restart + break; } } - if ( NewBlock.CheckBottom() ) { - saveToField(NewBlock); - flag = true; - } else { - clrBlock(NewBlock); - NewBlock.y += 1; - drawBlock(NewBlock); - } } - score += checkLine(); - if ( score < 3200 ) - period = SPEED - score / 50; - clrNextBlock(NewBlock); - if ( checkGameOver() ) - break; } - gameOver(score); - } \ No newline at end of file