Game Development

second – Determine doorways to partition a group of partitions with gaps into rooms

This can be a variation of an algorithm I used myself in a grid primarily based randomly generated stage (a merely 0= empty 1= wall grid) to put doorways.

Discovering doable doorway tiles

There are some easy guidelines relying on the encompassing tiles to find out whether or not or not there could be a door.

The tile itself should be empty and have no less than two neighboring wall tiles that aren’t linked with one another (solely throughout the neighbors).

For this you’ll be able to look at the neighboring tiles counter-clockwise. Everytime you look at a “wall” tile after inspecting an “empty” tile you enhance a counter by 1. If that counter is strictly 2 after one full circle (inspecting the primary tile a second time as final tile). you might have a doable doorway.

Nonetheless it will produce “to many” doorways, typically adjescant to one another. In your instance the door on the decrease edge has two doable doorway tiles. The “actual” doorway you marked as purple within the picture and the empty tile immediately above that.

Discovering the appropriate doorway tiles

Now that now we have all doable doorway tiles (right here X however possibly marked with -1 within the array)

6AAEAAC  
5001005  
50X0X05  
780002D  
50X0X05  
5005X05  
3AA9X29 

To unravel this downside you could possibly create a “rating” on how the perfect/worst doorway conditions appear to be. For this rating we will proceed utilizing damaging numbers within the array, e.g. -1 being “the perfect” doorway and “-F” being the worst

  1. The “finest” doorway tile is a tile that has precisely two adjescant wall tiles which might be precisely reverse of one another and solely empty tiles as neighbors in any other case.
  2. Subsequent come these with greater than two adjescant wall tiles however who nonetheless have two precisely opposing wall tiles
  3. Subsequent people who have precisely two adjescant wall tiles which aren’t precisely reverse of one another
  4. And lastly all remaining doorways.

With the rating in place we will at all times delete the more serious of two adjescant doorway tiles or a random one in case of equal rating.

This could depart you with properly positioned doorways.

About the author

Theme control panel

Leave a Comment