Ejemplo n.º 1
0
        public override void Added()
        {
            var fileList = new List <String>();

            int count = 0;

            while (true)
            {
                var fileName = Global.path + "Rooms/Room_" + index + "_" + count + ".tmx";
                if (File.Exists(fileName))
                {
                    fileList.Add(fileName);
                    count++;
                }
                else
                {
                    if (count == 0)
                    {
                        throw new Exception(fileName + " does not exist?");
                    }
                    break;
                }
            }
            XmlDocument doc = new XmlDocument();

            doc.Load(Rand.ChooseElement(fileList));

            MakeTiles(doc);
            MakeStuff(doc);
        }
Ejemplo n.º 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);
                    }
                }
            }
        }