![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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.
main.cpp@2:6b6986c3d2bd, 2017-03-03 (annotated)
- Committer:
- sergun2311
- Date:
- Fri Mar 03 13:19:26 2017 +0000
- Revision:
- 2:6b6986c3d2bd
- Parent:
- 1:b4aa36ae11ac
- Child:
- 4:107d1d5a642e
TETRIS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sergun2311 | 0:645509d95b8d | 1 | #include "mbed.h" |
sergun2311 | 0:645509d95b8d | 2 | #include <ctime> |
sergun2311 | 0:645509d95b8d | 3 | #include "playGround.h" |
sergun2311 | 0:645509d95b8d | 4 | #include "Block.h" |
sergun2311 | 1:b4aa36ae11ac | 5 | #include "Field.h" |
sergun2311 | 0:645509d95b8d | 6 | |
sergun2311 | 1:b4aa36ae11ac | 7 | #define SPEED 100 |
sergun2311 | 0:645509d95b8d | 8 | |
sergun2311 | 0:645509d95b8d | 9 | int main() |
sergun2311 | 0:645509d95b8d | 10 | { |
sergun2311 | 1:b4aa36ae11ac | 11 | int score = 0; |
sergun2311 | 1:b4aa36ae11ac | 12 | bool flag; |
sergun2311 | 0:645509d95b8d | 13 | clock_t start_s; |
sergun2311 | 0:645509d95b8d | 14 | TFTInit(); |
sergun2311 | 0:645509d95b8d | 15 | drawMap(); |
sergun2311 | 0:645509d95b8d | 16 | while (1) { |
sergun2311 | 0:645509d95b8d | 17 | Block NewBlock; |
sergun2311 | 1:b4aa36ae11ac | 18 | flag = false; |
sergun2311 | 0:645509d95b8d | 19 | drawMap(); |
sergun2311 | 2:6b6986c3d2bd | 20 | drawScore(score); |
sergun2311 | 2:6b6986c3d2bd | 21 | drawNextBlock(NewBlock); |
sergun2311 | 1:b4aa36ae11ac | 22 | while( !flag ) { |
sergun2311 | 0:645509d95b8d | 23 | drawMap(); |
sergun2311 | 0:645509d95b8d | 24 | drawBlock(NewBlock); |
sergun2311 | 1:b4aa36ae11ac | 25 | start_s = clock(); |
sergun2311 | 0:645509d95b8d | 26 | while( start_s + SPEED > clock() ) { |
sergun2311 | 1:b4aa36ae11ac | 27 | if ( TouchStatus() ) { |
sergun2311 | 1:b4aa36ae11ac | 28 | clrBlock(NewBlock); |
sergun2311 | 1:b4aa36ae11ac | 29 | NewBlock = doGest(NewBlock); |
sergun2311 | 1:b4aa36ae11ac | 30 | drawBlock(NewBlock); |
sergun2311 | 1:b4aa36ae11ac | 31 | wait_ms(50); |
sergun2311 | 1:b4aa36ae11ac | 32 | } |
sergun2311 | 0:645509d95b8d | 33 | } |
sergun2311 | 0:645509d95b8d | 34 | if ( NewBlock.CheckBottom() ) { |
sergun2311 | 0:645509d95b8d | 35 | saveToField(NewBlock); |
sergun2311 | 1:b4aa36ae11ac | 36 | flag = true; |
sergun2311 | 0:645509d95b8d | 37 | } else { |
sergun2311 | 0:645509d95b8d | 38 | clrBlock(NewBlock); |
sergun2311 | 0:645509d95b8d | 39 | NewBlock.y += 1; |
sergun2311 | 1:b4aa36ae11ac | 40 | drawBlock(NewBlock); |
sergun2311 | 0:645509d95b8d | 41 | } |
sergun2311 | 0:645509d95b8d | 42 | } |
sergun2311 | 1:b4aa36ae11ac | 43 | score += checkLine(); |
sergun2311 | 2:6b6986c3d2bd | 44 | clrNextBlock(NewBlock); |
sergun2311 | 1:b4aa36ae11ac | 45 | if ( checkGameOver() ) |
sergun2311 | 1:b4aa36ae11ac | 46 | break; |
sergun2311 | 0:645509d95b8d | 47 | } |
sergun2311 | 1:b4aa36ae11ac | 48 | gameOver(score); |
sergun2311 | 0:645509d95b8d | 49 | } |