Guest User

Tetrion

a guest
Mar 25th, 2018
140
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rotation explained for O piece:
  2.  
  3. case k_TetStandardPieces_PieceID_O:
  4. piece = new TetPiece(p_PieceID,4,CreateNewRotationDef(p_PieceID),null);
  5. Create4Minos(piece,pIsSticky,0,0,1,0,0,1,1,1);
  6.  
  7. this part defines the minos
  8. (x0,y0) , (x1,y1) , (x2,y2) , (x3,y3)
  9. ( 0, 0) , ( 1, 0) , ( 0, 1) , ( 1, 1)
  10.  
  11. the bigger y, the more the mino is located towards the top
  12. so the O piece is per default (state=0) located in the top right corner of the origin
  13.  
  14. pieces are always turned around the origin, in clockwise direction it's:
  15. xNew = y
  16. yNew = -x
  17. ( 0, 0) , ( 0,-1) , ( 1, 0) , ( 1,-1)
  18. so after clockwise rotation (state=1), O piece is located in bottom right corner of the origin
  19.  
  20. if you rotate again in clockwise rotation, then you get
  21. (0 , 0) , (-1, 0) , ( 0,-1) , (-1,-1)
  22. so after rotating twice (state=2), O piece is located in bottom left corner of the origin
  23.  
  24. and a third time:
  25. (0 , 0) , ( 0, 1) , (-1, 0) , (-1, 1)
  26. so after rotating three times (state=3), O piece is located in top left corner of the origin
  27. it's the same as if you would have rotated the original coordinates in counterclockwise direction:
  28. xNew = -y
  29. yNew = x
  30.  
  31. case k_TetStandardPieces_PieceID_O:
  32. rotationDef.AddRotationPoint(0,0,0,-1,-1,-1,-1,0);
  33.  
  34. this part defines the kicks / rotation offsets
  35. (x0,y0) , (x1,y1) , (x2,y2) , (x3,y3)
  36. ( 0, 0) , ( 0,-1) , (-1,-1) , (-1, 0)
  37. (x0,y0) represent the offsets in state 0 (initial orientation)
  38. (x1,y1) represent the offsets in state 1 (orientation after clockwise rotation)
  39. (x2,y2) represent the offsets in state 2 (orientation after 180 degree rotation)
  40. (x3,y3) represent the offsets in state 3 (orientation after counterclockwise rotation)
  41.  
  42. when rotating from state 0 to 1, the game will kick the O piece's center by
  43. (x0 - x1, y0 - y1) = (0, 1)
  44. that means the piece is kicked one row upwards
  45. this basically negates the change of the minos' positions (top right -> bottom right)
  46.  
  47. when rotating from state 1 to 2, the game will kick the O piece's center by
  48. (x1 - x2, y1 - y2) = (1, 0)
  49. that means the piece is kicked one column to the right
  50. this basically negates the change of the minos' positions (bottom right -> bottom left)
  51.  
  52. when rotating from state 2 to 3, the game will kick the O piece's center by
  53. (x2 - x3, y2 - y3) = (0,-1)
  54. that means the piece is kicked one row downwards
  55. this basically negates the change of the minos' positions (bottom left -> top left)
  56.  
  57. so the O piece always stays in its place despite of
  58.  
  59. Other pieces have more than 1 rotation point. For example the T,L,J,S,Z pieces' first rotation point only consists of 0s, which means the center of those pieces is not changed during rotation. However, if the base rotation fails, the game will try a non-0 rotation point which represent the first kick for each rotation. If the second rotation point also fails, then the game will try the third rotation point (which represents the second kick for each rotation), and so on.
  60.  
  61. code for the Flash games that were part of Tetris Online Poland. Games at Tetris Friends should have the same code but it is obfuscated:
  62.  
  63. public class TetStandardPieces
  64. {
  65.  
  66. public static const k_TetStandardPieces_PieceID_3I:int = 7;
  67. public static const k_TetStandardPieces_PieceID_3J:int = 8;
  68. public static const k_TetStandardPieces_PieceID_3L:int = 9;
  69. public static const k_TetStandardPieces_PieceID_I:int = 4;
  70. public static const k_TetStandardPieces_PieceID_J:int = 5;
  71. public static const k_TetStandardPieces_PieceID_L:int = 1;
  72. public static const k_TetStandardPieces_PieceID_O:int = 2;
  73. public static const k_TetStandardPieces_PieceID_S:int = 3;
  74. public static const k_TetStandardPieces_PieceID_T:int = 6;
  75. public static const k_TetStandardPieces_PieceID_2I:int = 10;
  76. public static const k_TetStandardPieces_PieceID_Z:int = 0;
  77. public static const k_TetStandardPiecesNumPieceIDs:int = 7;
  78.  
  79. private static function Create2Minos(p_Piece:TetPiece, pIsSticky:Boolean, p_Mino0_X:int, p_Mino0_Y:int, p_Mino1_X:int, p_Mino1_Y:int) : void
  80. {
  81. p_Piece.AddMino(new TetMino(p_Piece.GetPieceTypeID(),pIsSticky,null),p_Mino0_X,p_Mino0_Y);
  82. p_Piece.AddMino(new TetMino(p_Piece.GetPieceTypeID(),pIsSticky,null),p_Mino1_X,p_Mino1_Y);
  83. }
  84.  
  85. private static function Create4Minos(p_Piece:TetPiece, pIsSticky:Boolean, p_Mino0_X:int, p_Mino0_Y:int, p_Mino1_X:int, p_Mino1_Y:int, p_Mino2_X:int, p_Mino2_Y:int, p_Mino3_X:int, p_Mino3_Y:int) : void
  86. {
  87. p_Piece.AddMino(new TetMino(p_Piece.GetPieceTypeID(),pIsSticky,null),p_Mino0_X,p_Mino0_Y);
  88. p_Piece.AddMino(new TetMino(p_Piece.GetPieceTypeID(),pIsSticky,null),p_Mino1_X,p_Mino1_Y);
  89. p_Piece.AddMino(new TetMino(p_Piece.GetPieceTypeID(),pIsSticky,null),p_Mino2_X,p_Mino2_Y);
  90. p_Piece.AddMino(new TetMino(p_Piece.GetPieceTypeID(),pIsSticky,null),p_Mino3_X,p_Mino3_Y);
  91. }
  92.  
  93. private static function Create3Minos(p_Piece:TetPiece, pIsSticky:Boolean, p_Mino0_X:int, p_Mino0_Y:int, p_Mino1_X:int, p_Mino1_Y:int, p_Mino2_X:int, p_Mino2_Y:int) : void
  94. {
  95. p_Piece.AddMino(new TetMino(p_Piece.GetPieceTypeID(),pIsSticky,null),p_Mino0_X,p_Mino0_Y);
  96. p_Piece.AddMino(new TetMino(p_Piece.GetPieceTypeID(),pIsSticky,null),p_Mino1_X,p_Mino1_Y);
  97. p_Piece.AddMino(new TetMino(p_Piece.GetPieceTypeID(),pIsSticky,null),p_Mino2_X,p_Mino2_Y);
  98. }
  99.  
  100. private static function CreateNewRotationDef(p_PieceID:int) : TetSuperRotationDef
  101. {
  102. var rotationDef:TetSuperRotationDef = new TetSuperRotationDef(null);
  103. switch(p_PieceID)
  104. {
  105. case k_TetStandardPieces_PieceID_S:
  106. case k_TetStandardPieces_PieceID_Z:
  107. case k_TetStandardPieces_PieceID_J:
  108. case k_TetStandardPieces_PieceID_L:
  109. case k_TetStandardPieces_PieceID_T:
  110. rotationDef.AddRotationPoint(0,0,0,0,0,0,0,0);
  111. rotationDef.AddRotationPoint(0,0,1,0,0,0,-1,0);
  112. rotationDef.AddRotationPoint(0,0,1,-1,0,0,-1,-1);
  113. rotationDef.AddRotationPoint(0,0,0,2,0,0,0,2);
  114. rotationDef.AddRotationPoint(0,0,1,2,0,0,-1,2);
  115. break;
  116. case k_TetStandardPieces_PieceID_O:
  117. rotationDef.AddRotationPoint(0,0,0,-1,-1,-1,-1,0);
  118. break;
  119. case k_TetStandardPieces_PieceID_I:
  120. rotationDef.AddRotationPoint(0,0,-1,0,-1,1,0,1);
  121. rotationDef.AddRotationPoint(-1,0,0,0,1,1,0,1);
  122. rotationDef.AddRotationPoint(2,0,0,0,-2,1,0,1);
  123. rotationDef.AddRotationPoint(-1,0,0,1,1,0,0,-1);
  124. rotationDef.AddRotationPoint(2,0,0,-2,-2,0,0,2);
  125. break;
  126. case k_TetStandardPieces_PieceID_3L:
  127. rotationDef.AddRotationPoint(0,0,0,-1,-1,-1,-1,0);
  128. rotationDef.AddRotationPoint(0,0,1,-1,0,-2,-1,-1);
  129. rotationDef.AddRotationPoint(1,-1,0,-2,-1,-1,0,0);
  130. break;
  131. case k_TetStandardPieces_PieceID_3J:
  132. rotationDef.AddRotationPoint(0,0,1,0,1,-1,0,-1);
  133. rotationDef.AddRotationPoint(0,0,1,-1,0,-2,-1,-1);
  134. rotationDef.AddRotationPoint(-1,-1,0,0,1,-1,0,-2);
  135. break;
  136. case k_TetStandardPieces_PieceID_3I:
  137. rotationDef.AddRotationPoint(0,0,0,0,0,0,0,0);
  138. rotationDef.AddRotationPoint(1,0,0,0,-1,0,0,0);
  139. rotationDef.AddRotationPoint(-1,0,0,0,1,0,0,0);
  140. rotationDef.AddRotationPoint(0,0,0,1,0,-1,0,0);
  141. rotationDef.AddRotationPoint(0,0,0,-1,0,1,0,0);
  142. break;
  143. case k_TetStandardPieces_PieceID_2I:
  144. rotationDef.AddRotationPoint(0,0,-1,0,-1,1,0,1);
  145. rotationDef.AddRotationPoint(0,0,-1,-1,-2,0,-1,1);
  146. rotationDef.AddRotationPoint(0,0,0,0,0,0,0,0);
  147. rotationDef.AddRotationPoint(0,0,0,-1,-1,0,-1,-1);
  148. }
  149. return rotationDef;
  150. }
  151.  
  152. public static function CreateNewPiece(p_PieceID:int, pIsSticky:Boolean = false) : TetPiece
  153. {
  154. var piece:TetPiece = null;
  155. switch(p_PieceID)
  156. {
  157. case k_TetStandardPieces_PieceID_S:
  158. piece = new TetPiece(p_PieceID,4,CreateNewRotationDef(p_PieceID),null);
  159. Create4Minos(piece,pIsSticky,0,0,0,1,-1,0,1,1);
  160. break;
  161. case k_TetStandardPieces_PieceID_Z:
  162. piece = new TetPiece(p_PieceID,4,CreateNewRotationDef(p_PieceID),null);
  163. Create4Minos(piece,pIsSticky,0,0,0,1,1,0,-1,1);
  164. break;
  165. case k_TetStandardPieces_PieceID_J:
  166. piece = new TetPiece(p_PieceID,4,CreateNewRotationDef(p_PieceID),null);
  167. Create4Minos(piece,pIsSticky,0,0,-1,0,1,0,-1,1);
  168. break;
  169. case k_TetStandardPieces_PieceID_L:
  170. piece = new TetPiece(p_PieceID,4,CreateNewRotationDef(p_PieceID),null);
  171. Create4Minos(piece,pIsSticky,0,0,1,0,-1,0,1,1);
  172. break;
  173. case k_TetStandardPieces_PieceID_T:
  174. piece = new TetPiece(p_PieceID,4,CreateNewRotationDef(p_PieceID),null);
  175. Create4Minos(piece,pIsSticky,0,0,0,1,-1,0,1,0);
  176. break;
  177. case k_TetStandardPieces_PieceID_O:
  178. piece = new TetPiece(p_PieceID,4,CreateNewRotationDef(p_PieceID),null);
  179. Create4Minos(piece,pIsSticky,0,0,1,0,0,1,1,1);
  180. break;
  181. case k_TetStandardPieces_PieceID_I:
  182. piece = new TetPiece(p_PieceID,4,CreateNewRotationDef(p_PieceID),null);
  183. Create4Minos(piece,pIsSticky,0,0,1,0,2,0,-1,0);
  184. break;
  185. case k_TetStandardPieces_PieceID_3I:
  186. piece = new TetPiece(p_PieceID,3,CreateNewRotationDef(p_PieceID),null);
  187. Create3Minos(piece,pIsSticky,0,0,1,0,-1,0);
  188. break;
  189. case k_TetStandardPieces_PieceID_3J:
  190. piece = new TetPiece(p_PieceID,3,CreateNewRotationDef(p_PieceID),null);
  191. Create3Minos(piece,pIsSticky,0,0,0,1,-1,0);
  192. break;
  193. case k_TetStandardPieces_PieceID_3L:
  194. piece = new TetPiece(p_PieceID,3,CreateNewRotationDef(p_PieceID),null);
  195. Create3Minos(piece,pIsSticky,0,0,0,1,1,0);
  196. break;
  197. case k_TetStandardPieces_PieceID_2I:
  198. piece = new TetPiece(p_PieceID,2,CreateNewRotationDef(p_PieceID),null);
  199. Create2Minos(piece,pIsSticky,0,0,1,0);
  200. }
  201. return piece;
  202. }
  203. }
  204.  
  205. public class TetSuperRotationDef extends TetObject
  206. {
  207.  
  208. private static const k_TetMaxNumRotationPoints:int = 5;
  209. private var m_RotationPoints:Array;
  210. private var m_NumRotationPoints:int;
  211.  
  212. public function TetSuperRotationDef(p_RotationDefToCopy:TetSuperRotationDef)
  213. {
  214. super();
  215. m_RotationPoints = new Array(TetMatrix2D.k_TetNumFacings * k_TetMaxNumRotationPoints);
  216. var point:int = 0;
  217. var facing:int = 0;
  218. var index:int = 0;
  219. if(p_RotationDefToCopy == null)
  220. {
  221. m_NumRotationPoints = 0;
  222. for(point = 0; point < k_TetMaxNumRotationPoints; point++)
  223. {
  224. for(facing = 0; facing < TetMatrix2D.k_TetNumFacings; facing++)
  225. {
  226. m_RotationPoints[index] = null;
  227. index++;
  228. }
  229. }
  230. }
  231. else
  232. {
  233. m_NumRotationPoints = p_RotationDefToCopy.GetNumRotationPoints();
  234. for(point = 0; point < m_NumRotationPoints; point++)
  235. {
  236. for(facing = 0; facing < TetMatrix2D.k_TetNumFacings; facing++)
  237. {
  238. m_RotationPoints[index] = new TetVector2D(0,0,p_RotationDefToCopy.m_RotationPoints[index]);
  239. index++;
  240. }
  241. }
  242. }
  243. }
  244.  
  245. public function GetNumRotationPoints() : int
  246. {
  247. return m_NumRotationPoints;
  248. }
  249.  
  250. public function AddRotationPoint(p_FacingN_X:int, p_FacingN_Y:int, p_FacingE_X:int, p_FacingE_Y:int, p_FacingS_X:int, p_FacingS_Y:int, p_FacingW_X:int, p_FacingW_Y:int) : void
  251. {
  252. if(m_NumRotationPoints >= k_TetMaxNumRotationPoints)
  253. {
  254. return;
  255. }
  256. var facingIndex:int = m_NumRotationPoints * TetMatrix2D.k_TetNumFacings;
  257. m_RotationPoints[facingIndex] = null;
  258. m_RotationPoints[facingIndex] = new TetVector2D(p_FacingN_X,p_FacingN_Y,null);
  259. facingIndex++;
  260. m_RotationPoints[facingIndex] = null;
  261. m_RotationPoints[facingIndex] = new TetVector2D(p_FacingE_X,p_FacingE_Y,null);
  262. facingIndex++;
  263. m_RotationPoints[facingIndex] = null;
  264. m_RotationPoints[facingIndex] = new TetVector2D(p_FacingS_X,p_FacingS_Y,null);
  265. facingIndex++;
  266. m_RotationPoints[facingIndex] = null;
  267. m_RotationPoints[facingIndex] = new TetVector2D(p_FacingW_X,p_FacingW_Y,null);
  268. m_NumRotationPoints++;
  269. }
  270. }
RAW Paste Data