Exemplo n.º 1
0
        private void CreateDoors(RogueSharp.Rectangle room)
        {
            int xMin = room.Left;
            int xMax = room.Right;
            int yMin = room.Top;
            int yMax = room.Bottom;

            List <RogueSharp.ICell> borderCells
                = _map.GetCellsAlongLine(xMin, yMin, xMax, yMin).ToList();

            borderCells.AddRange(_map.GetCellsAlongLine(xMin, yMin, xMin, yMax));
            borderCells.AddRange(_map.GetCellsAlongLine(xMin, yMax, xMax, yMax));
            borderCells.AddRange(_map.GetCellsAlongLine(xMax, yMin, xMax, yMax));

            foreach (RogueSharp.ICell c in borderCells)
            {
                if (IsPotentialDoor(c))
                {
                    _map.SetCellProperties(c.X, c.Y, false, true, true);
                    _map.Doors.Add(new Core.DoorHelper(c.X, c.Y, false));

                    // create door entity - needs pos, render, door
                    _entManager.AddDoor(c.X, c.Y, false);
                }
            }
        }
        protected virtual void SpawnItems(Map map, Rectangle room)
        {
            int numberOfItems = Program.Game.Random.Next(MaximumItemsPerRoom + 1);

            var itemPool = new WeightedPool <Entity.EntityFactoryDelegate>();

            itemPool.Add(ItemFactory.CreatePotion, 70);
            itemPool.Add(ItemFactory.CreateLightningScroll, GetWeightFromDungeonLevel(new SortedDictionary <int, int> {
                { 2, 10 }, { 4, 25 }
            }));
            itemPool.Add(ItemFactory.CreateConfuseScroll, GetWeightFromDungeonLevel(new SortedDictionary <int, int> {
                { 2, 25 }
            }));
            itemPool.Add(ItemFactory.CreateFireballScroll, GetWeightFromDungeonLevel(new SortedDictionary <int, int> {
                { 4, 20 }
            }));
            itemPool.Add(ItemFactory.CreateSword, 30);

            for (int i = 0; i < numberOfItems; i++)
            {
                int x = Program.Game.Random.Next(room.Left + 1, room.Right);
                int y = Program.Game.Random.Next(room.Top + 1, room.Bottom);

                if (map.IsWalkable(x, y))
                {
                    var itemFactory = itemPool.Pick();

                    var item = itemFactory(x, y, Program.Game.DungeonLevel);
                    Program.Game.Entities.Add(item);
                }
            }
        }
 public void CreateRoom(Rectangle room, Tile tile)
 {
     for (int x = Math.Max(room.Left + 1, 1); x < Math.Min(room.Right, Width - 1); x++)
     {
         for (int y = Math.Max(room.Top + 1, 1); y < Math.Min(room.Bottom, Height - 1); y++)
         {
             SetTile(x, y, tile);
         }
     }
 }
Exemplo n.º 4
0
 private void CreateRoom(RogueSharp.Rectangle room)
 {
     for (int x = room.Left + 1; x < room.Right; x++)
     {
         for (int y = room.Top + 1; y < room.Bottom; y++)
         {
             _map.SetCellProperties(x, y, true, true, true);
         }
     }
 }
Exemplo n.º 5
0
        public Core.DungeonMap CreateMap()
        {
            _map.Initialize(_width, _height);

            for (int r = _maxRooms; r > 0; r--)
            {
                int roomWidth  = Game.Random.Next(_roomMinSize, _roomMaxSize);
                int roomHeight = Game.Random.Next(_roomMinSize, _roomMaxSize);
                int roomXPos   = Game.Random.Next(0, _width - roomWidth - 1);
                int roomYPos   = Game.Random.Next(0, _height - roomHeight - 1);

                var newRoom = new RogueSharp.Rectangle(roomXPos, roomYPos, roomWidth, roomHeight);

                bool newRoomIntersects = _map.Rooms.Any(room => newRoom.Intersects(room));

                if (!newRoomIntersects)
                {
                    _map.Rooms.Add(newRoom);
                }
            }

            foreach (RogueSharp.Rectangle room in _map.Rooms)
            {
                CreateRoom(room);
            }

            for (int r = 1; r < _map.Rooms.Count; r++)
            {
                int previousRoomCentreX = _map.Rooms[r - 1].Center.X;
                int previousRoomCentreY = _map.Rooms[r - 1].Center.Y;
                int CurrentRoomCentreX  = _map.Rooms[r].Center.X;
                int CurrentRoomCentreY  = _map.Rooms[r].Center.Y;

                if (Game.Random.Next(1, 2) == 1)
                {
                    CreateHorizontalTunnel(previousRoomCentreX, CurrentRoomCentreX, previousRoomCentreY);
                    CreateVerticalTunnel(previousRoomCentreY, CurrentRoomCentreY, CurrentRoomCentreX);
                }
                else
                {
                    CreateVerticalTunnel(previousRoomCentreY, CurrentRoomCentreY, previousRoomCentreX);
                    CreateHorizontalTunnel(previousRoomCentreX, CurrentRoomCentreX, CurrentRoomCentreY);
                }
            }

            foreach (RogueSharp.Rectangle room in _map.Rooms)
            {
                CreateDoors(room);
            }

            CreateStairs();
            return(_map);
        }
Exemplo n.º 6
0
 public bool DoesRoomHaveWalkableSpace(RogueSharp.Rectangle room)
 {
     for (int x = 1; x <= room.Width; x++)
     {
         for (int y = 1; y <= room.Height; y++)
         {
             if (IsWalkable(x + room.X, y + room.Y))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 7
0
 public RogueSharp.Point GetRandomWalkableLocationInRoom(RogueSharp.Rectangle room)
 {
     if (DoesRoomHaveWalkableSpace(room))
     {
         for (int i = 0; i < 100; i++)
         {
             int x = Game.Random.Next(1, room.Width - 2) + room.X;
             int y = Game.Random.Next(1, room.Height - 2) + room.Y;
             if (IsWalkable(x, y))
             {
                 return(new RogueSharp.Point(x, y));
             }
         }
     }
     return(default(RogueSharp.Point));
 }
        protected virtual void SpawnMonsters(Rectangle room)
        {
            int numberOfMonsters = Program.Game.Random.Next(MaximumMonstersPerRoom + 1);

            var monsterPool = new WeightedPool <Entity.EntityFactoryDelegate>();

            monsterPool.Add(MonsterFactory.CreateRat, 50);
            monsterPool.Add(MonsterFactory.CreateHound, GetWeightFromDungeonLevel(new SortedDictionary <int, int> {
                { 1, 10 }, { 3, 30 }, { 5, 50 }
            }));

            for (int i = 0; i < numberOfMonsters; i++)
            {
                int x = Program.Game.Random.Next(room.Left + 1, room.Right);
                int y = Program.Game.Random.Next(room.Top + 1, room.Bottom);

                var monsterFactory = monsterPool.Pick();

                var monster = monsterFactory(x, y, Program.Game.DungeonLevel);
                Program.Game.Entities.Add(monster);
            }
        }