コード例 #1
0
    //Places doors between two adjacent rooms so the player can travel between them
    private static void ConnectRooms(Dungeon Dungeon, DungeonRoom OldRoom, DungeonRoom NewRoom, Direction PlacementDirection)
    {
        //Create two lists to contain the wall tiles of each of the two rooms that are going to be connected
        List <DungeonTile> OldRoomWallTiles = new List <DungeonTile>();
        List <DungeonTile> NewRoomWallTiles = new List <DungeonTile>();

        //Place doors between the two rooms to connect them
        switch (PlacementDirection)
        {
        case (Direction.North):
            OldRoomWallTiles = OldRoom.GetWallTiles(Direction.North);
            NewRoomWallTiles = NewRoom.GetWallTiles(Direction.South);
            break;

        case (Direction.East):
            OldRoomWallTiles = OldRoom.GetWallTiles(Direction.East);
            NewRoomWallTiles = NewRoom.GetWallTiles(Direction.West);
            break;

        case (Direction.South):
            OldRoomWallTiles = OldRoom.GetWallTiles(Direction.South);
            NewRoomWallTiles = NewRoom.GetWallTiles(Direction.North);
            break;

        case (Direction.West):
            OldRoomWallTiles = OldRoom.GetWallTiles(Direction.West);
            NewRoomWallTiles = NewRoom.GetWallTiles(Direction.East);
            break;
        }

        //Now place doors somewhere along these two walls to connect the rooms together
        bool RoomsConnected = false;

        while (!RoomsConnected)
        {
            //Grab a tile from the middle of the old rooms wall, then remove it so we dont select it again
            int         OldWallSelection = (OldRoomWallTiles.Count - 1) / 2;
            DungeonTile OldWallTile      = OldRoomWallTiles[OldWallSelection];
            OldRoomWallTiles.Remove(OldWallTile);

            //Grab whatever tile is adjacent to the selected tile, and check if thats part of the new rooms wall
            DungeonTile AdjacentWallTile = GetAdjacentTile(Dungeon, OldWallTile, PlacementDirection);
            bool        DoesConnect      = NewRoomWallTiles.Contains(AdjacentWallTile);

            //If the old rooms adjacent tile is part of the new rooms wall, this is the linking location
            if (DoesConnect)
            {
                //Connect the rooms and stop searching for a linking location
                RoomsConnected = true;
                OldWallTile.SetType(DungeonTileType.Door);
                AdjacentWallTile.SetType(DungeonTileType.Door);
            }
        }
    }
コード例 #2
0
    public void Init()
    {
        //Track the row and column coordinates of each tile in relation to its position in this room of the dungeon
        int Column = 1;
        int Row    = 1;

        //Change all the tiles which make up this room into their set room types
        for (int x = (int)XRange.x; x < (int)XRange.y; x++)
        {
            for (int y = (int)YRange.x; y < (int)YRange.y; y++)
            {
                //Grab the tile being initialised, store it in this rooms tile dictionary
                DungeonTile Tile = DungeonGenerator.Instance.CurrentDungeon.Tiles[new Vector2(x, y)];
                RoomTiles.Add(new Vector2(Column, Row), Tile);

                bool IsLeft   = x == (int)XRange.x;
                bool IsRight  = x == ((int)XRange.y) - 1;
                bool IsBottom = y == (int)YRange.x;
                bool IsTop    = y == ((int)YRange.y) - 1;

                //Set the tiles type based on which sides of the room its on
                if (IsTop && IsLeft && !IsRight && !IsBottom)
                {
                    Tile.SetType(DungeonTileType.TopLeftWall);
                }
                else if (IsTop && !IsLeft && !IsRight && !IsBottom)
                {
                    Tile.SetType(DungeonTileType.TopWall);
                }
                else if (IsTop && !IsLeft && IsRight && !IsBottom)
                {
                    Tile.SetType(DungeonTileType.TopRightWall);
                }
                else if (!IsTop && !IsLeft && IsRight && !IsBottom)
                {
                    Tile.SetType(DungeonTileType.RightWall);
                }
                else if (!IsTop && !IsLeft && IsRight && IsBottom)
                {
                    Tile.SetType(DungeonTileType.BottomRightWall);
                }
                else if (!IsTop && !IsLeft && !IsRight && IsBottom)
                {
                    Tile.SetType(DungeonTileType.BottomWall);
                }
                else if (!IsTop && IsLeft && !IsRight && IsBottom)
                {
                    Tile.SetType(DungeonTileType.BottomLeftWall);
                }
                else if (!IsTop && IsLeft && !IsRight && !IsBottom)
                {
                    Tile.SetType(DungeonTileType.LeftWall);
                }
                else
                {
                    Tile.SetType(DungeonTileType.Floor);
                }

                Row++;
            }
            Column++;
            Row = 1;
        }
    }