Tetris for the RA8875, derived from another users implementation.

Dependencies:   RA8875

Fork of Tetris by Sergejs Popovs

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

Committer:
WiredHome
Date:
2017-03-18
Revision:
6:d2aa47c92687
Parent:
5:5ce8976cd303
Child:
7:0e426e81c566

File content as of revision 6:d2aa47c92687:

/* Tetris game for touchscreen MicroTFT 320x240 and microcontorller LPC1768
 * Uses SeeedStudioTFTv2 library
 * Copyright (c) 2017 Sergejs Popovs    sergun2311
 * 
 * Derivation for RA8875 and to clean up a lot of magic numbers by D.Smart
 *
 */

#include "mbed.h"
#include <ctime>
#include "playGround.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();

    while (1) {
        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);
                    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;
                }
            }
        }
    }
}