Exemplo n.º 1
0
    private List <RoomNode> GenerateNextRooms(RoomSide side, List <RoomNode> currentRooms,
                                              ShouldStillGenerate shouldStillGenerate, int radius)
    {
        var oppositeSide = Room.OppositeSide(side);
        var currRoomNum  = 0;
        var doorsLeft    = CountDoorsAtSide(side, currentRooms);
        var nextRooms    = new List <RoomNode>();

        while (doorsLeft > 0)
        {
            // find a room with <= rooms at opposite of side.
            RoomNode nextNode = GetRoomWithMaxDoors(
                oppositeSide, doorsLeft, shouldStillGenerate, radius);
            nextRooms.Add(nextNode);
            var nodesToMake = nextNode.GetDoorCount(oppositeSide);
            Assert.IsTrue(nodesToMake > 0);
            doorsLeft -= nodesToMake;
            Assert.IsTrue(doorsLeft >= 0);
            for (var doorNum = 0; doorNum < nodesToMake; doorNum++)
            {
                while (currentRooms[currRoomNum].GetNeighborRooms(side).Count >= currentRooms[currRoomNum].GetDoorCount(side))
                {
                    currRoomNum++;
                }

                var currentRoomDoorNum = currentRooms[currRoomNum].GetNeighborRooms(side).Count;
                currentRooms[currRoomNum].GetNeighborRooms(side).Add(nextNode);
                currentRooms[currRoomNum].GetRoomDoorNums(side).Add(doorNum);
                nextNode.GetNeighborRooms(oppositeSide).Add(currentRooms[currRoomNum]);
                nextNode.GetRoomDoorNums(oppositeSide).Add(currentRoomDoorNum);
            }
        }
        return(nextRooms);
    }
Exemplo n.º 2
0
    private void LeaveRoomThroughDoor(RoomNode oldRoom, RoomSide oldDoorSide, int oldDoorNum)
    {
        if (!oldRoom.myRoom.IsCleared())
        {
            return;
        }
        var newDoorSide = Room.OppositeSide(oldDoorSide);
        var newDoorNum  = oldRoom.GetRoomDoorNums(oldDoorSide)[oldDoorNum];  // todo !!! set this!!

        Debug.Log("enter door from door num" + oldDoorNum + "to" + newDoorNum);
        RoomNode newRoom = oldRoom.GetNeighborRooms(oldDoorSide)[oldDoorNum];
        var      newDoor = newRoom.roomObject.GetComponent <Room>().GetDoor(newDoorSide, newDoorNum);

        transform.position = newDoor.transform.position - Room.RoomSideToVec(newDoorSide);
        currentRoomNode    = newRoom;
        currentRoomNode.manager.ReloadMinimap();
    }