예제 #1
0
        private static 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 static IEnumerable <IEnumerable <Vector2> > GenerateWallPolygon(bool[,] layout)
        {
            var marching = new MarchingSquare();
            var islands  = LevelDecomposer.DecomposeLevel(layout);

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

            // List of Lists, where each list holds the points of an 'island'.
            // An island is a collision body in the level.
            var finalPoints = new List <IEnumerable <Vector2> >();

            var wholeShape = GetExteriorWall(layout, islands);

            finalPoints.Add(AddIsland(marching, wholeShape, false));

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

                finalPoints.Add(AddIsland(marching, shape));
            }

            return(finalPoints);
        }