Reprint Annotated Source: http://www.cnblogs.com/m-f-s/p/6509135.html
According to the http://www.gamelook.com.cn/2015/12/239245 translation finishing implementation:
Generate room
First of all, you want to generate some wide and high different rooms, randomly placed in one circle. Tkdev's algorithm uses a more common method of randomly generating room sizes, which I think is a good idea, because it can bring you more parameters to use, using different aspect ratios and standard deviations to bring the different appearance of the Vice local jail.
I use this function to return a random point within the radius of the _r circle:
public static Vector2 randombycircle (float _r)
{
float a = random.range (0, 1f); A, b random angle Draw circle
Float B = Random.range (0, 1f);
float temp = 0;
if (b < a)
{
temp = A;
A = b;
b = temp;
}
Calculate coordinates
float x = b * _r * MATHF.COS (2 * Mathf.pi * A/b); x, y equals room width height/position coordinates
Float y = b * _r * Mathf.sin (2 * Mathf.pi * A/b);
Vector2 pos = new Vector2 ((int) x, (int) y);
return POS;
}
So you can get the location of the room, again with this function randomly can get the length of the room width, of course, you can also use Random.range method random room length and width.
The returned POS needs to be rounded, 0 processed (the room length is an integer, the room length or width is 0), and I do this:
Rounding a point up (with no decimal points for coordinates)
size.x = Mathf.ceil (gsize.x);
Size.y = Mathf.ceil (GSIZE.Y);
Prevent rounding to 0
if (gsize.x = = 0) size.x = Mathf.ceil (Random.range (4, 10));
if (gsize.y = = 0) size.y = Mathf.ceil (Random.range (4, 10));
The number of the last room generated to be processed must take its absolute value to prevent negative:
Room. Getcomponent<boxcollider2d> (). Size = new Vector2 ((int) mathf.abs (size.x), (int) mathf.abs (size.y));
So you can get this diagram:
You can set a preset picture like this:
So that the next step is to disperse the room.
Reprint Annotated Source: http://www.cnblogs.com/m-f-s/p/6509135.html
(original untiy) random Dungeon Generation algorithm (i)