示例#1
0
    public void DrawRooms(Subdungeon subdungeon)
    {
        //Instantiates the tiles on the tiles into the game based on the construction of the rooms from CreateRooms()
        if (subdungeon == null)
        {
            return;
        }
        if (subdungeon.isLeaf())
        {
            for (int i = (int)subdungeon.room.x; i < subdungeon.room.xMax; i++)
            {
                for (int j = (int)subdungeon.room.y; j < subdungeon.room.yMax; j++)
                {
                    int        randIndex   = Random.Range(0, floorTiles.Length); //pick a random tile from the array
                    Vector3    pos         = new Vector3(i, j, 0f);              //the position where the tile will be placed
                    GameObject newInstance = Instantiate(floorTiles[randIndex], pos, Quaternion.identity) as GameObject;
                    newInstance.transform.SetParent(transform);

                    boardPosFloor[i, j] = newInstance;
                }
            }
        }
        else
        {
            DrawRooms(subdungeon.left);
            DrawRooms(subdungeon.right);
        }
    }
示例#2
0
 public void CreateBSP(Subdungeon subdungeon)
 //Create a BinarySpacePartition from a given subdungeon
 {
     if (subdungeon.isLeaf())
     {
         if (subdungeon.rect.width > maxRoomSize || subdungeon.rect.height > maxRoomSize || Random.Range(0.0f, 1.0f) > 0.25)
         {
             if (subdungeon.split(minRoomSize, maxRoomSize))
             {
                 CreateBSP(subdungeon.left);
                 CreateBSP(subdungeon.right);
             }
         }
     }
 }