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