(original untiy) random Dungeon Generation algorithm (i)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.