Exemple #1
0
    //команда движения игрока в указаном направлении
    //dir - направление движения
    public void Move(MoveDirection dir)
    {
        CellScript    targetCell;
        MoveDirection targetDir;

        if (dir == MoveDirection.Left)
        {
            targetCell = currCell.leftNeighbor;
            targetDir  = MoveDirection.Left;
        }
        else
        {
            targetCell = currCell.rightNeighbor;
            targetDir  = MoveDirection.Right;
        }
        if (moving)
        {
            //если во время прыжка поступит команда движение , то игрок сместится влево после прыжка
            if (currMove == MoveType.Jump && targetCell != null)
            {
                nextMove = MoveType.Move;
                nextDir  = targetDir;
            }
            //если во время движения поступила команда прыжка а затем команда движения, то прыжок отменится
            else if (nextMove == MoveType.Jump)
            {
                nextMove = MoveType.Stay;
            }
        }
        else if (targetCell != null)
        {
            if (targetCell.cellObject == null)
            {
                StartMove(targetCell);
            }
            else //попытка толкнуть ящик
            {
                BoxScript box = targetCell.cellObject as BoxScript;
                if (box != null)
                {
                    if (box.TryPush(targetDir, moveSpeed))
                    {
                        StartMove(targetCell);
                    }
                }
                else
                {
                    throw new UnityException("Непредвиденный тип объекта в клетке");
                }
            }
        }
    }