Example #1
0
File: Match3.cs Project: Ret44/LD41
 public void DropDownTiles()
 {
     for (int x = 0; x < _gridSize.x; x++)
     {
         for (int y = 0; y < _gridSize.y; y++)
         {
             if (_grid[x, y] == null)
             {
                 TileBase closest = GetClosestTile(x, y);
                 if (closest != null)
                 {
                     RemoveTile(closest.gridLocation);
                     SetTile(x, y, closest);
                     closest.target = GetWorldPosition(x, y);
                 }
                 else
                 {
                     GameObject tileObj = Instantiate(instance._tilePrefab) as GameObject;
                     tileObj.name                    = string.Format("Tile[{0},{1}]", x, y);
                     tileObj.transform.parent        = instance.transform;
                     tileObj.transform.localScale    = Vector3.one;
                     tileObj.transform.localPosition = new Vector2((0 - instance._gridSize.x / 2) + (x), (0 - instance._gridSize.y / 2) + (y));
                     TileBase tile = tileObj.GetComponent <TileBase>();
                     tile.Setup(instance._types[Random.Range(0, instance._types.Length)]);
                     tile.Spawn(new Vector2(x, y));
                 }
             }
         }
     }
     SanityCheck();
 }
Example #2
0
File: Match3.cs Project: Ret44/LD41
 public static void StartNewGame()
 {
     instance._grid           = new TileBase[(int)instance._gridSize.x, (int)instance._gridSize.y];
     instance._backgroundGrid = new SpriteRenderer[(int)instance._gridSize.x, (int)instance._gridSize.y];
     for (int x = 0; x < instance._gridSize.x; x++)
     {
         for (int y = 0; y < instance._gridSize.y; y++)
         {
             GameObject bckObj = Instantiate(instance._backgroundPrefab) as GameObject;
             bckObj.name                    = string.Format("Bck[{0},{1}]", x, y);
             bckObj.transform.parent        = instance.transform;
             bckObj.transform.localScale    = Vector3.one;
             bckObj.transform.localPosition = new Vector2((0 - instance._gridSize.x / 2) + (x), (0 - instance._gridSize.y / 2) + (y));
             instance._backgroundGrid[x, y] = bckObj.GetComponent <SpriteRenderer>();
             GameObject tileObj = Instantiate(instance._tilePrefab) as GameObject;
             tileObj.name                    = string.Format("Tile[{0},{1}]", x, y);
             tileObj.transform.parent        = instance.transform;
             tileObj.transform.localScale    = Vector3.one;
             tileObj.transform.localPosition = new Vector2((0 - instance._gridSize.x / 2) + (x), (0 - instance._gridSize.y / 2) + (y));
             TileBase tile = tileObj.GetComponent <TileBase>();
             tile.Setup(instance._types[Random.Range(0, instance._types.Length)]);
             tile.Spawn(new Vector2(x, y));
             //tile.gridLocation = new Vector2(x,y);
             //tile.target = GetWorldPosition(x, y);
             //  instance._grid[x, y] = tile;
         }
     }
 }
Example #3
0
File: Match3.cs Project: Ret44/LD41
    public void CreateNewTile(Vector2 gridPosition)
    {
        GameObject tileObj = Instantiate(instance._tilePrefab) as GameObject;

        tileObj.name                    = string.Format("Tile[{0},{1}]", gridPosition.x, gridPosition.y);
        tileObj.transform.parent        = instance.transform;
        tileObj.transform.localScale    = Vector3.one;
        tileObj.transform.localPosition = new Vector2((0 - instance._gridSize.x / 2) + (gridPosition.x), (0 - instance._gridSize.y / 2) + (gridPosition.y));
        TileBase tile = tileObj.GetComponent <TileBase>();

        tile.Setup(instance._types[Random.Range(0, instance._types.Length)]);
        tile.Spawn(gridPosition);
    }