Exemplo n.º 1
0
    void Start()
    {
        Gradient colorGradient = ColorGradients[UnityEngine.Random.Range(0, ColorGradients.Length)];

        topLeft = new Vector3(
            -Width * Spacing * 0.5f,
            -Height * Spacing * 0.5f,
            0f
            );

        size   = Vector3.one * Spacing * 0.5f;
        size.z = 0f;

        for (float x = 0; x < Width; x++)
        {
            for (float y = 0; y < Height; y++)
            {
                float t = new Vector3(x / Width, y / Height).magnitude;

                GameObject tile = GameObject.Instantiate(TileObject);
                tile.transform.localScale = Vector3.one * Spacing * TileScale;
                tile.transform.position   = topLeft + new Vector3(x * Spacing, y * Spacing, 0f) + size;

                miniTF_Tile tf_tile = tile.GetComponent <miniTF_Tile>();
                tiles.Add(tf_tile);
                tf_tile.SetBackColor(colorGradient.Evaluate(t));
                tf_tile.x = (int)x;
                tf_tile.y = (int)y;
            }
        }

        // Spawn players:
        startShapes  = new List <miniTF_ShapeDesc>(Shapes);
        randomShapes = new List <miniTF_ShapeDesc>();

        while (startShapes.Count > 0)
        {
            int index = UnityEngine.Random.Range(0, startShapes.Count);
            randomShapes.Add(startShapes[index]);
            startShapes.Remove(startShapes[index]);
        }

        // Pick a random spot.
        int start_x = Mathf.FloorToInt(Width * 0.5f);
        int start_y = UnityEngine.Random.Range(1, (int)Height - 2);

        // Place a random tetronimo at that point.
        ActivateTiles(start_x, 0, GetRandomShape());
    }