Esempio n. 1
0
    public bool Repopulate()
    {
        bool repop = false;

        for (int x = 0; x < WIDTH; x++)
        {
            for (int y = 0; y < HEIGHT; y++)
            {
                //Check if there is an empty spot in the array
                if (tiles[x, y] == null)
                {
                    //The game knows we're about to repopulate
                    repop = true;
                    //Check if we're on the top row of the grid
                    if (y == 0)
                    {
                        //If so, make a token
                        tiles[x, y] = Instantiate(tilePrefab);
                        TileScript tileScript = tiles[x, y].GetComponent <TileScript>();
                        tileScript.SetSprite(Random.Range(0, tileScript.tileColors.Length));
                        tiles[x, y].transform.parent        = gridHolder.transform;
                        tiles[x, y].transform.localPosition = new Vector2(WIDTH - x - xOffset, HEIGHT - y - yOffset);
                    }
                    else
                    {
                        slideLerp   = 0;
                        tiles[x, y] = tiles[x, y - 1];
                        TileScript tileScript = tiles[x, y].GetComponent <TileScript>();
                        if (tileScript != null)
                        {
                            tileScript.SetupSlide(new Vector2(WIDTH - x - xOffset, HEIGHT - y - yOffset));
                            tiles[x, y - 1] = null;
                            //tiles[x, y].transform.localPosition = Vector3.Lerp(tileScript.startPosition, tileScript.destPosition, lerpSpeed);
                        }
                        //Changes the PlayerScript xPos and yPos to the position it lerps down to
                        if (tileScript.type == -1)
                        {
                            PlayerScript temp2 = tileScript.GetComponentInParent <PlayerScript>();
                            temp2.xPos = x;
                            temp2.yPos = y;
                            //Debug.Log(temp2.xPos + " " + temp2.yPos);
                        }
                    }
                }
            }
        }
        return(repop);
    }