Jordan Sanchez / Mbed 2 deprecated Tetris

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Pieces.cpp Source File

Pieces.cpp

00001 #include Pieces.h
00002 
00003 // Define the Pieces
00004 char mPieces [7 /*kind */ ][4 /* rotation */ ][5 /* horizontal blocks */ ][5 /* vertical blocks */ ] =
00005 {
00006 // Square
00007   {
00008    {
00009     {0, 0, 0, 0, 0},
00010     {0, 0, 0, 0, 0},
00011     {0, 0, 2, 1, 0},
00012     {0, 0, 1, 1, 0},
00013     {0, 0, 0, 0, 0}
00014     },
00015    {
00016     {0, 0, 0, 0, 0},
00017     {0, 0, 0, 0, 0},
00018     {0, 0, 2, 1, 0},
00019     {0, 0, 1, 1, 0},
00020     {0, 0, 0, 0, 0}
00021     },
00022    {
00023     {0, 0, 0, 0, 0},
00024     {0, 0, 0, 0, 0},
00025     {0, 0, 2, 1, 0},
00026     {0, 0, 1, 1, 0},
00027     {0, 0, 0, 0, 0}
00028     },
00029    {
00030     {0, 0, 0, 0, 0},
00031     {0, 0, 0, 0, 0},
00032     {0, 0, 2, 1, 0},
00033     {0, 0, 1, 1, 0},
00034     {0, 0, 0, 0, 0}
00035     }
00036    },
00037 
00038 // I
00039   {
00040    {
00041     {0, 0, 0, 0, 0},
00042     {0, 0, 0, 0, 0},
00043     {0, 1, 2, 1, 1},
00044     {0, 0, 0, 0, 0},
00045     {0, 0, 0, 0, 0}
00046     },
00047    {
00048     {0, 0, 0, 0, 0},
00049     {0, 0, 1, 0, 0}, 
00050     {0, 0, 2, 0, 0},
00051     {0, 0, 1, 0, 0},
00052     {0, 0, 1, 0, 0}
00053     },
00054    {
00055     {0, 0, 0, 0, 0},
00056     {0, 0, 0, 0, 0},
00057     {1, 1, 2, 1, 0},
00058     {0, 0, 0, 0, 0},
00059     {0, 0, 0, 0, 0}
00060     },
00061    {
00062     {0, 0, 1, 0, 0},
00063     {0, 0, 1, 0, 0},
00064     {0, 0, 2, 0, 0},
00065     {0, 0, 1, 0, 0},
00066     {0, 0, 0, 0, 0}
00067     }
00068    }
00069   ,
00070 // L
00071   {
00072    {
00073     {0, 0, 0, 0, 0},
00074     {0, 0, 1, 0, 0},
00075     {0, 0, 2, 0, 0},
00076     {0, 0, 1, 1, 0},
00077     {0, 0, 0, 0, 0}
00078     },
00079    {
00080     {0, 0, 0, 0, 0},
00081     {0, 0, 0, 0, 0},
00082     {0, 1, 2, 1, 0},
00083     {0, 1, 0, 0, 0},
00084     {0, 0, 0, 0, 0}
00085     },
00086    {
00087     {0, 0, 0, 0, 0},
00088     {0, 1, 1, 0, 0},
00089     {0, 0, 2, 0, 0},
00090     {0, 0, 1, 0, 0},
00091     {0, 0, 0, 0, 0}
00092     },
00093    {
00094     {0, 0, 0, 0, 0},
00095     {0, 0, 0, 1, 0},
00096     {0, 1, 2, 1, 0},
00097     {0, 0, 0, 0, 0},
00098     {0, 0, 0, 0, 0}
00099     }
00100    },
00101 // L mirrored
00102   {
00103    {
00104     {0, 0, 0, 0, 0},
00105     {0, 0, 1, 0, 0},
00106     {0, 0, 2, 0, 0},
00107     {0, 1, 1, 0, 0},
00108     {0, 0, 0, 0, 0}
00109     },
00110    {
00111     {0, 0, 0, 0, 0},
00112     {0, 1, 0, 0, 0},
00113     {0, 1, 2, 1, 0},
00114     {0, 0, 0, 0, 0},
00115     {0, 0, 0, 0, 0}
00116     },
00117    {
00118     {0, 0, 0, 0, 0},
00119     {0, 0, 1, 1, 0},
00120     {0, 0, 2, 0, 0},
00121     {0, 0, 1, 0, 0},
00122     {0, 0, 0, 0, 0}
00123     },
00124    {
00125     {0, 0, 0, 0, 0},
00126     {0, 0, 0, 0, 0},
00127     {0, 1, 2, 1, 0},
00128     {0, 0, 0, 1, 0},
00129     {0, 0, 0, 0, 0}
00130     }
00131    },
00132 // N
00133   {
00134    {
00135     {0, 0, 0, 0, 0},
00136     {0, 0, 0, 1, 0},
00137     {0, 0, 2, 1, 0},
00138     {0, 0, 1, 0, 0},
00139     {0, 0, 0, 0, 0}
00140     },
00141    {
00142     {0, 0, 0, 0, 0},
00143     {0, 0, 0, 0, 0},
00144     {0, 1, 2, 0, 0},
00145     {0, 0, 1, 1, 0},
00146     {0, 0, 0, 0, 0}
00147     },
00148    {
00149     {0, 0, 0, 0, 0},
00150     {0, 0, 1, 0, 0},
00151     {0, 1, 2, 0, 0},
00152     {0, 1, 0, 0, 0},
00153     {0, 0, 0, 0, 0}
00154     },
00155    {
00156     {0, 0, 0, 0, 0},
00157     {0, 1, 1, 0, 0},
00158     {0, 0, 2, 1, 0},
00159     {0, 0, 0, 0, 0},
00160     {0, 0, 0, 0, 0}
00161     }
00162    },
00163 // N mirrored
00164   {
00165    {
00166     {0, 0, 0, 0, 0},
00167     {0, 0, 1, 0, 0},
00168     {0, 0, 2, 1, 0},
00169     {0, 0, 0, 1, 0},
00170     {0, 0, 0, 0, 0}
00171     },
00172    {
00173     {0, 0, 0, 0, 0},
00174     {0, 0, 0, 0, 0},
00175     {0, 0, 2, 1, 0},
00176     {0, 1, 1, 0, 0},
00177     {0, 0, 0, 0, 0}
00178     },
00179    {
00180     {0, 0, 0, 0, 0},
00181     {0, 1, 0, 0, 0},
00182     {0, 1, 2, 0, 0},
00183     {0, 0, 1, 0, 0},
00184     {0, 0, 0, 0, 0}
00185     },
00186    {
00187     {0, 0, 0, 0, 0},
00188     {0, 0, 1, 1, 0},
00189     {0, 1, 2, 0, 0},
00190     {0, 0, 0, 0, 0},
00191     {0, 0, 0, 0, 0}
00192     }
00193    },
00194 // T
00195   {
00196    {
00197     {0, 0, 0, 0, 0},
00198     {0, 0, 1, 0, 0},
00199     {0, 0, 2, 1, 0},
00200     {0, 0, 1, 0, 0},
00201     {0, 0, 0, 0, 0}
00202     },
00203    {
00204     {0, 0, 0, 0, 0},
00205     {0, 0, 0, 0, 0},
00206     {0, 1, 2, 1, 0},
00207     {0, 0, 1, 0, 0},
00208     {0, 0, 0, 0, 0}
00209     },
00210    {
00211     {0, 0, 0, 0, 0},
00212     {0, 0, 1, 0, 0},
00213     {0, 1, 2, 0, 0},
00214     {0, 0, 1, 0, 0},
00215     {0, 0, 0, 0, 0}
00216     },
00217    {
00218     {0, 0, 0, 0, 0},
00219     {0, 0, 1, 0, 0},
00220     {0, 1, 2, 1, 0},
00221     {0, 0, 0, 0, 0},
00222     {0, 0, 0, 0, 0}
00223     }
00224    }
00225 };
00226 
00227 // Displacement of the piece to the position where it is first drawn in the board when it is created
00228 int mPiecesInitialPosition  [7 /*kind */ ][4 /* rotation */ ][2 /* position */] =
00229 {
00230 /* Square */
00231   {
00232     {-2, -3}, 
00233     {-2, -3},
00234     {-2, -3},
00235     {-2, -3}
00236    },
00237 /* I */
00238   {
00239     {-2, -2},
00240     {-2, -3},
00241     {-2, -2},
00242     {-2, -3}
00243    },
00244 /* L */
00245   {
00246     {-2, -3},
00247     {-2, -3},
00248     {-2, -3},
00249     {-2, -2}
00250    },
00251 /* L mirrored */
00252   {
00253     {-2, -3},
00254     {-2, -2},
00255     {-2, -3},
00256     {-2, -3}
00257    },
00258 /* N */
00259   {
00260     {-2, -3},
00261     {-2, -3},
00262     {-2, -3},
00263     {-2, -2}
00264    },
00265 /* N mirrored */
00266   {
00267     {-2, -3},
00268     {-2, -3},
00269     {-2, -3},
00270     {-2, -2}
00271    },
00272 /* T */
00273   {
00274     {-2, -3},
00275     {-2, -3},
00276     {-2, -3},
00277     {-2, -2}
00278    },
00279 };
00280 
00281 /* 
00282 ======================================                                  
00283 Return the type of a block (0 = no-block, 1 = normal block, 2 = pivot block)
00284 
00285 Parameters:
00286 
00287 int pPiece:      Piece to draw
00288 int pRotation:   1 of the 4 possible rotations
00289 int pX:          Horizontal position in blocks
00290 int pY:          Vertical position in blocks
00291 ====================================== 
00292 */
00293 int Pieces::GetBlockType (int pPiece, int pRotation, int pX, int pY)
00294 {
00295     return mPieces [pPiece][pRotation][pX][pY];
00296 }
00297 
00298 /* 
00299 ======================================                                  
00300 Returns the horizontal displacement of the piece that has to be applied in order to create it in the
00301 correct position.
00302 
00303 Parameters:
00304 
00305 int pPiece:  Piece to draw
00306 int pRotation:   1 of the 4 possible rotations
00307 ====================================== 
00308 */
00309 int Pieces::GetXInitialPosition (int pPiece, int pRotation)
00310 {
00311     return mPiecesInitialPosition [pPiece][pRotation][0];
00312 }
00313 
00314 /* 
00315 ======================================                                  
00316 Returns the vertical displacement of the piece that has to be applied in order to create it in the
00317 correct position.
00318 
00319 Parameters:
00320 
00321 int pPiece:  Piece to draw
00322 int pRotation:   1 of the 4 possible rotations
00323 ====================================== 
00324 */
00325 int Pieces::GetYInitialPosition (int pPiece, int pRotation)
00326 {
00327     return mPiecesInitialPosition [pPiece][pRotation][1];
00328 }