Beispiel #1
0
 /// <summary>
 /// Load tiles in from a GridCollider.
 /// </summary>
 /// <param name="grid">The GridCollider to reference.</param>
 /// <param name="color">The color to set tiles that are collidable on the grid.</param>
 /// <param name="layer">The layer to place the tiles on.</param>
 public void LoadGrid(GridCollider grid, Color color, string layer = "")
 {
     for (var i = 0; i < grid.TileColumns; i++)
     {
         for (var j = 0; j < grid.TileRows; j++)
         {
             if (grid.GetTile(i, j))
             {
                 SetTile(i, j, color, layer);
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Load tiles in from a GridCollider and choose tiles based on the shape of the grid.
        /// </summary>
        /// <param name="grid">The GridCollider to reference.</param>
        /// <param name="layer">The layer to place the tiles on.</param>
        public void LoadGridAutoTile(GridCollider grid, string layer = "") {
            if (autoTileTable == null) {
                SetAutoTileData(autoTileDefaultData);
            }

            for (var i = 0; i < grid.TileColumns; i++) {
                for (var j = 0; j < grid.TileRows; j++) {
                    if (grid.GetTile(i, j)) {
                        int tileValue = 0;

                        /*
                            * auto tiling grid
                            * 
                            * 128 001 016
                            * 008 ___ 002
                            * 064 004 032
                            * 
                            */

                        if (grid.GetTile(i - 1, j - 1)) {
                            tileValue += 128;
                        }
                        if (grid.GetTile(i, j - 1)) {
                            tileValue += 1;
                        }
                        if (grid.GetTile(i + 1, j - 1)) {
                            tileValue += 16;
                        }
                        if (grid.GetTile(i + 1, j)) {
                            tileValue += 2;
                        }
                        if (grid.GetTile(i + 1, j + 1)) {
                            tileValue += 32;
                        }
                        if (grid.GetTile(i, j + 1)) {
                            tileValue += 4;
                        }
                        if (grid.GetTile(i - 1, j + 1)) {
                            tileValue += 64;
                        }
                        if (grid.GetTile(i - 1, j)) {
                            tileValue += 8;
                        }

                        if (autoTileTable.ContainsKey(tileValue)) {
                            tileValue = Rand.ChooseElement<int>(autoTileTable[tileValue]);
                        }

                        SetTile(i, j, tileValue, layer);
                    }
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Load tiles in from a GridCollider.
 /// </summary>
 /// <param name="grid">The GridCollider to reference.</param>
 /// <param name="color">The color to set tiles that are collidable on the grid.</param>
 /// <param name="layer">The layer to place the tiles on.</param>
 public void LoadGrid(GridCollider grid, Color color, string layer = "") {
     for (var i = 0; i < grid.TileColumns; i++) {
         for (var j = 0; j < grid.TileRows; j++) {
             if (grid.GetTile(i, j)) {
                 SetTile(i, j, color, layer);
             }
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// Load tiles in from a GridCollider and choose tiles based on the shape of the grid.
        /// </summary>
        /// <param name="grid">The GridCollider to reference.</param>
        /// <param name="layer">The layer to place the tiles on.</param>
        public void LoadGridAutoTile(GridCollider grid, string layer = "")
        {
            if (autoTileTable == null)
            {
                SetAutoTileData(autoTileDefaultData);
            }

            for (var i = 0; i < grid.TileColumns; i++)
            {
                for (var j = 0; j < grid.TileRows; j++)
                {
                    if (grid.GetTile(i, j))
                    {
                        int tileValue = 0;

                        /*
                         * auto tiling grid
                         *
                         * 128 001 016
                         * 008 ___ 002
                         * 064 004 032
                         *
                         */

                        if (grid.GetTile(i - 1, j - 1))
                        {
                            tileValue += 128;
                        }
                        if (grid.GetTile(i, j - 1))
                        {
                            tileValue += 1;
                        }
                        if (grid.GetTile(i + 1, j - 1))
                        {
                            tileValue += 16;
                        }
                        if (grid.GetTile(i + 1, j))
                        {
                            tileValue += 2;
                        }
                        if (grid.GetTile(i + 1, j + 1))
                        {
                            tileValue += 32;
                        }
                        if (grid.GetTile(i, j + 1))
                        {
                            tileValue += 4;
                        }
                        if (grid.GetTile(i - 1, j + 1))
                        {
                            tileValue += 64;
                        }
                        if (grid.GetTile(i - 1, j))
                        {
                            tileValue += 8;
                        }

                        if (autoTileTable.ContainsKey(tileValue))
                        {
                            tileValue = Rand.ChooseElement <int>(autoTileTable[tileValue]);
                        }

                        SetTile(i, j, tileValue);
                    }
                }
            }
        }