Exemplo n.º 1
0
    private void DropDrag()
    {
        if (SelectedChuzzles.Any())
        {
            //drop shining
            foreach (var chuzzle in Gamefield.Level.ActiveChuzzles)
            {
                chuzzle.Shine = false;
                chuzzle.Teleportable.Hide();
            }

            //move all tiles to new real coordinates
            foreach (var chuzzle in SelectedChuzzles)
            {
                chuzzle.Real = Gamefield.Level.GetCellAt(GamefieldUtility.ToRealCoordinates(chuzzle), false);
            }

            foreach (var c in Gamefield.Level.Chuzzles)
            {
                c.MoveTo = c.Real;
            }

            foreach (var chuzzle in Gamefield.Level.Chuzzles)
            {
                chuzzle.AnimateMoveTo(chuzzle.MoveTo.Position, 0.1f);
            }

            CheckAnimationCompleted();
        }
    }
Exemplo n.º 2
0
    private void MoveChuzzles(List <Cell> activeCells)
    {
        foreach (var c in SelectedChuzzles)
        {
            var copyPosition = c.transform.position;

            var real       = GamefieldUtility.ToRealCoordinates(c);
            var targetCell = GamefieldUtility.CellAt(activeCells, real.x, real.y);

            var difference = c.transform.position - GamefieldUtility.ConvertXYToPosition(real.x, real.y, Chuzzle.Scale);

            var isNeedCopy = false;

            if (targetCell != null && !targetCell.IsTemporary)
            {
                if (!_isVerticalDrag)
                {
                    if (difference.x > 0)
                    {
                        isNeedCopy = targetCell.Right == null ||
                                     (targetCell.Right != null && targetCell.Right.Type != CellTypes.Usual);
                        if (isNeedCopy)
                        {
                            var rightCell = GetRightCell(activeCells, targetCell.Right, c);
                            copyPosition = rightCell.Position + difference - new Vector3(Chuzzle.Scale.x, 0, 0);
                        }
                    }
                    else
                    {
                        isNeedCopy = targetCell.Left == null ||
                                     (targetCell.Left != null && targetCell.Left.Type != CellTypes.Usual);
                        if (isNeedCopy)
                        {
                            var leftCell = GetLeftCell(activeCells, targetCell.Left, c);
                            copyPosition = leftCell.Position + difference + new Vector3(Chuzzle.Scale.x, 0, 0);
                        }
                    }
                }
                else
                {
                    if (difference.y > 0)
                    {
                        isNeedCopy = targetCell.Top == null ||
                                     (targetCell.Top != null &&
                                      (targetCell.Top.Type == CellTypes.Block || targetCell.Top.IsTemporary));
                        if (isNeedCopy)
                        {
                            var topCell = GetTopCell(activeCells, targetCell.Top, c);
                            copyPosition = topCell.Position + difference - new Vector3(0, Chuzzle.Scale.y, 0);
                        }
                    }
                    else
                    {
                        isNeedCopy = targetCell.Bottom == null ||
                                     (targetCell.Bottom != null && targetCell.Bottom.Type == CellTypes.Block);
                        if (isNeedCopy)
                        {
                            var bottomCell = GetBottomCell(activeCells, targetCell.Bottom, c);
                            copyPosition = bottomCell.Position + difference + new Vector3(0, Chuzzle.Scale.y, 0);
                        }
                    }
                }
            }
            else
            {
                isNeedCopy = true;
            }

            if (targetCell == null || targetCell.Type == CellTypes.Block || targetCell.IsTemporary)
            {
                switch (CurrentDirection)
                {
                case Direction.Left:
                    //if border
                    targetCell = GetLeftCell(activeCells, targetCell, c);
                    break;

                case Direction.Right:
                    targetCell = GetRightCell(activeCells, targetCell, c);
                    break;

                case Direction.Top:
                    //if border
                    targetCell = GetTopCell(activeCells, targetCell, c);
                    break;

                case Direction.Bottom:
                    targetCell = GetBottomCell(activeCells, targetCell, c);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("Current direction can not be shit");
                }

                c.transform.position = targetCell.Position + difference;

                // Debug.Log("New coord: "+GamefieldUtility.ToRealCoordinates(c)+" for "+c.gameObject.name + " pos: "+c.transform.position);
            }

            if (difference.magnitude < (Chuzzle.Scale.x / 25))
            {
                isNeedCopy = false;
            }

            if (isNeedCopy)
            {
                c.Teleportable.Show();
                c.Teleportable.Copy.transform.position = copyPosition;
            }
            else
            {
                c.Teleportable.Hide();
            }
        }
    }