Exemplo n.º 1
0
    public void StartRotation(EnumAxis axis, EnumAnimType animType, EnumDirection direction, int nslice = 0, float speed = 300f)
    {
        rotationAxis      = axis;
        animationType     = animType;
        rotationDirection = direction;
        slice             = nslice;
        rotationSpeed     = speed;

        if (gameState == EnumGameState.playing)
        {
            History.Push(new Move {
                Axis      = axis,
                Type      = animationType,
                Direction = rotationDirection,
                Slice     = slice
            });
        }

        DoRotate();
    }
Exemplo n.º 2
0
    public void Undo()
    {
        if (state == EnumCubeAnimState.animating)
        {
            return;
        }
        if (History.Count == 0)
        {
            return;
        }

        var move = History.Pop();

        rotationAxis      = move.Axis;
        animationType     = move.Type;
        rotationDirection = move.Direction == EnumDirection.positive ? EnumDirection.negative : EnumDirection.positive;
        slice             = move.Slice.GetValueOrDefault();
        rotationSpeed     = 300f;

        DoRotate();
    }
Exemplo n.º 3
0
    private void ProcessTouch()
    {
        // did not touch enough faces
        if (touchList.Count <= 1)
        {
            touchList.Clear();
            print("did not touch enough faces");
            return;
        }

        var axisTouched = touchList[0].name.Substring(4, 1);

        List <GameObject> facesOnSameAxis = touchList.Where(f => f.name.Contains(axisTouched)).ToList();

        // Did not touch enough faces on same axis
        if (facesOnSameAxis.Count == 1)
        {
            touchList.Clear();
            print("Did not touch enough faces on same axis");
            return;
        }

        var firstFace    = facesOnSameAxis.FirstOrDefault();
        var firstFaceRow = int.Parse(firstFace.name.Substring(5, 1));
        var firstFaceCol = int.Parse(firstFace.name.Substring(6, 1));

        var lastFace    = facesOnSameAxis.LastOrDefault();
        var lastFaceRow = int.Parse(lastFace.name.Substring(5, 1));
        var lastFaceCol = int.Parse(lastFace.name.Substring(6, 1));

        // Can't determine slice touched
        if (firstFaceCol != lastFaceCol && firstFaceRow != lastFaceRow)
        {
            touchList.Clear();
            print("Cannot determine slice touched");
            return;
        }

        EnumAxis      axis      = EnumAxis.z; // remove default;
        int           slice     = 0;
        EnumDirection direction = EnumDirection.positive;
        EnumAnimType  animType  = EnumAnimType.slice;

        switch (axisTouched)
        {
        case "X":
            if (firstFaceRow == lastFaceRow)
            {
                axis      = EnumAxis.y;
                slice     = firstFaceRow;
                direction = firstFaceCol > lastFaceCol ? EnumDirection.negative : EnumDirection.positive;
                animType  = firstFaceRow == 1 ? EnumAnimType.cube : EnumAnimType.slice;
            }
            else
            {
                axis      = EnumAxis.z;
                slice     = firstFaceCol;
                direction = firstFaceRow > lastFaceRow ? EnumDirection.negative : EnumDirection.positive;
                animType  = firstFaceCol == 1 ? EnumAnimType.cube : EnumAnimType.slice;
            }
            break;

        case "Y":
            if (firstFaceRow == lastFaceRow)
            {
                axis      = EnumAxis.x;
                slice     = firstFaceRow;
                direction = firstFaceCol > lastFaceCol ? EnumDirection.negative : EnumDirection.positive;
                animType  = firstFaceRow == 1 ? EnumAnimType.cube : EnumAnimType.slice;
            }
            else
            {
                axis      = EnumAxis.z;
                slice     = firstFaceCol;
                direction = firstFaceRow > lastFaceRow ? EnumDirection.positive : EnumDirection.negative;
                animType  = firstFaceCol == 1 ? EnumAnimType.cube : EnumAnimType.slice;
            }
            break;

        case "Z":
            if (firstFaceRow == lastFaceRow)
            {
                axis      = EnumAxis.y;
                slice     = firstFaceRow;
                direction = firstFaceCol > lastFaceCol ? EnumDirection.positive : EnumDirection.negative;
                animType  = firstFaceRow == 1 ? EnumAnimType.cube : EnumAnimType.slice;
            }
            else
            {
                axis      = EnumAxis.x;
                slice     = firstFaceCol;
                direction = firstFaceRow > lastFaceRow ? EnumDirection.positive : EnumDirection.negative;
                animType  = firstFaceCol == 1 ? EnumAnimType.cube : EnumAnimType.slice;
            }
            break;
        }

        touchList.Clear();
        print("rotating");
        CubeController.Instance.StartRotation(axis, animType, direction, slice);
    }