This is a remake of tetris game for mbed. Please see detail here http://developer.mbed.org/users/sucrelv/notebook/tetris-game-on-mbed
Dependencies: 4DGL-uLCD-SE PinDetect SDFileSystem mbed-rtos mbed wave_player
Pieces.cpp
00001 #include "Pieces.h" 00002 00003 // Pieces definition 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 00228 // Displacement of the piece to the position where it is first drawn in the board when it is created 00229 int mPiecesInitialPosition [7 /*kind */ ][4 /* rotation */ ][2 /* position */] = 00230 { 00231 /* Square */ 00232 { 00233 {-2, -3}, 00234 {-2, -3}, 00235 {-2, -3}, 00236 {-2, -3} 00237 }, 00238 /* I */ 00239 { 00240 {-2, -2}, 00241 {-2, -3}, 00242 {-2, -2}, 00243 {-2, -3} 00244 }, 00245 /* L */ 00246 { 00247 {-2, -3}, 00248 {-2, -3}, 00249 {-2, -3}, 00250 {-2, -2} 00251 }, 00252 /* L mirrored */ 00253 { 00254 {-2, -3}, 00255 {-2, -2}, 00256 {-2, -3}, 00257 {-2, -3} 00258 }, 00259 /* N */ 00260 { 00261 {-2, -3}, 00262 {-2, -3}, 00263 {-2, -3}, 00264 {-2, -2} 00265 }, 00266 /* N mirrored */ 00267 { 00268 {-2, -3}, 00269 {-2, -3}, 00270 {-2, -3}, 00271 {-2, -2} 00272 }, 00273 /* T */ 00274 { 00275 {-2, -3}, 00276 {-2, -3}, 00277 {-2, -3}, 00278 {-2, -2} 00279 }, 00280 }; 00281 00282 00283 /* 00284 ====================================== 00285 Return the type of a block (0 = no-block, 1 = normal block, 2 = pivot block) 00286 00287 Parameters: 00288 00289 >> pPiece: Piece to draw 00290 >> pRotation: 1 of the 4 possible rotations 00291 >> pX: Horizontal position in blocks 00292 >> pY: Vertical position in blocks 00293 ====================================== 00294 */ 00295 int Pieces::GetBlockType (int pPiece, int pRotation, int pX, int pY) 00296 { 00297 return mPieces [pPiece][pRotation][pX][pY]; 00298 } 00299 00300 00301 /* 00302 ====================================== 00303 Returns the horizontal displacement of the piece that has to be applied in order to create it in the 00304 correct position. 00305 00306 Parameters: 00307 00308 >> pPiece: Piece to draw 00309 >> pRotation: 1 of the 4 possible rotations 00310 ====================================== 00311 */ 00312 int Pieces::GetXInitialPosition (int pPiece, int pRotation) 00313 { 00314 return mPiecesInitialPosition [pPiece][pRotation][0]; 00315 } 00316 00317 00318 /* 00319 ====================================== 00320 Returns the vertical displacement of the piece that has to be applied in order to create it in the 00321 correct position. 00322 00323 Parameters: 00324 00325 >> pPiece: Piece to draw 00326 >> pRotation: 1 of the 4 possible rotations 00327 ====================================== 00328 */ 00329 int Pieces::GetYInitialPosition (int pPiece, int pRotation) 00330 { 00331 return mPiecesInitialPosition [pPiece][pRotation][1]; 00332 }
Generated on Thu Jul 14 2022 13:36:47 by 1.7.2