public Tuple <int, int> canRotate(TetrisGrid grid, bool clockwise) { byte v; bool passing = true; int target; if (clockwise) { target = (Rotation + 1) % 4; } else { if (Rotation - 1 < 0) { target = 3; } else { target = Rotation - 1; } } BlockTester tester = new BlockTester(0, 0, (float)Tetrimino.Size.Width, (float)Tetrimino.Size.Height); foreach (Tuple <int, int> kick in TetriminoKicks[Util.rotation_id(target, clockwise)]) { passing = true; for (int i = 0; i < TetriminoLayout.GetLength(1); i++) { for (int j = 0; j < TetriminoLayout.GetLength(2); j++) { v = TetriminoLayout[target, i, j]; if (v == 0) { continue; } tester.X = i * ((float)Tetrimino.Size.Width) + (kick.Item1 * (float)Tetrimino.Size.Width) + this.x(); tester.Y = j * ((float)Tetrimino.Size.Height) + (kick.Item2 * (float)Tetrimino.Size.Height) + this.y(); if (grid.isCollision(tester)) { passing = false; break; } } if (passing == false) { break; } } if (passing == true) { return(kick); } } return(null); }
public void layoutTetriminos(Tuple <int, int> offset = null) { byte v; int current = 0; float offX = (offset != null ? offset.Item1 * (float)Tetrimino.Size.Width : 0); float offY = (offset != null ? offset.Item2 * (float)Tetrimino.Size.Height : 0); this.X += offX; this.Y += offY; int firstX = -1, lastX = -1, firstY = -1, lastY = -1; Tuple <int, int>[] coords = new Tuple <int, int> [4]; for (int i = 0; i < TetriminoLayout.GetLength(1); i++) { for (int j = 0; j < TetriminoLayout.GetLength(2); j++) { v = TetriminoLayout[Rotation, i, j]; if (v == 0) { continue; } Tetriminos[current].X = i * ((float)Tetrimino.Size.Width); Tetriminos[current].Y = j * ((float)Tetrimino.Size.Height); current += 1; firstX = (firstX == -1 || i < firstX ? i : firstX); firstY = (firstY == -1 || j < firstY ? j : firstY); lastX = (lastX == -1 || i > lastX ? i : lastX); lastY = (lastY == -1 || j > firstY ? j : lastY); } } Width = (float)((lastX - firstX + 1) * Tetrimino.Size.Width); Height = (float)((lastY - firstY + 1) * Tetrimino.Size.Height); offsetX = (float)(firstX * Tetrimino.Size.Width); offsetY = (float)(firstY * Tetrimino.Size.Height); }