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:
Sat Mar 18 22:30:32 2017 +0000
Revision:
5:5ce8976cd303
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?

UserRevisionLine numberNew contents of line
WiredHome 5:5ce8976cd303 1 #include "mbed.h"
WiredHome 5:5ce8976cd303 2 #include "playGround.h"
WiredHome 5:5ce8976cd303 3 #include "Piece.h"
WiredHome 5:5ce8976cd303 4 #include "Block.h"
WiredHome 5:5ce8976cd303 5 #include "Field.h"
WiredHome 5:5ce8976cd303 6 #include "BPG_Arial20x20.h"
WiredHome 5:5ce8976cd303 7 #include "BPG_Arial10x10.h"
WiredHome 5:5ce8976cd303 8 #include "Define.h"
WiredHome 5:5ce8976cd303 9 #include <ctime>
WiredHome 5:5ce8976cd303 10
WiredHome 5:5ce8976cd303 11 // Define this for 800x480 panel, undefine for 480x272
WiredHome 5:5ce8976cd303 12 #define BIG_SCREEN
WiredHome 5:5ce8976cd303 13
WiredHome 5:5ce8976cd303 14 // Define this for Cap touch panel, undefine for resistive
WiredHome 5:5ce8976cd303 15 #define CAP_TOUCH
WiredHome 5:5ce8976cd303 16
WiredHome 5:5ce8976cd303 17 #ifdef CAP_TOUCH
WiredHome 5:5ce8976cd303 18 RA8875 TFT(p5,p6,p7,p12,NC, p9,p10,p13, "tft"); // SPI:{MOSI,MISO,SCK,/ChipSelect,/reset}, I2C:{SDA,SCL,/IRQ}, name
WiredHome 5:5ce8976cd303 19 #else
WiredHome 5:5ce8976cd303 20 RA8875 TFT(p5,p6,p7,p12,NC, "tft"); // SPI:{MOSI,MISO,SCK,/ChipSelect,/reset}, name
WiredHome 5:5ce8976cd303 21 LocalFileSystem local("local"); // access to calibration file for resistive touch.
WiredHome 5:5ce8976cd303 22 #endif
WiredHome 5:5ce8976cd303 23
WiredHome 5:5ce8976cd303 24 #ifdef BIG_SCREEN
WiredHome 5:5ce8976cd303 25 #define LCD_W 800
WiredHome 5:5ce8976cd303 26 #define LCD_H 480
WiredHome 5:5ce8976cd303 27 #define LCD_C 8 // color - bits per pixel
WiredHome 5:5ce8976cd303 28 #define BL_NORM 25 // Backlight Normal setting (0 to 255)
WiredHome 5:5ce8976cd303 29 #else
WiredHome 5:5ce8976cd303 30 #define LCD_W 480
WiredHome 5:5ce8976cd303 31 #define LCD_H 272
WiredHome 5:5ce8976cd303 32 #define LCD_C 8 // color - bits per pixel
WiredHome 5:5ce8976cd303 33 #define BL_NORM 25 // Backlight Normal setting (0 to 255)
WiredHome 5:5ce8976cd303 34 #endif
WiredHome 5:5ce8976cd303 35
WiredHome 5:5ce8976cd303 36 #if 0
WiredHome 5:5ce8976cd303 37 #define PIN_XP p20
WiredHome 5:5ce8976cd303 38 #define PIN_XM p19
WiredHome 5:5ce8976cd303 39 #define PIN_YP p18
WiredHome 5:5ce8976cd303 40 #define PIN_YM p17
WiredHome 5:5ce8976cd303 41 #define PIN_MOSI p11
WiredHome 5:5ce8976cd303 42 #define PIN_MISO p12
WiredHome 5:5ce8976cd303 43 #define PIN_SCLK p13
WiredHome 5:5ce8976cd303 44 #define PIN_CS_TFT p14
WiredHome 5:5ce8976cd303 45 #define PIN_DC_TFT p21
WiredHome 5:5ce8976cd303 46 #define PIN_BL_TFT p15
WiredHome 5:5ce8976cd303 47 #define PIN_CS_SD p4
WiredHome 5:5ce8976cd303 48 #endif
WiredHome 5:5ce8976cd303 49
WiredHome 5:5ce8976cd303 50 // Hot-Spots
WiredHome 5:5ce8976cd303 51 static const rect_t Drop = { DROP };
WiredHome 5:5ce8976cd303 52 static const rect_t rLeft = { ROT_LEFT };
WiredHome 5:5ce8976cd303 53 static const rect_t rRight = { ROT_RIGHT };
WiredHome 5:5ce8976cd303 54 static const rect_t mLeft = { MOV_LEFT };
WiredHome 5:5ce8976cd303 55 static const rect_t mRight = { MOV_RIGHT };
WiredHome 5:5ce8976cd303 56 static const rect_t Replay = { REPLAY };
WiredHome 5:5ce8976cd303 57
WiredHome 5:5ce8976cd303 58 // Draws Field on the screen. Draw both black and colored blocks
WiredHome 5:5ce8976cd303 59 // It does delete everything on the PlayGround what shouldn't be there
WiredHome 5:5ce8976cd303 60
WiredHome 5:5ce8976cd303 61 void drawMap()
WiredHome 5:5ce8976cd303 62 {
WiredHome 5:5ce8976cd303 63 int y , x;
WiredHome 5:5ce8976cd303 64
WiredHome 5:5ce8976cd303 65 for ( y = 0 ; y < MAXY ; y++ ) {
WiredHome 5:5ce8976cd303 66 for ( x = 0 ; x < MAXX ; x++ ) {
WiredHome 5:5ce8976cd303 67 if ( Field[y][x] != 0 ) {
WiredHome 5:5ce8976cd303 68 TFT.fillrect(ORIGIN_X + BLOCK_SIZE * ( x + 1 ), ORIGIN_Y + BLOCK_SIZE * y,
WiredHome 5:5ce8976cd303 69 ORIGIN_X + BLOCK_SIZE * ( x + 2 ), ORIGIN_Y + BLOCK_SIZE * ( y + 1 ),
WiredHome 5:5ce8976cd303 70 Field[y][x]);
WiredHome 5:5ce8976cd303 71 TFT.rect(ORIGIN_X + BLOCK_SIZE * ( x + 1 ), ORIGIN_Y + BLOCK_SIZE * y,
WiredHome 5:5ce8976cd303 72 ORIGIN_X + BLOCK_SIZE * ( x + 2 ), ORIGIN_Y + BLOCK_SIZE * ( y + 1 ),
WiredHome 5:5ce8976cd303 73 White );
WiredHome 5:5ce8976cd303 74 }
WiredHome 5:5ce8976cd303 75 }
WiredHome 5:5ce8976cd303 76 }
WiredHome 5:5ce8976cd303 77 }
WiredHome 5:5ce8976cd303 78
WiredHome 5:5ce8976cd303 79 // Draws Field on the screen. Draw only colored blocks
WiredHome 5:5ce8976cd303 80 // It doesn't delete anything on the playground what shouldn't be there
WiredHome 5:5ce8976cd303 81
WiredHome 5:5ce8976cd303 82 void drawMapV2()
WiredHome 5:5ce8976cd303 83 {
WiredHome 5:5ce8976cd303 84 int y , x;
WiredHome 5:5ce8976cd303 85
WiredHome 5:5ce8976cd303 86 for ( y = 0 ; y < MAXY ; y++ ) {
WiredHome 5:5ce8976cd303 87 for ( x = 0 ; x < MAXX ; x++ ) {
WiredHome 5:5ce8976cd303 88 TFT.fillrect(ORIGIN_X + BLOCK_SIZE * ( x + 1 ), ORIGIN_Y + BLOCK_SIZE * y,
WiredHome 5:5ce8976cd303 89 ORIGIN_X + BLOCK_SIZE * ( x + 2 ), ORIGIN_Y + BLOCK_SIZE * ( y + 1 ),
WiredHome 5:5ce8976cd303 90 Field[y][x]);
WiredHome 5:5ce8976cd303 91 if ( Field[y][x] != 0 )
WiredHome 5:5ce8976cd303 92 TFT.rect(ORIGIN_X + BLOCK_SIZE * ( x + 1 ), ORIGIN_Y + BLOCK_SIZE * y,
WiredHome 5:5ce8976cd303 93 ORIGIN_X + BLOCK_SIZE * ( x + 2 ), ORIGIN_Y + BLOCK_SIZE * ( y + 1 ),
WiredHome 5:5ce8976cd303 94 White );
WiredHome 5:5ce8976cd303 95 }
WiredHome 5:5ce8976cd303 96 }
WiredHome 5:5ce8976cd303 97 }
WiredHome 5:5ce8976cd303 98
WiredHome 5:5ce8976cd303 99 // Draws NewBlock on the playground.
WiredHome 5:5ce8976cd303 100
WiredHome 5:5ce8976cd303 101 void drawBlock(Block NewBlock)
WiredHome 5:5ce8976cd303 102 {
WiredHome 5:5ce8976cd303 103 int ix , iy , x , y;
WiredHome 5:5ce8976cd303 104 x = NewBlock.x;
WiredHome 5:5ce8976cd303 105 y = NewBlock.y;
WiredHome 5:5ce8976cd303 106 for ( ix = x - 2 ; ix < x + 2 ; ix++ ) {
WiredHome 5:5ce8976cd303 107 for ( iy = y - 2 ; iy < y + 2 ; iy++ ) {
WiredHome 5:5ce8976cd303 108 if ( Piece[NewBlock.form][NewBlock.angle][ix - x + 2][iy - y + 2] != 0 ) {
WiredHome 5:5ce8976cd303 109 TFT.fillrect(ORIGIN_X + BLOCK_SIZE * ( ix + 1 ), ORIGIN_Y + BLOCK_SIZE * iy,
WiredHome 5:5ce8976cd303 110 ORIGIN_X + BLOCK_SIZE * ( ix + 2 ), ORIGIN_Y + BLOCK_SIZE * ( iy + 1 ),
WiredHome 5:5ce8976cd303 111 Piece[NewBlock.form][NewBlock.angle][ix - x + 2][iy - y + 2]);
WiredHome 5:5ce8976cd303 112 TFT.rect(ORIGIN_X + BLOCK_SIZE * ( ix + 1 ), ORIGIN_Y + BLOCK_SIZE * iy,
WiredHome 5:5ce8976cd303 113 ORIGIN_X + BLOCK_SIZE * ( ix + 2 ), ORIGIN_Y + BLOCK_SIZE * ( iy + 1 ),
WiredHome 5:5ce8976cd303 114 White );
WiredHome 5:5ce8976cd303 115 }
WiredHome 5:5ce8976cd303 116 }
WiredHome 5:5ce8976cd303 117 }
WiredHome 5:5ce8976cd303 118 }
WiredHome 5:5ce8976cd303 119
WiredHome 5:5ce8976cd303 120 // Removes NewBlock from the playground.
WiredHome 5:5ce8976cd303 121
WiredHome 5:5ce8976cd303 122 void clrBlock(Block NewBlock)
WiredHome 5:5ce8976cd303 123 {
WiredHome 5:5ce8976cd303 124 int ix , iy , x , y;
WiredHome 5:5ce8976cd303 125 x = NewBlock.x;
WiredHome 5:5ce8976cd303 126 y = NewBlock.y;
WiredHome 5:5ce8976cd303 127 for ( ix = x - 2 ; ix < x + 2 ; ix++ ) {
WiredHome 5:5ce8976cd303 128 for ( iy = y - 2 ; iy < y + 2 ; iy++ ) {
WiredHome 5:5ce8976cd303 129 if ( Piece[NewBlock.form][NewBlock.angle][ix - x + 2][iy - y + 2] != 0 ) {
WiredHome 5:5ce8976cd303 130 TFT.fillrect(ORIGIN_X + BLOCK_SIZE * ( ix + 1 ), ORIGIN_Y + BLOCK_SIZE * iy,
WiredHome 5:5ce8976cd303 131 ORIGIN_X + BLOCK_SIZE * ( ix + 2 ), ORIGIN_Y + BLOCK_SIZE * ( iy + 1 ),
WiredHome 5:5ce8976cd303 132 Black );
WiredHome 5:5ce8976cd303 133 }
WiredHome 5:5ce8976cd303 134 }
WiredHome 5:5ce8976cd303 135 }
WiredHome 5:5ce8976cd303 136 }
WiredHome 5:5ce8976cd303 137
WiredHome 5:5ce8976cd303 138 // Draws Purple frame around playground
WiredHome 5:5ce8976cd303 139
WiredHome 5:5ce8976cd303 140 void drawFrame()
WiredHome 5:5ce8976cd303 141 {
WiredHome 5:5ce8976cd303 142 int x, y;
WiredHome 5:5ce8976cd303 143 for ( y = 0 ; y < (MAXY + 1) * BLOCK_SIZE ; y += BLOCK_SIZE ) {
WiredHome 5:5ce8976cd303 144 TFT.fillrect(ORIGIN_X + 0, ORIGIN_Y + y, ORIGIN_X + BLOCK_SIZE, ORIGIN_Y + y + BLOCK_SIZE, Purple );
WiredHome 5:5ce8976cd303 145 TFT.rect(ORIGIN_X + 0, ORIGIN_Y + y, ORIGIN_X + BLOCK_SIZE, ORIGIN_Y + y + BLOCK_SIZE, DarkGray );
WiredHome 5:5ce8976cd303 146 TFT.fillrect(ORIGIN_X + (MAXX + 1) * BLOCK_SIZE, ORIGIN_Y + y, ORIGIN_X + (MAXX + 2) * BLOCK_SIZE, ORIGIN_Y + y + BLOCK_SIZE, Purple );
WiredHome 5:5ce8976cd303 147 TFT.rect(ORIGIN_X + (MAXX + 1) * BLOCK_SIZE, ORIGIN_Y + y, ORIGIN_X + (MAXX + 2) * BLOCK_SIZE, ORIGIN_Y + y + BLOCK_SIZE, DarkGray );
WiredHome 5:5ce8976cd303 148 }
WiredHome 5:5ce8976cd303 149 for ( x = 0 ; x < (MAXX + 2) * BLOCK_SIZE ; x += BLOCK_SIZE ) {
WiredHome 5:5ce8976cd303 150 TFT.fillrect(ORIGIN_X + x, ORIGIN_Y + MAXY * BLOCK_SIZE, ORIGIN_X + x + BLOCK_SIZE, ORIGIN_Y + (MAXY + 1) * BLOCK_SIZE, Purple );
WiredHome 5:5ce8976cd303 151 TFT.rect(ORIGIN_X + x, ORIGIN_Y + MAXY * BLOCK_SIZE, ORIGIN_X + x + BLOCK_SIZE, ORIGIN_Y + (MAXY + 1) * BLOCK_SIZE, DarkGray );
WiredHome 5:5ce8976cd303 152 }
WiredHome 5:5ce8976cd303 153 }
WiredHome 5:5ce8976cd303 154
WiredHome 5:5ce8976cd303 155 // Initializes screen parameters, sets orentation, background,
WiredHome 5:5ce8976cd303 156 // fonts and cleans screen.
WiredHome 5:5ce8976cd303 157
WiredHome 5:5ce8976cd303 158 void TFTInit()
WiredHome 5:5ce8976cd303 159 {
WiredHome 5:5ce8976cd303 160 TFT.init(LCD_W,LCD_H,LCD_C);
WiredHome 5:5ce8976cd303 161 TFT.TouchPanelInit();
WiredHome 5:5ce8976cd303 162 TFT.Backlight_u8(BL_NORM);
WiredHome 5:5ce8976cd303 163 TFT.SetOrientation();
WiredHome 5:5ce8976cd303 164 }
WiredHome 5:5ce8976cd303 165
WiredHome 5:5ce8976cd303 166 void ReInitGame() {
WiredHome 5:5ce8976cd303 167 TFT.foreground(White);
WiredHome 5:5ce8976cd303 168 TFT.background(Black);
WiredHome 5:5ce8976cd303 169 TFT.cls();
WiredHome 5:5ce8976cd303 170 TFT.SetLayerMode(RA8875::BooleanOR);
WiredHome 5:5ce8976cd303 171 TFT.SelectUserFont(BPG_Arial20x20);
WiredHome 5:5ce8976cd303 172 TFT.SelectDrawingLayer(1);
WiredHome 5:5ce8976cd303 173 TFT.SetGraphicsCursor(TITLE_X,TITLE_Y);
WiredHome 5:5ce8976cd303 174 TFT.printf("Tetris for the RA8875\r\n");
WiredHome 5:5ce8976cd303 175 TFT.SelectUserFont(BPG_Arial10x10);
WiredHome 5:5ce8976cd303 176 TFT.printf(" adapted by Smartware Computing");
WiredHome 5:5ce8976cd303 177 TFT.rect(Drop, Charcoal);
WiredHome 5:5ce8976cd303 178 TFT.rect(rLeft, Charcoal);
WiredHome 5:5ce8976cd303 179 TFT.rect(rRight, Charcoal);
WiredHome 5:5ce8976cd303 180 TFT.rect(mLeft, Charcoal);
WiredHome 5:5ce8976cd303 181 TFT.rect(mRight, Charcoal);
WiredHome 5:5ce8976cd303 182 TFT.SelectDrawingLayer(0);
WiredHome 5:5ce8976cd303 183 }
WiredHome 5:5ce8976cd303 184
WiredHome 5:5ce8976cd303 185 void gameOver(int score)
WiredHome 5:5ce8976cd303 186 {
WiredHome 5:5ce8976cd303 187 drawScore(score);
WiredHome 5:5ce8976cd303 188 TFT.fillrect(Replay, Blue);
WiredHome 5:5ce8976cd303 189 TFT.rect(Replay, White);
WiredHome 5:5ce8976cd303 190 TFT.SetTextCursor(Replay.p1.x+15,(Replay.p1.y+Replay.p2.y)/2-TFT.fontheight()/2);
WiredHome 5:5ce8976cd303 191 TFT.foreground(White);
WiredHome 5:5ce8976cd303 192 TFT.background(Blue);
WiredHome 5:5ce8976cd303 193 TFT.puts("Replay");
WiredHome 5:5ce8976cd303 194 }
WiredHome 5:5ce8976cd303 195
WiredHome 5:5ce8976cd303 196 bool ReplayTouched() {
WiredHome 5:5ce8976cd303 197 point_t p;
WiredHome 5:5ce8976cd303 198
WiredHome 5:5ce8976cd303 199 if (TFT.TouchPanelReadable(&p))
WiredHome 5:5ce8976cd303 200 return true;
WiredHome 5:5ce8976cd303 201 else
WiredHome 5:5ce8976cd303 202 return false;
WiredHome 5:5ce8976cd303 203 }
WiredHome 5:5ce8976cd303 204
WiredHome 5:5ce8976cd303 205 void drawScore(int score)
WiredHome 5:5ce8976cd303 206 {
WiredHome 5:5ce8976cd303 207 TFT.SelectUserFont(BPG_Arial20x20);
WiredHome 5:5ce8976cd303 208 TFT.SetTextCursor(SCORE_X, SCORE_Y);
WiredHome 5:5ce8976cd303 209 TFT.foreground(BrightRed);
WiredHome 5:5ce8976cd303 210 TFT.printf("Score : %i", score);
WiredHome 5:5ce8976cd303 211 }
WiredHome 5:5ce8976cd303 212
WiredHome 5:5ce8976cd303 213
WiredHome 5:5ce8976cd303 214 // Reads gestures from the screen.
WiredHome 5:5ce8976cd303 215 // Returns : 0 for dropping object down
WiredHome 5:5ce8976cd303 216 // 1 for moving object to the right
WiredHome 5:5ce8976cd303 217 // 2 for moving object to the left
WiredHome 5:5ce8976cd303 218 // 3 for rotating object counter-clockwise
WiredHome 5:5ce8976cd303 219 // 4 for rotating objec clockwise
WiredHome 5:5ce8976cd303 220 int getGesture()
WiredHome 5:5ce8976cd303 221 {
WiredHome 5:5ce8976cd303 222 point_t p;
WiredHome 5:5ce8976cd303 223 clock_t start_s = clock();
WiredHome 5:5ce8976cd303 224 int flag = 0;
WiredHome 5:5ce8976cd303 225 while( !flag ) {
WiredHome 5:5ce8976cd303 226 p.x=0;
WiredHome 5:5ce8976cd303 227 p.y=0;
WiredHome 5:5ce8976cd303 228 TouchCode_t t = TFT.TouchCode();
WiredHome 5:5ce8976cd303 229 if ( t == touch || t == held ) {
WiredHome 5:5ce8976cd303 230 p = TFT.TouchCoordinates(); // read analog pos.
WiredHome 5:5ce8976cd303 231 flag = 1;
WiredHome 5:5ce8976cd303 232 } else if ( start_s > 10 )
WiredHome 5:5ce8976cd303 233 return 13;
WiredHome 5:5ce8976cd303 234 }
WiredHome 5:5ce8976cd303 235 if ( TFT.Intersect(Drop,p) ) { // below the bottom to drop
WiredHome 5:5ce8976cd303 236 return 0 ;
WiredHome 5:5ce8976cd303 237 } else if ( TFT.Intersect(rLeft, p) ) {
WiredHome 5:5ce8976cd303 238 return 3;
WiredHome 5:5ce8976cd303 239 } else if ( TFT.Intersect(rRight, p) ) {
WiredHome 5:5ce8976cd303 240 return 4;
WiredHome 5:5ce8976cd303 241 } else if ( TFT.Intersect(mLeft, p) ) {
WiredHome 5:5ce8976cd303 242 return 2;
WiredHome 5:5ce8976cd303 243 } else if ( TFT.Intersect(mRight, p) ) {
WiredHome 5:5ce8976cd303 244 return 1;
WiredHome 5:5ce8976cd303 245 }
WiredHome 5:5ce8976cd303 246 return 13; //13 = IGNORE
WiredHome 5:5ce8976cd303 247 }
WiredHome 5:5ce8976cd303 248
WiredHome 5:5ce8976cd303 249 // Returns status of screen. If it was touched returns true, else false
WiredHome 5:5ce8976cd303 250
WiredHome 5:5ce8976cd303 251 bool TouchStatus()
WiredHome 5:5ce8976cd303 252 {
WiredHome 5:5ce8976cd303 253 if ( TFT.TouchPanelReadable() )
WiredHome 5:5ce8976cd303 254 return true;
WiredHome 5:5ce8976cd303 255 return false;
WiredHome 5:5ce8976cd303 256 }
WiredHome 5:5ce8976cd303 257
WiredHome 5:5ce8976cd303 258 // Moves NewBlock acording the gesture was read by function getGesture.
WiredHome 5:5ce8976cd303 259
WiredHome 5:5ce8976cd303 260 Block doGest(Block NewBlock)
WiredHome 5:5ce8976cd303 261 {
WiredHome 5:5ce8976cd303 262 static bool lockout = false;
WiredHome 5:5ce8976cd303 263 int gest = getGesture();
WiredHome 5:5ce8976cd303 264 if ( gest != 13 ) {
WiredHome 5:5ce8976cd303 265 switch ( gest ) {
WiredHome 5:5ce8976cd303 266 case 0: {
WiredHome 5:5ce8976cd303 267 while ( !NewBlock.CheckBottom() ) {
WiredHome 5:5ce8976cd303 268 NewBlock.y++;
WiredHome 5:5ce8976cd303 269 }
WiredHome 5:5ce8976cd303 270 saveToField(NewBlock);
WiredHome 5:5ce8976cd303 271 drawFrame();
WiredHome 5:5ce8976cd303 272 lockout = false;
WiredHome 5:5ce8976cd303 273 break;
WiredHome 5:5ce8976cd303 274 }
WiredHome 5:5ce8976cd303 275 case 1: {
WiredHome 5:5ce8976cd303 276 NewBlock.moveRight();
WiredHome 5:5ce8976cd303 277 lockout = false;
WiredHome 5:5ce8976cd303 278 break;
WiredHome 5:5ce8976cd303 279 }
WiredHome 5:5ce8976cd303 280 case 2: {
WiredHome 5:5ce8976cd303 281 NewBlock.moveLeft();
WiredHome 5:5ce8976cd303 282 lockout = false;
WiredHome 5:5ce8976cd303 283 break;
WiredHome 5:5ce8976cd303 284 }
WiredHome 5:5ce8976cd303 285 case 3: {
WiredHome 5:5ce8976cd303 286 if (!lockout) {
WiredHome 5:5ce8976cd303 287 lockout = true;
WiredHome 5:5ce8976cd303 288 NewBlock.rotateLeft();
WiredHome 5:5ce8976cd303 289 }
WiredHome 5:5ce8976cd303 290 break;
WiredHome 5:5ce8976cd303 291 }
WiredHome 5:5ce8976cd303 292 case 4: {
WiredHome 5:5ce8976cd303 293 if (!lockout) {
WiredHome 5:5ce8976cd303 294 lockout = true;
WiredHome 5:5ce8976cd303 295 NewBlock.rotateRight();
WiredHome 5:5ce8976cd303 296 }
WiredHome 5:5ce8976cd303 297 break;
WiredHome 5:5ce8976cd303 298 }
WiredHome 5:5ce8976cd303 299 }
WiredHome 5:5ce8976cd303 300 } else {
WiredHome 5:5ce8976cd303 301 lockout = false;
WiredHome 5:5ce8976cd303 302 }
WiredHome 5:5ce8976cd303 303 return NewBlock;
WiredHome 5:5ce8976cd303 304 }
WiredHome 5:5ce8976cd303 305
WiredHome 5:5ce8976cd303 306
WiredHome 5:5ce8976cd303 307 // Draws the next block on the bottom of the screen.
WiredHome 5:5ce8976cd303 308 // Block is sized of SMALL_BLOCK_SIZED
WiredHome 5:5ce8976cd303 309
WiredHome 5:5ce8976cd303 310 void drawNextBlock(Block NewBlock)
WiredHome 5:5ce8976cd303 311 {
WiredHome 5:5ce8976cd303 312 int ix, iy;
WiredHome 5:5ce8976cd303 313
WiredHome 5:5ce8976cd303 314 for ( ix = - 2 ; ix < 2 ; ix++ ) {
WiredHome 5:5ce8976cd303 315 for ( iy = - 2 ; iy < 2 ; iy++ ) {
WiredHome 5:5ce8976cd303 316 rect_t r;
WiredHome 5:5ce8976cd303 317
WiredHome 5:5ce8976cd303 318 r.p1.x = SB_X - 2 * SMALL_BLOCK_SIZE + SMALL_BLOCK_SIZE * ( ix + 1 );
WiredHome 5:5ce8976cd303 319 r.p1.y = SB_Y - 2 * SMALL_BLOCK_SIZE + SMALL_BLOCK_SIZE * iy;
WiredHome 5:5ce8976cd303 320 r.p2.x = SB_X - 2 * SMALL_BLOCK_SIZE + SMALL_BLOCK_SIZE * ( ix + 2 );
WiredHome 5:5ce8976cd303 321 r.p2.y = SB_Y - 2 * SMALL_BLOCK_SIZE + SMALL_BLOCK_SIZE * ( iy + 1 );
WiredHome 5:5ce8976cd303 322 if ( Piece[NewBlock.nextForm][NewBlock.angle][ix + 2][iy + 2] != 0 ) {
WiredHome 5:5ce8976cd303 323 TFT.fillrect(r, Piece[NewBlock.nextForm][NewBlock.angle][ix + 2][iy + 2]);
WiredHome 5:5ce8976cd303 324 TFT.rect(r, White );
WiredHome 5:5ce8976cd303 325 }
WiredHome 5:5ce8976cd303 326 }
WiredHome 5:5ce8976cd303 327 }
WiredHome 5:5ce8976cd303 328 }
WiredHome 5:5ce8976cd303 329
WiredHome 5:5ce8976cd303 330 void clrNextBlock(Block NewBlock)
WiredHome 5:5ce8976cd303 331 {
WiredHome 5:5ce8976cd303 332 rect_t r;
WiredHome 5:5ce8976cd303 333
WiredHome 5:5ce8976cd303 334 r.p1.x = SB_X - 2 * SMALL_BLOCK_SIZE + SMALL_BLOCK_SIZE * ( -2 + 1 );
WiredHome 5:5ce8976cd303 335 r.p1.y = SB_Y - 2 * SMALL_BLOCK_SIZE + SMALL_BLOCK_SIZE * -2;
WiredHome 5:5ce8976cd303 336 r.p2.x = SB_X - 2 * SMALL_BLOCK_SIZE + SMALL_BLOCK_SIZE * ( 1 + 2 );
WiredHome 5:5ce8976cd303 337 r.p2.y = SB_Y - 2 * SMALL_BLOCK_SIZE + SMALL_BLOCK_SIZE * ( 1 + 1 );
WiredHome 5:5ce8976cd303 338 TFT.fillrect( r, Black );
WiredHome 5:5ce8976cd303 339 }