Exemplo n.º 1
0
    //[x1, y1] Coordinates before movement, [x2, y2] Coordinates to be moved
    void MoveOrCombine(int x1, int y1, int x2, int y2)
    {
        //If it is empty in the coordinates to be moved and exists in the coordinates before the movement,
        if (Square[x2, y2] == null && Square[x1, y1] != null)
        {
            move = true;
            Square[x1, y1].GetComponent <Moving>().Move(x2, y2, false);
            Square[x2, y2] = Square[x1, y1];
            Square[x1, y1] = null;
        }

        // Merge (If it is empty in the coordinates to be moved and exists in the coordinates before the movement,)
        if (Square[x1, y1] != null && Square[x2, y2] != null && Square[x1, y1].name == Square[x2, y2].name && Square[x1, y1].tag != "Combine" && Square[x2, y2].tag != "Combine")
        {
            move = true;
            for (j = 0; j <= 16; j++)
            {
                if (Square[x2, y2].name == n[j].name + "(Clone)")
                {
                    break;
                }
            }
            Square[x1, y1].GetComponent <Moving>().Move(x2, y2, true);
            Destroy(Square[x2, y2]);
            Square[x1, y1]     = null;
            Square[x2, y2]     = Instantiate(n[j + 1], new Vector3(1.2f * x2 - 1.8f, 1.2f * y2 - 1.8f, 0), Quaternion.identity, tilesParrent.transform);
            Square[x2, y2].tag = "Combine";
            Square[x2, y2].GetComponent <Animator>().SetTrigger("Combine");
            score += (int)Mathf.Pow(2, j + 2);
            audioScript.Merged();
            Debug.Log("Merged");
        }
    }