コード例 #1
0
        private bool[,] GetExteriorWall(bool[,] layout, IEnumerable <IEnumerable <Node> > islands)
        {
            // First piece is always exterior walls. If it isn't, well what the f**k.
            var exterior = islands.First();

            var wholeShape = MapTilesToArray(layout, exterior);

            // Invert the whole thing
            for (int y = 0; y < wholeShape.GetLength(1); y++)
            {
                for (int x = 0; x < wholeShape.GetLength(0); x++)
                {
                    wholeShape[x, y] = !wholeShape[x, y];
                }
            }

            // Get the distinct outside of our shape.
            var xx = LevelDecomposer.DecomposeLevel(wholeShape);

            var exteriorTiles = xx.First(); // Should only ever be one shape here.

            wholeShape = new bool[layout.GetLength(0), layout.GetLength(1)];

            // Map it and return it.
            foreach (var i in exteriorTiles)
            {
                wholeShape[i.x, i.y] = true;
            }

            return(wholeShape);
        }
コード例 #2
0
        public void GenerateWallPolygon(bool[,] layout)
        {
            // Debug shit
            //vertices.Clear();

            var marching = new MarchingSquare();
            var islands  = LevelDecomposer.DecomposeLevel(layout);

            if (islands.Count() == 0)
            {
                throw new Exception("Downlinked Planet could not be parsed");
            }

            var wholeShape = GetExteriorWall(layout, islands);

            AddIsland(marching, wholeShape, false); // false means wall

            foreach (var island in islands.Skip(1))
            {
                var shape = MapTilesToArray(layout, island);

                AddIsland(marching, shape);
            }
        }