Example #1
0
    public IEnumerator SwitchShapes(GameSlot slot1, GameSlot slot2)
    {
        // Setting the parents
        Transform shape1 = slot1.GetSlotShapeTransform();
        Transform shape2 = slot2.GetSlotShapeTransform();

        shape1.SetParent(slot2.transform);
        shape2.SetParent(slot1.transform);

        slot1.SetSlotShapeReference(shape2);
        slot2.SetSlotShapeReference(shape1);

        onShapeSwap?.Invoke();
        while (locksAnimating > 0)
        {
            yield return(null);
        }

        // Triggering Shape Destruction(s)
        int destroyedShapes = 0;

        destroyedShapes += TriggerShapeDestruction(slot1.GetSlotIndex(), gameBoardParent);
        destroyedShapes += TriggerShapeDestruction(slot2.GetSlotIndex(), gameBoardParent);

        while (shapesBeingDestroyed > 0)
        {
            yield return(null);
        }

        onShapeDestroy?.Invoke(destroyedShapes);
        while (locksAnimating > 0)
        {
            yield return(null);
        }

        // Reset each slot
        slot1.ResetSlotState();
        slot2.ResetSlotState();

        if (shapesBeingDestroyed == 0)
        {
            gameManager.CheckGameState();
        }

        gameManager.MarkSwitchingAsComplete();
    }
Example #2
0
    public IEnumerator MoveShapes(GameSlot slot1, GameSlot slot2)
    {
        // Declaring temporary storeage variables
        Transform shape1P = slot1.GetSlotShapeTransform(), shape2P = slot2.GetSlotShapeTransform();

        Vector3 shape1StartPosition = shape1P.position, shape2StartPosition = shape2P.position;
        float   mult = 1f / (10f / 24f);
        float   progress = 0;

        while (progress < 1f)
        {
            // Incrementing the progress
            progress += Mathf.Clamp(Time.deltaTime * mult, 0f, 1f);

            // Moving the shapes
            shape1P.position = Vector3.Lerp(shape1StartPosition, shape2StartPosition, progress);
            shape2P.position = Vector3.Lerp(shape2StartPosition, shape1StartPosition, progress);

            // Frame delay
            yield return(null);
        }

        StartCoroutine(SwitchShapes(slot1, slot2));
    }