コード例 #1
0
        public override IsaacRoomLayout GenerateLayout(IsaacRoom room, System.Random random, int roomWidth, int roomHeight)
        {
            var doors  = room.doorPositions;
            var layout = new IsaacRoomLayout();

            layout.InitializeTiles(roomWidth, roomHeight, IsaacRoomTileType.Empty);

            if (doors.Count > 1)
            {
                for (int i = 0; i < doors.Count; i++)
                {
                    for (int j = i + 1; j < doors.Count; j++)
                    {
                        var brushSize = random.Range(minBrushSize, maxBrushSize + 1);
                        ConnectDoors(layout, doors[i], doors[j], brushSize);
                    }
                }
            }
            else
            {
                var brushSize = random.Range(minBrushSize, maxBrushSize + 1);
                ConnectDoors(layout, doors[0], doors[0], brushSize);
            }

            return(layout);
        }
コード例 #2
0
        public IsaacRoom CreateRoom(IntVector position)
        {
            var room = new IsaacRoom();

            room.roomId   = idCounter++;
            room.position = position;
            return(room);
        }
コード例 #3
0
        void ConnectRoomsWithDoors(IsaacRoom roomA, IsaacRoom roomB)
        {
            // Create a door between the two rooms
            roomA.adjacentRooms.Add(roomB.roomId);
            roomB.adjacentRooms.Add(roomA.roomId);
            float doorPositionRatio = random.NextFloat();

            CreateDoor(roomA, roomB, doorPositionRatio);
        }
コード例 #4
0
        void GenerateRoomLayout(IsaacRoomLayoutBuilder layoutBuilder, IsaacRoom room)
        {
            IsaacRoomLayout layout;

            if (layoutBuilder == null)
            {
                layout = GenerateEmptyRoomLayout();
            }
            else
            {
                layout = layoutBuilder.GenerateLayout(room, random, isaacConfig.roomWidth, isaacConfig.roomHeight);
            }
            room.layout = layout;
        }
コード例 #5
0
        void CreateDoor(IsaacRoom roomA, IsaacRoom roomB, float ratio)
        {
            var door = new IsaacDoor();

            door.roomA = roomA.roomId;
            door.roomB = roomB.roomId;
            door.ratio = ratio;
            doors.Add(door);

            // Create the door tile
            var  roomWidth  = isaacConfig.roomWidth;
            var  roomHeight = isaacConfig.roomHeight;
            bool horizontal = (roomA.position.z - roomB.position.z) == 0; // Are the two room horizontal
            var  size       = horizontal ? isaacConfig.roomHeight : isaacConfig.roomWidth;
            var  location1D = Mathf.FloorToInt(size * door.ratio);

            var leftRoom  = roomA;
            var rightRoom = roomB;

            if (horizontal && leftRoom.position.x > rightRoom.position.x)
            {
                // Swap
                leftRoom  = roomB;
                rightRoom = roomA;
            }
            else if (!horizontal && leftRoom.position.z > rightRoom.position.z)
            {
                // Swap
                leftRoom  = roomB;
                rightRoom = roomA;
            }


            IntVector leftRoomDoor;
            IntVector rightRoomDoor;

            if (horizontal)
            {
                leftRoomDoor  = new IntVector(roomWidth, 0, location1D);
                rightRoomDoor = new IntVector(-1, 0, location1D);
            }
            else
            {
                leftRoomDoor  = new IntVector(location1D, 0, roomHeight);
                rightRoomDoor = new IntVector(location1D, 0, -1);
            }

            leftRoom.doorPositions.Add(leftRoomDoor);
            rightRoom.doorPositions.Add(rightRoomDoor);
        }
コード例 #6
0
        void AddNextRoomNode(IsaacRoomFactory roomFactory,
                             Queue <LevelGrowthNode> queue, HashSet <IntVector> visited, int maxRooms,
                             IsaacRoom parentRoom, int direction, float probability)
        {
            if (random.NextFloat() > probability)
            {
                return;
            }
            if (rooms.Count >= maxRooms)
            {
                return;
            }

            var nextPosition = parentRoom.position + directions[direction];

            if (!visited.Contains(nextPosition))
            {
                var nextRoom = roomFactory.CreateRoom(nextPosition);
                rooms.Add(nextRoom);
                var nextNode = new LevelGrowthNode();
                nextNode.room          = nextRoom;
                nextNode.moveDirection = direction;
                queue.Enqueue(nextNode);
                visited.Add(nextPosition);

                // Create a door between the two rooms
                ConnectRoomsWithDoors(parentRoom, nextRoom);
            }
            else
            {
                // See if we can connect to the other room
                // first make sure we don't already have a connection between the two
                var nextRoom = GetRoomAt(nextPosition);
                if (!ContainsDoorBetween(parentRoom.roomId, nextRoom.roomId))
                {
                    float loopTest = random.NextFloat();
                    if (loopTest < isaacConfig.cycleProbability)
                    {
                        // Connect the two rooms together
                        if (nextRoom != null)
                        {
                            // Create a door between the two rooms
                            ConnectRoomsWithDoors(parentRoom, nextRoom);
                        }
                    }
                }
            }
        }
コード例 #7
0
 public static bool ContainsDoorAt(int x, int z, IsaacRoom room)
 {
     return(room.doorPositions.Contains(new IntVector(x, 0, z)));
 }
コード例 #8
0
 public abstract IsaacRoomLayout GenerateLayout(IsaacRoom room, System.Random random, int roomWidth, int roomHeight);