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.

Committer:
WiredHome
Date:
Sun Mar 29 18:21:14 2020 +0000
Revision:
11:2bdc83648d7f
Parent:
5:5ce8976cd303
Pick up a bug-fix on jpeg rendering

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 5:5ce8976cd303 1 #include "Field.h"
WiredHome 5:5ce8976cd303 2 #include "playGround.h"
WiredHome 5:5ce8976cd303 3 #include "Piece.h"
WiredHome 5:5ce8976cd303 4 #include "Define.h"
WiredHome 5:5ce8976cd303 5
WiredHome 5:5ce8976cd303 6 // Declearing and defining of the playground/field
WiredHome 5:5ce8976cd303 7 extern int Field[MAXY][MAXX] = {0};
WiredHome 5:5ce8976cd303 8
WiredHome 5:5ce8976cd303 9 // Checking field for filled lines. If it is field
WiredHome 5:5ce8976cd303 10 // it removes it with lines upon it
WiredHome 5:5ce8976cd303 11 // Returns Score equal to amount of removed lines, multiplied with 100
WiredHome 5:5ce8976cd303 12
WiredHome 5:5ce8976cd303 13 int checkLine()
WiredHome 5:5ce8976cd303 14 {
WiredHome 5:5ce8976cd303 15 int x, y, score = 0;
WiredHome 5:5ce8976cd303 16 bool status;
WiredHome 5:5ce8976cd303 17 for ( y = 0 ; y < MAXY ; y++ ) {
WiredHome 5:5ce8976cd303 18 status = true;
WiredHome 5:5ce8976cd303 19 for ( x = 0 ; x < MAXX ; x++ ) {
WiredHome 5:5ce8976cd303 20 if ( Field[y][x] == Black )
WiredHome 5:5ce8976cd303 21 status = false;
WiredHome 5:5ce8976cd303 22 }
WiredHome 5:5ce8976cd303 23 if ( status ) {
WiredHome 5:5ce8976cd303 24 score += 100;
WiredHome 5:5ce8976cd303 25 int xx, yy;
WiredHome 5:5ce8976cd303 26 for ( yy = y ; yy > 0 ; yy-- ) {
WiredHome 5:5ce8976cd303 27 for (xx = 0 ; xx < MAXX ; xx++ ) {
WiredHome 5:5ce8976cd303 28 Field[yy][xx] = Field[yy-1][xx];
WiredHome 5:5ce8976cd303 29 }
WiredHome 5:5ce8976cd303 30 }
WiredHome 5:5ce8976cd303 31 }
WiredHome 5:5ce8976cd303 32 }
WiredHome 5:5ce8976cd303 33 if (score)
WiredHome 5:5ce8976cd303 34 drawMapV2();
WiredHome 5:5ce8976cd303 35 return score;
WiredHome 5:5ce8976cd303 36 }
WiredHome 5:5ce8976cd303 37
WiredHome 5:5ce8976cd303 38 // Checks blocks on MAXX (top) layer.
WiredHome 5:5ce8976cd303 39 // If there is any it retunrs TRUE ,else false
WiredHome 5:5ce8976cd303 40
WiredHome 5:5ce8976cd303 41 bool checkGameOver()
WiredHome 5:5ce8976cd303 42 {
WiredHome 5:5ce8976cd303 43 int x;
WiredHome 5:5ce8976cd303 44 for ( x = 0 ; x < MAXX ; x++ )
WiredHome 5:5ce8976cd303 45 if ( Field[0][x] != Black )
WiredHome 5:5ce8976cd303 46 return true;
WiredHome 5:5ce8976cd303 47 return false;
WiredHome 5:5ce8976cd303 48 }
WiredHome 5:5ce8976cd303 49
WiredHome 5:5ce8976cd303 50 // Saves an object NewBlock to the field.
WiredHome 5:5ce8976cd303 51 // Fills matrix with colors of the blocks
WiredHome 5:5ce8976cd303 52
WiredHome 5:5ce8976cd303 53 void saveToField(Block NewBlock)
WiredHome 5:5ce8976cd303 54 {
WiredHome 5:5ce8976cd303 55 int xx , yy;
WiredHome 5:5ce8976cd303 56 for ( xx = 0 ; xx < 5 ; xx++ ) {
WiredHome 5:5ce8976cd303 57 for (yy = 0 ; yy < 5 ; yy++ ) {
WiredHome 5:5ce8976cd303 58 if ( Piece[NewBlock.form][NewBlock.angle][xx][yy] != 0 )
WiredHome 5:5ce8976cd303 59 Field[NewBlock.y + yy - 2][NewBlock.x + xx - 2] =
WiredHome 5:5ce8976cd303 60 Piece[NewBlock.form][NewBlock.angle][xx][yy];
WiredHome 5:5ce8976cd303 61 }
WiredHome 5:5ce8976cd303 62 }
WiredHome 5:5ce8976cd303 63 }