
Having ~45 minutes total free today, I decided to do what I suggested; things that would make the algorithm more useful (from my last post).
The changes I made were:
The added functions were ListIntersect and ListInside, and both are easy to follow:
bool ListInside(Rectangle *rects[16], int x, int y, int count)
{
for (int i = 0; i = rects[i]->X &&
x X + rects[i]->W &&
y >= rects[i]->Y &&
y Y + rects[i]->H)
{
//cout
The first rectangle insertion was adjusted, and for a certain number of iterations you add more rectangles:
//first rectangle
x = Next(128);
y = Next(128);
r = Next(32) + 32;
rectangles[0] = new Rectangle();
rectangles[0]->X = x - r/2;
rectangles[0]->Y = y - r/2;
rectangles[0]->H = r;
rectangles[0]->W = r;
count = 1;
//additional rectangles
// at least 6 more
// at most 15 more
int iterations = 6 + Next(9);
for (int i = 0; i X = x - r/2;
rectangles[count]->Y = y - r/2;
rectangles[count]->H = r;
rectangles[count]->W = r;
int maxiter = 100;
while (ListIntersects(rectangles, rectangles[count], count) && maxiter >= 0)
{
rectangles[count]->X = Next(128) - r/2;
rectangles[count]->Y = Next(128) - r/2;
maxiter--;
}
count++;
}
The changes to the corridors was making the corridors go from the first rectangle to the second last, and make a path from the current rectangle to the next rectangle, swapping each time between the 2 methods used previously between 1&2 and 2&3. The result of which you can see for yourself.
All in all, the algorithm is still simple, and it is once again available on my GitHub.
3 comments
ah its not wordpress, its
Submitted by MarkyMark (not verified) on Wed, 05/16/2012 - 04:09ah its not wordpress, its drupal right?
Yeah, it is Drupal, the only
Submitted by edg3 on Mon, 05/21/2012 - 13:51Yeah, it is Drupal, the only thing I dislike is how between versions everything breaks :(
what a great post, just
Submitted by HardyLatte (not verified) on Thu, 05/17/2012 - 00:59what a great post, just signed up to your RSS feed and hope to read more of your posts in the future. keep it up!