示例#1
0
 public Room(int _RoomID, Enums.roomSize _roomSize, Enums.roomType _roomType, Enums.roomClass _roomClass)
 {
     RoomID    = _RoomID;
     roomClass = _roomClass;
     roomSize  = _roomSize;
     roomType  = _roomType;
     isValid   = true;
     roomMap   = new Tile[0, 0];
     roomTiles = new List <Tile>();
     wallTiles = new List <Tile>();
     roomSeed  = "";
 }
示例#2
0
    //END UNITY METHODS



    //CREATE STRUCTS

    Room newRoom(int originX, int originY, Enums.roomSize _RoomSize = Enums.roomSize.Medium, Enums.roomType _RoomType = Enums.roomType.None, Enums.roomClass _RoomClass = Enums.roomClass.Neutral)
    {
        Vector2Int origin = new Vector2Int(originX, originY);

restart:
        Room room = new Room(Rooms.Count, _RoomSize, _RoomType, _RoomClass);

        List <Tile> floorTiles = new List <Tile>();
        List <Tile> wallTiles  = new List <Tile>();

        Vector2Int RoomBoundMin = new Vector2Int(origin.x - (int)room.roomSize / 2, origin.y - (int)room.roomSize / 2);
        Vector2Int RoomBoundMax = new Vector2Int(origin.x + (int)room.roomSize / 2, origin.y + (int)room.roomSize / 2);

        room.roomSeed = new Seed(globalPrng);

        System.Random roomPrng = new System.Random(room.roomSeed.GetHashCode());


        {
            if (RoomBoundMin.x < 0)
            {
                RoomBoundMin.x = 0;
            }
            if (RoomBoundMin.y < 0)
            {
                RoomBoundMin.y = 0;
            }
            if (RoomBoundMax.x > size)
            {
                RoomBoundMax.x = size;
            }
            if (RoomBoundMax.y > size)
            {
                RoomBoundMax.y = size;
            }
        }// Check If In Map

        Tile[,] roomMap = new Tile[(RoomBoundMax.x - RoomBoundMin.x) + 2, (RoomBoundMax.y - RoomBoundMin.y) + 2];
        int roomArea  = (RoomBoundMax.x - RoomBoundMin.x) * (RoomBoundMax.y - RoomBoundMin.y);
        int tileCount = 0;

        for (int x = 0; x < roomMap.GetLength(0); x++)
        {
            for (int y = 0; y < roomMap.GetLength(1); y++)
            {
                roomMap[x, y] = globalMap[x + RoomBoundMin.x, y + RoomBoundMin.y];
            }
        }


        {
            for (int x = 0; x < roomMap.GetLength(0); x++)
            {
                for (int y = 0; y < roomMap.GetLength(1); y++)
                {
                    if (x > 0 && x < roomMap.GetLength(0) - 2 && y > 0 && y < roomMap.GetLength(1) - 2)
                    {
                        if (room.roomType != Enums.roomType.Spawn)
                        {
                            roomMap[x, y].tileType = (roomPrng.Next(0, 100) < randomFillPercent) ? Enums.tileType.Wall : Enums.tileType.Floor;
                        }
                        else
                        {
                            roomMap[x, y].tileType = Enums.tileType.Floor;
                        }
                    }
                }
            }
        } // Room Creation
        {
            for (int i = 0; i < SmoothMultiplier; i++)
            {
                for (int x = 0; x < roomMap.GetLength(0); x++)
                {
                    for (int y = 0; y < roomMap.GetLength(1); y++)
                    {
                        if (x > 0 && x < roomMap.GetLength(0) - 2 && y > 0 && y < roomMap.GetLength(1) - 2)
                        {
                            int neighbourWallTiles = GetSurroundingWallCount(x, y, roomMap);

                            if (neighbourWallTiles > 4)
                            {
                                roomMap[x, y].tileType = Enums.tileType.Wall;
                            }
                            else if (neighbourWallTiles < 4)
                            {
                                roomMap[x, y].tileType = Enums.tileType.Floor;
                            }
                        }
                    }
                }
            }
        } // Room Smoothing
        {
        } // Room Check

        if (tileCount > roomArea / 3f && room.isValid)
        {
            room.roomTiles = floorTiles;
            room.wallTiles = wallTiles;

            room.roomMap = roomMap;

            CreateMesh();

            return(room);
        }
        else
        {
            goto restart;
        }
    }