Esempio n. 1
0
    private void ResetVertical(DiceHandler[] diceList)
    {
        isSwapping = true;
        float delay = 0.5f;

        // Move cleared dice to the top
        for (int i = 0; i < diceList.Length; i++)
        {
            diceList[i].isTumbling = true;

            int xPos = (int)diceList[i].gridPosition.x;
            int yPos = (int)diceList[i].gridPosition.y;

            Vector3 pos = diceList[i].transform.position;
            pos.y = resetHeight + (yOffset * i);
            diceList[i].transform.position = pos;

            diceList[i].value     = Random.Range(1, 7);
            diceList[i].fallDelay = delay * i;
        }

        // Slide other dice down
        DiceHandler topDie = diceList[0];

        if (topDie.gridPosition.y != height - 1)
        {
            for (int y = (int)(topDie.gridPosition.y + 1); y < height; y++)
            {
                DiceHandler die = board[(int)topDie.gridPosition.x, y].GetComponent <DiceHandler>();

                Vector3 endPos = die.transform.position;
                endPos.y -= 1.1f * diceList.Length;
                StartCoroutine(die.SwapPosition(die.transform.position, endPos));

                board[(int)die.gridPosition.x, y - diceList.Length] = die.gameObject;
                die.gridPosition = new Vector2(die.gridPosition.x, y - diceList.Length);
            }
        }

        // Drop cleared dice
        for (int i = 0; i < diceList.Length; i++)
        {
            Vector3 endPos = diceList[i].transform.position;
            endPos.y = 3.8f - (yOffset * (diceList.Length - i - 1));

            StartCoroutine(diceList[i].FallingRoutine(diceList[i].transform.position, endPos));

            int gridY = height - (diceList.Length - i);
            board[(int)diceList[i].gridPosition.x, gridY] = diceList[i].gameObject;
            diceList[i].gridPosition = new Vector2(diceList[i].gridPosition.x, gridY);
        }
    }
Esempio n. 2
0
    public void SwapDice(GameObject secondDie)
    {
        isSwapping = true;

        DiceHandler secondHandler = secondDie.GetComponent <DiceHandler>();
        Vector2     tempGrid      = secondHandler.gridPosition;
        Vector3     tempPos       = secondDie.transform.position;

        secondHandler.gridPosition = selectedDie.gridPosition;
        board[(int)selectedDie.gridPosition.x, (int)selectedDie.gridPosition.y] = secondDie;

        selectedDie.gridPosition = tempGrid;
        board[(int)tempGrid.x, (int)tempGrid.y] = selectedDie.gameObject;

        StartCoroutine(secondHandler.SwapPosition(secondDie.transform.position, selectedDie.transform.position));
        StartCoroutine(selectedDie.SwapPosition(selectedDie.transform.position, tempPos));

        selectedDie = null;
    }