Ejemplo n.º 1
0
        protected void DrawBlob(T map, BlobMap blobMap, int index, Loc offset, bool encroach)
        {
            BlobMap.Blob mapBlob = blobMap.Blobs[index];
            for (int xx = Math.Max(0, offset.X); xx < Math.Min(map.Width, offset.X + mapBlob.Bounds.Width); xx++)
            {
                for (int yy = Math.Max(0, offset.Y); yy < Math.Min(map.Height, offset.Y + mapBlob.Bounds.Height); yy++)
                {
                    Loc destLoc = new Loc(xx, yy);
                    Loc srcLoc  = destLoc + mapBlob.Bounds.Start - offset;
                    if (blobMap.Map[srcLoc.X][srcLoc.Y] == index)
                    {
                        // can place anything if encroaching
                        // otherwise, can place anything except roomterrain
                        if (encroach || !map.GetTile(destLoc).TileEquivalent(map.RoomTerrain))
                        {
                            map.TrySetTile(new Loc(xx, yy), this.Terrain.Copy());
                        }
                    }
                }
            }

            GenContextDebug.DebugProgress("Draw Blob");
        }
Ejemplo n.º 2
0
        public static BlobMap DetectBlobs(Rect rect, Grid.LocTest isValid)
        {
            if (isValid == null)
            {
                throw new ArgumentNullException(nameof(isValid));
            }

            var blobMap = new BlobMap(rect.Width, rect.Height);

            for (int xx = rect.X; xx < rect.End.X; xx++)
            {
                for (int yy = rect.Y; yy < rect.End.Y; yy++)
                {
                    if (isValid(new Loc(xx, yy)) && blobMap.Map[xx][yy] == -1)
                    {
                        var blob = new BlobMap.Blob(new Rect(xx, yy, 1, 1), 0);

                        // fill the area, keeping track of the total area and blob bounds
                        Grid.FloodFill(
                            rect,
                            (Loc testLoc) => (!isValid(testLoc) || blobMap.Map[testLoc.X][testLoc.Y] != -1),
                            (Loc testLoc) => true,
                            (Loc fillLoc) =>
                        {
                            blobMap.Map[fillLoc.X][fillLoc.Y] = blobMap.Blobs.Count;
                            blob.Bounds = Rect.IncludeLoc(blob.Bounds, fillLoc);
                            blob.Area  += 1;
                        },
                            new Loc(xx, yy));

                        blobMap.Blobs.Add(blob);
                    }
                }
            }

            return(blobMap);
        }