Example #1
0
    public void TriggerSkyFall()
    {
        bool missingOrbs = false;

        for (int y = 0; y < boardVertical; y++)
        {
            for (int x = 0; x < boardHorizontal; x++)
            {
                if (orbBoard[x, y] != null)
                {
                    int newY = y;
                    while (newY > 0)
                    {
                        if (orbBoard[x, newY - 1] == null)
                        {
                            newY--;
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (newY != y)
                    {
                        orbBoard[x, newY] = orbBoard[x, y];
                        orbBoard[x, y]    = null;
                        orbBoard[x, newY].SetTilePosition(new Vector2(x, newY));
                        orbBoard[x, newY].ApplyPositionOnBoard();
                    }
                }
            }
        }

        for (int y = 0; y < boardVertical; y++)
        {
            for (int x = 0; x < boardHorizontal; x++)
            {
                if (orbBoard[x, y] == null)
                {
                    missingOrbs = true;
                    Vector2    pos = new Vector2(-450 + x * orbSize, -390 + y * orbSize);
                    GameObject orb = Instantiate(orbPrefabs[Random.Range(0, orbPrefabs.Length)], Vector3.zero, Quaternion.identity, transform);
                    orb.GetComponent <RectTransform>().anchoredPosition = pos;
                    GemBehaviour gem = orb.GetComponent <GemBehaviour>();
                    gem.SetTilePosition(new Vector2(x, y));
                    orbBoard[x, y] = gem;
                }
            }
        }

        if (missingOrbs)
        {
            FindMatches(0.6f);
        }
    }
Example #2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (!orbPicked)
        {
            return;
        }
        //if (lastSwapped == collision.gameObject) return;
        GemBehaviour neighbour = collision.GetComponent <GemBehaviour>();

        Vector2 newTilePos = neighbour.GetTileIndex();

        neighbour.SetTilePosition(indexOnBoard);
        neighbour.ApplyPositionOnBoard();

        indexOnBoard = newTilePos;
    }
Example #3
0
 public void GenerateBoard()
 {
     orbBoard   = new GemBehaviour[boardHorizontal, boardVertical];
     orbChecked = new bool[boardHorizontal, boardVertical];
     for (int y = 0; y < boardVertical; y++)
     {
         for (int x = 0; x < boardHorizontal; x++)
         {
             Vector2    pos = new Vector2(-450 + x * orbSize, -390 + y * orbSize);
             GameObject orb = Instantiate(orbPrefabs[Random.Range(0, orbPrefabs.Length)], Vector3.zero, Quaternion.identity, transform);
             orb.GetComponent <RectTransform>().anchoredPosition = pos;
             GemBehaviour gem = orb.GetComponent <GemBehaviour>();
             gem.SetTilePosition(new Vector2(x, y));
             orbBoard[x, y] = gem;
         }
     }
 }