Example #1
0
        public static void UpdateSelectionBox(GoRogue.Rectangle box)
        {
            SelectionBox.Resize(box.Width, box.Height, true);
            SelectionBox.Position = box.Position;
            SelectionBox.DrawBox(new Microsoft.Xna.Framework.Rectangle(0, 0, SelectionBox.Width, SelectionBox.Height), new Cell(Color.White, Color.Transparent, 179));

            SelectionBox.ConnectLines();
        }
        public void MonoGameRectToGoRogueRectConversion()
        {
            XnaRect m = new XnaRect(1, 2, 5, 6);
            GoRect  g = m;

            Assert.AreEqual(m.X, g.X);
            Assert.AreEqual(m.Y, g.Y);
            Assert.AreEqual(m.Width, g.Width);
            Assert.AreEqual(m.Height, g.Height);
        }
        public void GoRogueRectToMonoGameRectConversion()
        {
            GoRect  g = new GoRect(1, 2, 5, 6);
            XnaRect m = g;

            Assert.AreEqual(g.X, m.X);
            Assert.AreEqual(g.Y, m.Y);
            Assert.AreEqual(g.Width, m.Width);
            Assert.AreEqual(g.Height, m.Height);
        }
Example #4
0
        public static List <Coord> BorderLocations(GoRogue.Rectangle room)
        {
            int          xMin = room.MinExtentX;
            int          xMax = room.MaxExtentX;
            int          yMin = room.MinExtentY;
            int          yMax = room.MaxExtentY;
            Coord        min  = new Coord(xMin, yMin); //upper left
            Coord        max  = new Coord(xMax, yMax); //bottom right
            Coord        bl   = new Coord(xMin, yMax); //bottom left
            Coord        tr   = new Coord(xMax, yMin); //top right
            List <Coord> borderCells;

            borderCells = PointsAlongStraightLine(tr, max).ToList();
            borderCells.AddRange(PointsAlongStraightLine(min, tr).ToList());
            borderCells.AddRange(PointsAlongStraightLine(min, bl).ToList());
            borderCells.AddRange(PointsAlongStraightLine(bl, max).ToList());

            return(borderCells.Distinct().ToList());
        }
Example #5
0
 public static XNARect ToXNARect(this GoRogue.Rectangle r) => new XNARect(r.X, r.Y, r.Width, r.Height);
Example #6
0
        public IEnumerable <MapInfo> GenerateOn(Floor floor, Rectangle area, ResettableRandom rng)
        {
            GenerationContext context = new GenerationContext(rng);
            MapInfo           mapInfo = floor.MapInfo;

            Bag <RoomConnection> pendingConnections = new Bag <RoomConnection>(rng);
            List <IRoom>         rooms = new List <IRoom>();

            Rectangle initialRoomRect = new Rectangle(new Coord(20, 20), 3, 3);
            SourceCursor <IRoomGenerator> initialSourceCursor = _rootRoomSource.Pull(context);
            IRoomGenerator initialRoomGenerator = initialSourceCursor.Value;

            initialSourceCursor.Use();

            IRoom initialRoom = initialRoomGenerator.Generate(floor, new RoomConnection(new Coord(area.Width / 4, area.Height / 2), Direction.NONE, null, false), rng);

            floor.Entrance = initialRoom.Area.Bounds.Center;

            pendingConnections.PutRange(initialRoom.PotentialConnections);

            yield return(mapInfo);

            int n = 0;

            while (pendingConnections.Count > 0 && n < 1000)
            {
                RoomConnection nextConnection = pendingConnections.Get(true);

                Coord hallEnd = nextConnection.Position +
                                new Coord(nextConnection.Direction.DeltaX, nextConnection.Direction.DeltaY) * rng.Next(1, 8);

                RoomConnection hallConnection = new RoomConnection(hallEnd, nextConnection.Direction, null, false);

                if (nextConnection.Possibilities.IsEmpty())
                {
                    n += 1;
                    continue;
                }

                SourceCursor <IRoomGenerator> generatorCursor = nextConnection.Possibilities.Pull(context);

                IRoomGenerator generator = generatorCursor.Value;

                int[] rngState = rng.GetState();

                if (!generator.CanGenerate(floor, hallConnection, rng))
                {
                    pendingConnections.Put(nextConnection);
                    n += 1;
                    continue;
                }

                rng.LoadState(rngState);

                IRoom room = generator.Generate(floor, hallConnection, rng);
                rooms.Add(room);

                generatorCursor.Use();

                pendingConnections.PutRange(room.PotentialConnections);

                yield return(mapInfo);


                SourceCursor <IHallGenerator> hallGeneratorCursor = _hallGenerators.Pull(context);;
                IHallGenerator hallGenerator = hallGeneratorCursor.Value;

                if (!hallGenerator.CanGenerate(floor, nextConnection.Position, hallEnd, rng))
                {
                    continue;
                }

                IRoom hall = hallGenerator.Generate(floor, nextConnection.Position, hallEnd, rng);
                hallGeneratorCursor.Use();

                yield return(mapInfo);

                n += 1;
            }

            while (pendingConnections.Count > 0)
            {
                RoomConnection nextConnection = pendingConnections.Get(true);
                Coord          hit            = Trace(mapInfo.Map, nextConnection.Position, nextConnection.Direction);

                if (hit == Coord.NONE)
                {
                    continue;
                }

                if (Distance.MANHATTAN.Calculate(nextConnection.Position, hit) > 10)
                {
                    continue;
                }

                if (mapInfo.Map.AStar.ShortestPath(nextConnection.Position, hit) is Path shortestPath && shortestPath.Length < 40)
                {
                    continue;
                }

                SourceCursor <IHallGenerator> hallGeneratorCursor = _hallGenerators.Pull(context);;
                IHallGenerator hallGenerator = hallGeneratorCursor.Value;

                if (!hallGenerator.CanGenerate(floor, nextConnection.Position, hit, rng))
                {
                    continue;
                }

                IRoom hall = hallGenerator.Generate(floor, nextConnection.Position, hit, rng);
                hallGeneratorCursor.Use();


                yield return(mapInfo);
            }

            foreach (Coord pos in area.Positions())
            {
                if (mapInfo.Map.GetTerrain(pos) == null)
                {
                    mapInfo.Map.SetTerrain(SolidRock(pos));
                }
            }

            Console.WriteLine($"num rooms: {rooms.Count}");

            foreach (IRoom room in rooms)
            {
                room.GeneratedBy.Populate(floor, room, rng);
            }



            // place exit
            while (true)
            {
                IRoom randomRoom = rooms.RandomItem(rng);
                Coord randomPos  = randomRoom.Area.Perimeter().ToList().RandomItem(rng);

                if (mapInfo.Map.WalkabilityView[randomPos] == false &&
                    mapInfo.Map.AStar.ShortestPath(floor.Entrance, randomPos) is Path shortestPath && shortestPath.Length > 50 &&
                    mapInfo.Map.GetObject(randomPos, mapInfo.Map.LayerMasker.Mask(Layers.Main)) == null)
                {
                    mapInfo.Map.SetTerrain(Exit(floor, randomPos));
                    floor.Exit = randomPos;
                    break;
                }
            }

            Console.WriteLine($"leftover connections = {pendingConnections.Count}");
        }
Example #7
0
 public static Microsoft.Xna.Framework.Rectangle ToMonoGameRectangle(this GoRogue.Rectangle rect) =>
 new Microsoft.Xna.Framework.Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
 public static XnaRect ToXnaRect(this GoRogue.Rectangle rect) => new XnaRect(rect.X, rect.Y, rect.Width, rect.Height);