private IEnumerator GenrateLevel()
    {
        //Need a way to control number of rooms

        //currently will only go along a single chain of doors,
        //need a way to go back along the chain until there is a free door
        while (numDoors > 0)
        {
            if (lastRoom != currentRoom)
            {
                currentRoom.parentRoom = lastRoom;
            }
            currentRoom.ConstructRoom(ref numDoors);
            if (PlaceRoom())
            {
                numDoors--; placedRooms.Add(currentRoom);
            }
            else
            {
                currentRoom = currentRoom.parentRoom;
            }
            yield return(new WaitForSecondsRealtime(0.1f));
        }
        for (int i = placedRooms.Count; i > 0; i++)
        {
            placedRooms[i].FillOutRoom();
            yield return(new WaitForSecondsRealtime(0.1f));
        }
    }
 //place a core room
 private void PlaceCore()
 {
     coreRoom             = Instantiate(cores[Random.Range(0, cores.Count)], Vector3.zero, Quaternion.identity);
     coreRoom.createdFrom = RoomBlock.Direction.NULL;
     coreRoom.ConstructRoom(ref numDoors);
     currentRoom = coreRoom;
     currentRoom.distFromCore = 0;
     placedRooms.Add(coreRoom);
 }
Пример #3
0
    public RoomBlock ConstructRoom(ref int numDoors)
    {
        //--------------------------
        //disables nodes over the room which created this one
        //--------------------------
        switch ((int)createdFrom)
        {
        case    1: northNode = null; break;

        case    2: eastNode = null; break;

        case    3: southNode = null; break;

        case    4: westNode = null; break;

        default: break;
        }
        RoomBlock outPut = new RoomBlock();

        numDoors += getNumDoors();
        //--------------------------
        //do room construction
        //--------------------------

        //Need to do collision checks on nodes before spawning rooms

        #region roomConstruction
        if (northNode.myType == Node.Type.roomNode)
        {
            RoomBlock _northBlock =                                                                                      //Create the next room block for this room
                                    Instantiate(northBlock, northNode.transform.position, northNode.transform.rotation); //tell it its distance from the core room
            _northBlock.createdFrom  = Direction.s;                                                                      //tell it where it was created from so it
            _northBlock.distFromCore = distFromCore;                                                                     //ignores that direction in it's creation
            outPut.parentRoom        = this;
            _northBlock.ConstructRoom(ref numDoors);
            northBlock = _northBlock;
        }
        if (eastNode.myType == Node.Type.roomNode)
        {
            RoomBlock _eastBlock =
                Instantiate(eastBlock, eastNode.transform.position, eastNode.transform.rotation);
            _eastBlock.createdFrom  = Direction.w;
            _eastBlock.distFromCore = distFromCore;
            outPut.parentRoom       = this;
            outPut = _eastBlock.ConstructRoom(ref numDoors);
        }
        if (southNode.myType == Node.Type.roomNode)
        {
            RoomBlock _southBlock =
                Instantiate(southBlock, southNode.transform.position, southNode.transform.rotation);
            _southBlock.createdFrom  = Direction.n;
            _southBlock.distFromCore = distFromCore;
            outPut.parentRoom        = this;
            outPut = _southBlock.ConstructRoom(ref numDoors);
        }
        if (westNode.myType == Node.Type.roomNode)
        {
            RoomBlock _westBlock =
                Instantiate(westBlock, westNode.transform.position, westNode.transform.rotation);
            _westBlock.createdFrom  = Direction.e;
            _westBlock.distFromCore = distFromCore;
            outPut.parentRoom       = this;
            outPut = _westBlock.ConstructRoom(ref numDoors);
        }
        #endregion

        //--------------------------
        //generate walls
        //--------------------------
        if (northNode.myType == Node.Type.secretDoorNode || northNode.myType == Node.Type.wallNode)
        {
            /*create a wall room block*/
        }
        if (eastNode.myType == Node.Type.secretDoorNode || northNode.myType == Node.Type.wallNode)
        {
            /*create a wall room block*/
        }
        if (southNode.myType == Node.Type.secretDoorNode || northNode.myType == Node.Type.wallNode)
        {
            /*create a wall room block*/
        }
        if (westNode.myType == Node.Type.secretDoorNode || northNode.myType == Node.Type.wallNode)
        {
            /*create a wall room block*/
        }

        //--------------------------
        //fill the room
        //--------------------------
        FillOutRoom();


        return(outPut);
    }