![](/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@5:5ce8976cd303, 2017-03-18 (annotated)
- Committer:
- WiredHome
- Date:
- Sat Mar 18 22:30:32 2017 +0000
- Revision:
- 5:5ce8976cd303
- Parent:
- 4:107d1d5a642e
- Child:
- 6:d2aa47c92687
Tetris for the RA8875 display, derived from sergun2311, who's commit caught my eye at just the right moment. Currently "sized" for the 800x480 display, but this can be managed in Define.h with a number of macros.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sergun2311 | 4:107d1d5a642e | 1 | /* Tetris game for touchscreen MicroTFT 320x240 and microcontorller LPC1768 |
sergun2311 | 4:107d1d5a642e | 2 | * Uses SeeedStudioTFTv2 library |
sergun2311 | 4:107d1d5a642e | 3 | * Copyright (c) 2017 Sergejs Popovs sergun2311 |
sergun2311 | 4:107d1d5a642e | 4 | */ |
sergun2311 | 4:107d1d5a642e | 5 | |
sergun2311 | 0:645509d95b8d | 6 | #include "mbed.h" |
sergun2311 | 0:645509d95b8d | 7 | #include <ctime> |
sergun2311 | 0:645509d95b8d | 8 | #include "playGround.h" |
sergun2311 | 0:645509d95b8d | 9 | #include "Block.h" |
sergun2311 | 1:b4aa36ae11ac | 10 | #include "Field.h" |
sergun2311 | 4:107d1d5a642e | 11 | #include "Define.h" |
sergun2311 | 0:645509d95b8d | 12 | |
WiredHome | 5:5ce8976cd303 | 13 | Serial pc(USBTX, USBRX); // Not required for display |
WiredHome | 5:5ce8976cd303 | 14 | |
sergun2311 | 0:645509d95b8d | 15 | int main() |
sergun2311 | 0:645509d95b8d | 16 | { |
sergun2311 | 1:b4aa36ae11ac | 17 | int score = 0; |
sergun2311 | 4:107d1d5a642e | 18 | int period = SPEED; |
sergun2311 | 1:b4aa36ae11ac | 19 | bool flag; |
sergun2311 | 0:645509d95b8d | 20 | clock_t start_s; |
WiredHome | 5:5ce8976cd303 | 21 | pc.baud(460800); //I like a snappy terminal, so crank it up! |
WiredHome | 5:5ce8976cd303 | 22 | pc.printf("\r\nTetris - Build " __DATE__ " " __TIME__ "\r\n"); |
WiredHome | 5:5ce8976cd303 | 23 | int playState = 0; // 0=init, 1=newBlock, 2=game over |
sergun2311 | 0:645509d95b8d | 24 | TFTInit(); |
WiredHome | 5:5ce8976cd303 | 25 | |
sergun2311 | 0:645509d95b8d | 26 | while (1) { |
WiredHome | 5:5ce8976cd303 | 27 | switch (playState) { |
WiredHome | 5:5ce8976cd303 | 28 | case 0: { // init |
WiredHome | 5:5ce8976cd303 | 29 | score = 0; |
WiredHome | 5:5ce8976cd303 | 30 | period = SPEED; |
WiredHome | 5:5ce8976cd303 | 31 | ReInitGame(); |
WiredHome | 5:5ce8976cd303 | 32 | drawFrame(); |
WiredHome | 5:5ce8976cd303 | 33 | drawMap(); |
WiredHome | 5:5ce8976cd303 | 34 | playState++; |
WiredHome | 5:5ce8976cd303 | 35 | // break; // fall thru |
WiredHome | 5:5ce8976cd303 | 36 | } |
WiredHome | 5:5ce8976cd303 | 37 | case 1: { |
WiredHome | 5:5ce8976cd303 | 38 | Block NewBlock; |
WiredHome | 5:5ce8976cd303 | 39 | flag = false; |
WiredHome | 5:5ce8976cd303 | 40 | drawScore(score); |
WiredHome | 5:5ce8976cd303 | 41 | drawNextBlock(NewBlock); |
WiredHome | 5:5ce8976cd303 | 42 | while( !flag ) { |
WiredHome | 5:5ce8976cd303 | 43 | drawMap(); |
sergun2311 | 1:b4aa36ae11ac | 44 | drawBlock(NewBlock); |
WiredHome | 5:5ce8976cd303 | 45 | start_s = clock(); |
WiredHome | 5:5ce8976cd303 | 46 | while( start_s + period > clock() ) { |
WiredHome | 5:5ce8976cd303 | 47 | if ( TouchStatus() ) { |
WiredHome | 5:5ce8976cd303 | 48 | clrBlock(NewBlock); |
WiredHome | 5:5ce8976cd303 | 49 | NewBlock = doGest(NewBlock); |
WiredHome | 5:5ce8976cd303 | 50 | drawBlock(NewBlock); |
WiredHome | 5:5ce8976cd303 | 51 | wait_ms(80); |
WiredHome | 5:5ce8976cd303 | 52 | } |
WiredHome | 5:5ce8976cd303 | 53 | } |
WiredHome | 5:5ce8976cd303 | 54 | if ( NewBlock.CheckBottom() ) { |
WiredHome | 5:5ce8976cd303 | 55 | saveToField(NewBlock); |
WiredHome | 5:5ce8976cd303 | 56 | flag = true; |
WiredHome | 5:5ce8976cd303 | 57 | } else { |
WiredHome | 5:5ce8976cd303 | 58 | clrBlock(NewBlock); |
WiredHome | 5:5ce8976cd303 | 59 | NewBlock.y += 1; |
WiredHome | 5:5ce8976cd303 | 60 | drawBlock(NewBlock); |
WiredHome | 5:5ce8976cd303 | 61 | } |
WiredHome | 5:5ce8976cd303 | 62 | } |
WiredHome | 5:5ce8976cd303 | 63 | score += checkLine(); |
WiredHome | 5:5ce8976cd303 | 64 | if ( score < 3200 ) |
WiredHome | 5:5ce8976cd303 | 65 | period = SPEED - score / 50; |
WiredHome | 5:5ce8976cd303 | 66 | clrNextBlock(NewBlock); |
WiredHome | 5:5ce8976cd303 | 67 | if ( checkGameOver() ) { |
WiredHome | 5:5ce8976cd303 | 68 | playState++; |
WiredHome | 5:5ce8976cd303 | 69 | gameOver(score); |
WiredHome | 5:5ce8976cd303 | 70 | } |
WiredHome | 5:5ce8976cd303 | 71 | break; |
WiredHome | 5:5ce8976cd303 | 72 | } |
WiredHome | 5:5ce8976cd303 | 73 | case 2: { |
WiredHome | 5:5ce8976cd303 | 74 | if (ReplayTouched()) { |
WiredHome | 5:5ce8976cd303 | 75 | playState = 0; // restart |
WiredHome | 5:5ce8976cd303 | 76 | break; |
sergun2311 | 1:b4aa36ae11ac | 77 | } |
sergun2311 | 0:645509d95b8d | 78 | } |
sergun2311 | 0:645509d95b8d | 79 | } |
sergun2311 | 0:645509d95b8d | 80 | } |
sergun2311 | 0:645509d95b8d | 81 | } |