コード例 #1
0
    public void OpenDoor(VirtualMap map, CellLocation start_floor_loc, CellLocation end_floor_loc, CellLocation passage_loc, VirtualMap.DirectionType direction)
    {
        map.GetCell(passage_loc).Type        = VirtualCell.CellType.Door;
        map.GetCell(passage_loc).Orientation = direction;

        // We also connect the cells
        map.ConnectCells(start_floor_loc, end_floor_loc);
    }
コード例 #2
0
    public VirtualRoom CreateRoom(VirtualMap map, int width, int height, VirtualRoom r)
    {
        // Check if we have enough space for a room
        if (r.leftCorner == new CellLocation(-1, -1))
        {
            return(null);
        }
        else
        {
            //Debug.Log ("Creating a room: w:"+width +" H:"+height +" starting_location:"+r.leftCorner);
            for (int i = 0; i < r.Width; i++)
            {
                for (int j = 0; j < r.Height; j++)
                {
                    CellLocation l = new CellLocation(r.leftCorner.x + 2 * i, r.leftCorner.y + 2 * j);
                    // We create the room starting from the lower left floor

                    //Debug.Log("LOC: " + l);

                    // Do not add to this room's cells if it already belongs to another room
                    if (usedLocations.Contains(l))
                    {
//							Debug.Log (l + " already belongs to a room!");
                        continue;
                    }

                    VirtualCell passageCell;

                    // Set top passage to empty
                    passageCell = map.GetCell(l.x, l.y + 1);
                    if (!passageCell.IsRoomWall())                      // May belong to another room already
                    {
                        passageCell.Type = VirtualCell.CellType.EmptyPassage;
                        if (l.y + 2 <= r.leftCorner.y + 2 * (r.Height - 1))
                        {
                            map.ConnectCells(l, new CellLocation(l.x, l.y + 2));
                            //Debug.Log("EMPTY: " + l + " TO TOP");
                        }
                    }

                    // Set right passage to empty
                    passageCell = map.GetCell(l.x + 1, l.y);
                    if (!passageCell.IsRoomWall())                      // May belong to another room already
                    {
                        passageCell.Type = VirtualCell.CellType.EmptyPassage;
                        if (l.x + 2 <= r.leftCorner.x + 2 * (r.Width - 1))
                        {
                            map.ConnectCells(l, new CellLocation(l.x + 2, l.y));
                            //Debug.Log("EMPTY: " + l + " TO RIGHT");
                        }
                    }

                    // Other passages are potentially walls
                    if (i == r.Width - 1)
                    {
                        map.GetCell(l.x + 1, l.y).Type = VirtualCell.CellType.RoomWall;
                        CellLocation floor_l = new CellLocation(l.x + 2, l.y);
                        if (!map.LocationIsOutsideBounds(floor_l))
                        {
                            map.DisconnectCells(l, floor_l);
                        }
                        //Debug.Log("WALL RIGHT: " + map.GetCell(l.x + 1, l.y).starting_location);
                    }
                    if (i == 0)
                    {
                        map.GetCell(l.x - 1, l.y).Type = VirtualCell.CellType.RoomWall;
                        CellLocation floor_l = new CellLocation(l.x - 2, l.y);
                        if (!map.LocationIsOutsideBounds(floor_l))
                        {
                            map.DisconnectCells(l, floor_l);
                        }
                        //Debug.Log("WALL LEFT: " + map.GetCell(l.x - 1, l.y).starting_location);
                    }
                    if (j == r.Height - 1)
                    {
                        map.GetCell(l.x, l.y + 1).Type = VirtualCell.CellType.RoomWall;
                        CellLocation floor_l = new CellLocation(l.x, l.y + 2);
                        if (!map.LocationIsOutsideBounds(floor_l))
                        {
                            map.DisconnectCells(l, floor_l);
                        }
                        //Debug.Log("WALL TOP: " + map.GetCell(l.x, l.y + 1).starting_location);
                    }
                    if (j == 0)
                    {
                        map.GetCell(l.x, l.y - 1).Type = VirtualCell.CellType.RoomWall;
                        CellLocation floor_l = new CellLocation(l.x, l.y - 2);
                        if (!map.LocationIsOutsideBounds(floor_l))
                        {
                            map.DisconnectCells(l, floor_l);
                        }
                        //Debug.Log("WALL BOT: " + map.GetCell(l.x, l.y - 1).starting_location);
                    }

                    map.AddRoomCell(l);

                    r.cells.Add(l);
                    usedLocations.Add(l);
                }
            }
        }
        return(r);
    }