本文整理汇总了C#中QuadTree.GenerateZones方法的典型用法代码示例。如果您正苦于以下问题:C# QuadTree.GenerateZones方法的具体用法?C# QuadTree.GenerateZones怎么用?C# QuadTree.GenerateZones使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QuadTree
的用法示例。
在下文中一共展示了QuadTree.GenerateZones方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateZones
// Procedurally generate QuadTrees
// Make a maximum of "max_depth" levels of depth
public void GenerateZones(int depth, int max_depth)
{
Debug.Log("Generate Zones, depth = " + depth + ", max = " + max_depth + " " + boundary.ToString());
// Reached max depth
if (depth > max_depth) return;
// If there's no place for 4 rooms, exit
if (boundary.half.x * 2.0f < DungeonGenerator.ROOM_MIN_SIZE*2) return;
if (boundary.half.y * 2.0f < DungeonGenerator.ROOM_MIN_SIZE*2) return;
// Try to make a slice capable of generating 4 more rooms
// If we can't manage to make it in "10" tries, exit
XY slice = new XY();
bool new_slice = RandomSlice(1,10,ref slice);
if (new_slice == false) return;
// Place QuadTree children
AABB aabb1 = new AABB();
XY size = new XY(slice.x - boundary.Left (), boundary.Top() - slice.y);
aabb1.center = new XY(slice.x - size.x/2.0f, slice.y + size.y/2.0f);
aabb1.half = new XY(size.x/2.0f,size.y/2.0f);
if (aabb1.half.x*2.0f >= DungeonGenerator.ROOM_MIN_SIZE && aabb1.half.y*2.0f >= DungeonGenerator.ROOM_MIN_SIZE)
{
Debug.Log("Creating north west quadtree");
northWest = new QuadTree(aabb1);
northWest.GenerateZones(depth+1,max_depth);
}
AABB aabb2 = new AABB();
size = new XY(boundary.Right() - slice.x, boundary.Top() - slice.y);
aabb2.center = new XY(slice.x + size.x/2.0f, slice.y + size.y/2.0f);
aabb2.half = new XY(size.x/2.0f,size.y/2.0f);
if (aabb2.half.x*2.0f >= DungeonGenerator.ROOM_MIN_SIZE && aabb2.half.y*2.0f >= DungeonGenerator.ROOM_MIN_SIZE)
{
Debug.Log("Creating north east quadtree");
northEast = new QuadTree(aabb2);
northEast.GenerateZones(depth+1,max_depth);
}
AABB aabb3 = new AABB();
size = new XY(slice.x - boundary.Left (), slice.y - boundary.Bottom());
aabb3.center = new XY(slice.x - size.x/2.0f, slice.y - size.y/2.0f);
aabb3.half = new XY(size.x/2.0f,size.y/2.0f);
if (aabb3.half.x*2 >= DungeonGenerator.ROOM_MIN_SIZE && aabb3.half.y*2 >= DungeonGenerator.ROOM_MIN_SIZE)
{
Debug.Log("Creating south west quadtree");
southWest = new QuadTree(aabb3);
southWest.GenerateZones(depth+1,max_depth);
}
AABB aabb4 = new AABB();
size = new XY(boundary.Right() - slice.x, slice.y - boundary.Bottom());
aabb4.center = new XY(slice.x + size.x/2.0f, slice.y - size.y/2.0f);
aabb4.half = new XY(size.x/2.0f,size.y/2.0f);
if (aabb4.half.x*2 >= DungeonGenerator.ROOM_MIN_SIZE && aabb4.half.y*2 >= DungeonGenerator.ROOM_MIN_SIZE)
{
Debug.Log("Creating south east quadtree");
southEast = new QuadTree(aabb4);
southEast.GenerateZones(depth+1,max_depth);
}
}
示例2: GenerateZones
// Procedurally generate QuadTrees
// Make a maximum of "max_depth" levels of depth
public void GenerateZones(int depth, int max_depth)
{
// Reached max depth
if (depth > max_depth) return;
// No place for 4 rooms? return
if (boundary.half.x < roomRealMinSize) return;
if (boundary.half.y < roomRealMinSize) return;
// Random possibilty of not generating zone
int r = Random.Range(0,100);
if (r < dungeon.CHANCE_STOP && depth > 1) return;
// Try to make a slice with space for 4 rooms
// Retry "N=SLICE_TRIES" times
XY slice = new XY();
bool new_slice = RandomSlice(1,dungeon.SLICE_TRIES,ref slice);
if (new_slice == false) return;
// Generate children QuadTrees
// NORTHWEST
AABB aabb1 = new AABB();
XY size = new XY(slice.x - boundary.Left (), boundary.Top() - slice.y);
aabb1.center = new XY(slice.x - size.x/2.0f, slice.y + size.y/2.0f);
aabb1.half = new XY(size.x/2.0f,size.y/2.0f);
northWest = new QuadTree(aabb1);
northWest.parent = this;
northWest.GenerateZones(depth+1,max_depth);
// NORTHEAST
AABB aabb2 = new AABB();
size = new XY(boundary.Right() - slice.x, boundary.Top() - slice.y);
aabb2.center = new XY(slice.x + size.x/2.0f, slice.y + size.y/2.0f);
aabb2.half = new XY(size.x/2.0f,size.y/2.0f);
northEast = new QuadTree(aabb2);
northEast.parent = this;
northEast.GenerateZones(depth+1,max_depth);
// SOUTHWEST
AABB aabb3 = new AABB();
size = new XY(slice.x - boundary.Left (), slice.y - boundary.Bottom());
aabb3.center = new XY(slice.x - size.x/2.0f, slice.y - size.y/2.0f);
aabb3.half = new XY(size.x/2.0f,size.y/2.0f);
southWest = new QuadTree(aabb3);
southWest.parent = this;
southWest.GenerateZones(depth+1,max_depth);
// SOUTEAST
AABB aabb4 = new AABB();
size = new XY(boundary.Right() - slice.x, slice.y - boundary.Bottom());
aabb4.center = new XY(slice.x + size.x/2.0f, slice.y - size.y/2.0f);
aabb4.half = new XY(size.x/2.0f,size.y/2.0f);
southEast = new QuadTree(aabb4);
southEast.parent = this;
southEast.GenerateZones(depth+1,max_depth);
}