コード例 #1
0
    public IAction SwapFieldObjects(Vector2Int aCell, Vector2Int bCell)
    {
        ActionPack swapAnimationActionPack = GetSwapAnimationActionPack(aCell, bCell);

        fieldMatrix.SwapObjectsInStorage(aCell, bCell);

        return(swapAnimationActionPack);
    }
コード例 #2
0
    private IAction CreateNewFieldObjectsAndFillEmptyCells()
    {
        ActionPack updateActions = new ActionPack();

        for (int i = 0; i < fieldProperties.GetFieldSize().x; i++)
        {
            int emptyCellsCount = 0;
            for (int j = 0; j < fieldProperties.GetFieldSize().y; j++)
            {
                if (fieldMatrix.GetObjectFromStorage(i, j) == null)
                {
                    emptyCellsCount++;
                }
                else if (emptyCellsCount > 0)
                {
                    Vector2Int newCellForCurrentObject = new Vector2Int(i, j - emptyCellsCount);
                    Vector2Int currentCell             = new Vector2Int(i, j);

                    Vector2 newPositionForCurrentObject = fieldProperties.CalculateLocalFieldObjectPosition(newCellForCurrentObject);
                    Vector2 currentPosition             = fieldProperties.CalculateLocalFieldObjectPosition(currentCell);

                    GameObject targetObject = fieldMatrix.GetObjectFromStorage(i, j).GetGameObject();

                    fieldMatrix.SwapObjectsInStorage(currentCell, newCellForCurrentObject);

                    updateActions.AddAction((callback) => { coroutinePlayer.PlayCoroutine(CoroutineAnimations.AcceleratedMovement(targetObject, currentPosition, newPositionForCurrentObject, fieldObjectFallingStartSpeed, fieldObjectFallingVelocity, callback)); });
                }
            }

            for (int j = fieldProperties.GetFieldSize().y - emptyCellsCount; j < fieldProperties.GetFieldSize().y; j++)
            {
                Vector2Int imaginaryCell = new Vector2Int(i, j + emptyCellsCount);
                Vector2Int actualCell    = new Vector2Int(i, j);

                Vector2 positionToCreateObject = fieldProperties.CalculateLocalFieldObjectPosition(imaginaryCell);
                Vector2 positionToMoveObject   = fieldProperties.CalculateLocalFieldObjectPosition(actualCell);

                fieldObjectCreator.CreateFieldObject(actualCell, positionToCreateObject);

                GameObject targetObject = fieldMatrix.GetObjectFromStorage(i, j).GetGameObject();

                updateActions.AddAction((callback) => { coroutinePlayer.PlayCoroutine(CoroutineAnimations.AcceleratedMovement(targetObject, positionToCreateObject, positionToMoveObject, fieldObjectFallingStartSpeed, fieldObjectFallingVelocity, callback)); });
            }
        }

        return(updateActions);
    }