protected void RotateLayer(Cube cube, RotationSense rotationSense, PickType pickType, int index) { FacePosition currentFacePosition = FacePosition.Front; FacePosition nextFacePosition = currentFacePosition.Rotate(rotationSense, pickType); Face curFaceF = cube.GetFaceByPosition(currentFacePosition); Face curFaceU = cube.GetFaceByPosition(nextFacePosition); List <Color> oldColors = curFaceU.GetPiecesColorRange(pickType, index); List <Color> newColors = curFaceF.GetPiecesColorRange(pickType, index); FacePosition endPosition = GetEndingRotation(rotationSense, pickType); do { curFaceU.ChangeColorRange(pickType, index, newColors); newColors.Clear(); newColors.AddRange(oldColors); currentFacePosition = nextFacePosition; nextFacePosition = nextFacePosition.Rotate(rotationSense, pickType); curFaceF = cube.GetFaceByPosition(currentFacePosition); curFaceU = cube.GetFaceByPosition(nextFacePosition); oldColors.Clear(); oldColors.AddRange(curFaceU.GetPiecesColorRange(pickType, index)); } while (nextFacePosition != endPosition); }
public SimulationStep UseTool(Tool tool, Vector2Int gridPos, RotationSense rotSense = RotationSense.CW) { switch (tool) { case Tool.SwapTiles: case Tool.SwapLines: throw new ArgumentOutOfRangeException(nameof(tool)); } if (availableToolUses[tool] == 0) { throw new InvalidOperationException("No tool uses available."); } SimulationStep step = null; switch (tool) { case Tool.ToggleMarked: step = simulator.TogglePrediction(gridPos); break; case Tool.RemoveTile: step = simulator.RemoveTile(gridPos); break; case Tool.RefillInert: step = simulator.RefillTile(gridPos); break; case Tool.Bomb: step = simulator.RemoveBlock(gridPos); break; case Tool.PlusBomb: step = simulator.RemovePlus(gridPos); break; case Tool.RemoveRow: step = simulator.RemoveRow(gridPos.y); break; case Tool.RemoveColor: step = simulator.RemoveColor(gridPos); break; case Tool.Rotate3x3: step = simulator.Rotate3x3Block(gridPos, rotSense); break; case Tool.CreateWildcard: step = simulator.CreateWildcard(gridPos); break; } if (availableToolUses[tool] > 0) { --availableToolUses[tool]; } if (tool != Tool.ToggleMarked) { toolUsedThisTurn = true; } return(step); }
private void Update() { // HACK! if (BoardManipulator.ActiveTool != Tool) { RotationSense = RotationSense.CCW; UpdateRotationSenseIndicator(); } }
protected void RotateAdjacentSide(Cube cube, RotationSense rotationSense, PickType pickType, int index) { if (index == 2) { return; } Face adjacentFace = cube.GetFaceByPosition(GetAdjacentFace(pickType, index)); RotateMiddlePieces(adjacentFace, rotationSense); RotateCornerPieces(adjacentFace, rotationSense); }
protected FacePosition GetEndingRotation(RotationSense rotationSense, PickType pickType) { switch (pickType) { case PickType.Horizontal: return(rotationSense == RotationSense.Clockwise ? FacePosition.Left : FacePosition.Right); case PickType.Vertical: return(rotationSense == RotationSense.Clockwise ? FacePosition.Up : FacePosition.Down); } return(default(FacePosition)); }
public static FacePosition Rotate(this FacePosition face, RotationSense rotationSense, PickType pickType) { switch (rotationSense) { case RotationSense.Clockwise: return(RotateClockwise(face, pickType)); case RotationSense.Counterclockwise: return(RotateAnticlockwise(face, pickType)); default: return(face); } }
public override void OnClick() { SoundManager.Instance.PlayEffect(SoundEffect.ToolSelected); if (BoardManipulator.ActiveTool == Tool) { RotationSense = RotationSense.Other(); UpdateRotationSenseIndicator(); } if (RotationSense == RotationSense.CCW) { BoardManipulator.ToggleTool(Tool); } }
public RotationStep Rotate3x3Block(Vector2Int pivot, RotationSense rotSense) { if (!board.IsInBounds(pivot - Vector2Int.one) || !board.IsInBounds(pivot + Vector2Int.one)) { throw new InvalidOperationException("3x3 block partially or fully out of bounds"); } var movedTiles = new List <MovedTile>(); List <Tile> tiles = board.GetRows(HorizontalOrder.LeftToRight, VerticalOrder.BottomToTop) .Skip(pivot.y - 1) .Take(3) .SelectMany(row => row.Skip(pivot.x - 1).Take(3)) .ToList(); HorizontalOrder horizontalOrder = rotSense == RotationSense.CW ? HorizontalOrder.LeftToRight : HorizontalOrder.RightToLeft; VerticalOrder verticalOrder = rotSense == RotationSense.CW ? VerticalOrder.TopToBottom : VerticalOrder.BottomToTop; int i = 0; foreach (int x in board.GetXs(horizontalOrder)) { foreach (int y in board.GetYs(verticalOrder)) { if (x < pivot.x - 1 || x > pivot.x + 1 || y < pivot.y - 1 || y > pivot.y + 1) { continue; } Tile tile = tiles[i]; if (tile.Position != new Vector2Int(x, y)) { movedTiles.Add(board.MoveTile(tile, x, y)); } ++i; } } CheckWhetherReactionIsAllowed(); return(new RotationStep(pivot, rotSense, movedTiles)); }
public RotationStep Rotate2x2Block(Vector2Int bottomLeft, RotationSense rotSense) { if (!board.IsInBounds(bottomLeft) || !board.IsInBounds(bottomLeft + Vector2Int.one)) { throw new InvalidOperationException("2x2 block partially or fully out of bounds"); } var movedTiles = new List <MovedTile>(); List <Tile> tiles = board.GetRows(HorizontalOrder.LeftToRight, VerticalOrder.BottomToTop) .Skip(bottomLeft.y) .Take(2) .SelectMany(row => row.Skip(bottomLeft.x).Take(2)) .ToList(); HorizontalOrder horizontalOrder = rotSense == RotationSense.CW ? HorizontalOrder.LeftToRight : HorizontalOrder.RightToLeft; VerticalOrder verticalOrder = rotSense == RotationSense.CW ? VerticalOrder.TopToBottom : VerticalOrder.BottomToTop; int i = 0; foreach (int x in board.GetXs(horizontalOrder)) { foreach (int y in board.GetYs(verticalOrder)) { if (x < bottomLeft.x || x > bottomLeft.x + 1 || y < bottomLeft.y || y > bottomLeft.y + 1) { continue; } movedTiles.Add(board.MoveTile(tiles[i], x, y)); ++i; } } CheckWhetherReactionIsAllowed(); Vector2 pivot = bottomLeft + 0.5f * Vector2.one; return(new RotationStep(pivot, rotSense, movedTiles)); }
public RotationStep RotateBoard(RotationSense rotSense) { var movedTiles = new List <MovedTile>(); List <Tile> tiles = board.GetRows(HorizontalOrder.LeftToRight, VerticalOrder.BottomToTop).SelectMany(x => x).ToList(); HorizontalOrder horizontalOrder = rotSense == RotationSense.CW ? HorizontalOrder.LeftToRight : HorizontalOrder.RightToLeft; VerticalOrder verticalOrder = rotSense == RotationSense.CW ? VerticalOrder.TopToBottom : VerticalOrder.BottomToTop; int i = 0; foreach (int x in board.GetXs(horizontalOrder)) { foreach (int y in board.GetYs(verticalOrder)) { Tile tile = tiles[i]; if (tile.Position != new Vector2Int(x, y)) { movedTiles.Add(board.MoveTile(tile, x, y)); } ++i; } } CheckWhetherReactionIsAllowed(); Vector2 pivot = new Vector2(board.Width - 1, board.Height - 1) / 2f; return(new RotationStep(pivot, rotSense, movedTiles)); }
public void Rotate(Cube cube, RotationSense rotationSense, PickType pickType, int index) { RotateLayer(cube, rotationSense, pickType, index); RotateAdjacentSide(cube, rotationSense, pickType, index); }
protected void RotateCornerPieces(Face face, RotationSense rotationSense) { }
protected void RotateMiddlePieces(Face face, RotationSense rotationSense) { }
private async Task AnimateRotatingTilesAsync(List <MovedTile> movedTiles, Vector2 pivot, RotationSense rotSense) { Sequence seq = DOTween.Sequence(); foreach (MovedTile movedTile in movedTiles) { Tile tile = movedTile.Tile; TileRenderer tileRenderer = tileDictionary[tile.ID]; seq.Insert(0, tileRenderer.RotateToCurrentPosition(movedTile.From, pivot, rotSense)); } await seq.Completion(); await new WaitForSeconds(postFallDelay); }
public static RotationSense Other(this RotationSense rotSense) => rotSense == RotationSense.CW ? RotationSense.CCW : RotationSense.CW;
public RotationStep(Vector2 pivot, RotationSense rotationSense, List <MovedTile> movedTiles) { Pivot = pivot; RotationSense = rotationSense; MovedTiles = movedTiles; }
public Tween RotateToCurrentPosition(Vector2Int from, Vector2 pivot, RotationSense rotSense) { SoundManager.Instance.PlayEffect(SoundEffect.VialShifted); Sequence seq = DOTween.Sequence(); #region Direct rotation //seq.Append(transform // //.DOLocalMove((Vector3Int)tile.Position, Mathf.Sqrt(2f * (from - tile.Position).magnitude / fallingSpeed)) // .DOLocalMove((Vector3Int)tile.Position, 1f) // .SetEase(Ease.InOutQuad)); #endregion #region Manhattan rotation //Vector2Int to = tile.Position; //Vector2Int corner = Vector2Int.zero; //int cornerDistance = 0; //int fullDistance = 0; //if (rotSense == RotationSense.CW) //{ // // bottom to left // if (to.x <= from.x && to.y >= from.y) // { // corner = new Vector2Int(to.x, from.y); // cornerDistance = from.x - to.x; // fullDistance = cornerDistance + to.y - from.y; // } // // left to top // else if (to.x >= from.x && to.y >= from.y) // { // corner = new Vector2Int(from.x, to.y); // cornerDistance = to.y - from.y; // fullDistance = cornerDistance + to.x - from.x; // } // // top to right // else if (to.x >= from.x && to.y <= from.y) // { // corner = new Vector2Int(to.x, from.y); // cornerDistance = to.x - from.x; // fullDistance = cornerDistance + from.y - to.y; // } // // right to bottom // else // { // corner = new Vector2Int(from.x, to.y); // cornerDistance = from.y - to.y; // fullDistance = cornerDistance + from.x - to.x; // } //} //else //{ // // right to top // if (to.x <= from.x && to.y >= from.y) // { // corner = new Vector2Int(from.x, to.y); // cornerDistance = to.y - from.y; // fullDistance = cornerDistance + from.x - to.x; // } // // bottom to right // else if (to.x >= from.x && to.y >= from.y) // { // corner = new Vector2Int(to.x, from.y); // cornerDistance = to.x - from.x; // fullDistance = cornerDistance + to.y - from.y; // } // // left to bottom // else if (to.x >= from.x && to.y <= from.y) // { // corner = new Vector2Int(from.x, to.y); // cornerDistance = from.y - to.y; // fullDistance = cornerDistance + to.x - from.x; // } // // top to left // else // { // corner = new Vector2Int(to.x, from.y); // cornerDistance = from.x - to.x; // fullDistance = cornerDistance + from.y - to.y; // } //} //seq.Append(transform // //.DOLocalPath(new Vector3[] { (Vector2)corner, (Vector2)to }, 1f, PathType.Linear, PathMode.Ignore) // //.DOLocalPath(new Vector3[] { (Vector2)corner, (Vector2)to }, Mathf.Sqrt(2f * fullDistance / fallingSpeed), PathType.Linear, PathMode.Ignore) // .DOLocalPath(new Vector3[] { (Vector2)corner, (Vector2)to }, 2f * fullDistance / fallingSpeed, PathType.Linear, PathMode.Ignore) // .SetEase(Ease.Linear)); #endregion #region Arc rotation Transform originalParent = transform.parent; Transform parent = new GameObject().transform; parent.parent = originalParent; parent.localPosition = pivot; transform.parent = parent; float targetAngle = Vector2.SignedAngle(from - pivot, tile.Position - pivot); seq.Join(parent.DOLocalRotate(new Vector3(0, 0, targetAngle), 1f).SetEase(Ease.InOutQuad)); seq.Join(transform.DOLocalRotate(new Vector3(0, 0, -targetAngle), 1f).SetEase(Ease.InOutQuad)); seq.AppendCallback(() => { transform.parent = originalParent; transform.localRotation = Quaternion.identity; }); #endregion return(seq); }