Difference between revisions of "Irregular Shaped Rooms"

From RogueBasin
Jump to navigation Jump to search
 
(Method for generating irregular polygons or caves)
Line 1: Line 1:
Rectangular or any type of regularly shaped room in roguelike games has always bothered me, so instead of working I came up with a simple way to generate irregular, more "natural" looking caves, such as the ones featured below.
Rectangular or any type of regularly shaped room in roguelike games has always bothered me, so today, instead of working I came up with a simple way to generate irregular polygons, or more "natural" looking caves. A few examples are shown below.


http://www.evilscience.co.uk/wp-content/uploads/2008/05/rooms2.JPG
http://www.evilscience.co.uk/wp-content/uploads/2008/05/rooms2.JPG
Line 5: Line 5:
== How it works ==
== How it works ==


The basic concept is simple enough: enclose an area in 4 rectangles, randomly choose at least 1 point in each of the rectangles, join each of those points together using a Bresenham's Line algorhithm, and then fill in the enclosed area, as illustrated below.
The basic concept is simple enough:  


http://www.evilscience.co.uk/wp-content/uploads/2008/05/rooms1.JPG
# Enclose an area in 4 rectangles (left picture),
# Randomly choose at least 1 point in each of the rectangles (second from left),
## Order the points in Rectangle A by their X value, from low to high, add them to the main list.
## Order the points in Rectangle B by their Y value, from low to high, add them to the main list.
## Order the points in Rectangle C by their X value, for high to low, add them to the main list.
## Order the points in Rectangle D by their Y value, from high to low, add them to the main list.
# Starting with the first point in the main list use [[Bresenham's_Line_Algorithm | Bresenham's Line algorithm]] to connect it to the next point, and so on, until you reach the end of the list. Connect the last point to the first point of the list, to completely enclosed the shape (third from left picture). The way the points have been arranged means they are connected in a clockwise direction (right picture).
 
http://www.evilscience.co.uk/wp-content/uploads/2008/05/rooms1.jpg
 
Step 2, really is the most important part, so here it is again.
: Moving from left to right, the points in Rectangle A are joined, then moving from top to bottom the points in Rectangle B are joined, then moving from right to left Rectangle C's points are joined and finally, from bottom to top Rectangle D's points are joined. Basically, we move around the rectangles clockwise joining the points as we go. This is the most important bit to get right, else the polygon produced is not enclosed.

Revision as of 22:37, 19 May 2008

Rectangular or any type of regularly shaped room in roguelike games has always bothered me, so today, instead of working I came up with a simple way to generate irregular polygons, or more "natural" looking caves. A few examples are shown below.

rooms2.JPG

How it works

The basic concept is simple enough:

  1. Enclose an area in 4 rectangles (left picture),
  2. Randomly choose at least 1 point in each of the rectangles (second from left),
    1. Order the points in Rectangle A by their X value, from low to high, add them to the main list.
    2. Order the points in Rectangle B by their Y value, from low to high, add them to the main list.
    3. Order the points in Rectangle C by their X value, for high to low, add them to the main list.
    4. Order the points in Rectangle D by their Y value, from high to low, add them to the main list.
  3. Starting with the first point in the main list use Bresenham's Line algorithm to connect it to the next point, and so on, until you reach the end of the list. Connect the last point to the first point of the list, to completely enclosed the shape (third from left picture). The way the points have been arranged means they are connected in a clockwise direction (right picture).

rooms1.jpg

Step 2, really is the most important part, so here it is again.

Moving from left to right, the points in Rectangle A are joined, then moving from top to bottom the points in Rectangle B are joined, then moving from right to left Rectangle C's points are joined and finally, from bottom to top Rectangle D's points are joined. Basically, we move around the rectangles clockwise joining the points as we go. This is the most important bit to get right, else the polygon produced is not enclosed.