Connecting rooms with wider corridors for a Rogue-like map

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Lothrinn

Hello everyone !

I followed KidsCanCode’s tutorial on procedural dungeon generation. In the tutorial, he makes corridors connecting each room with this part of the code :

func carve_path(pos1, pos2):
#Carve a path between 2 points
var x_diff = sign(pos2.x - pos1.x)
var y_diff = sign(pos2.y - pos1.y)
if x_diff == 0: x_diff = pow(-1.0, randi() % 2)
if y_diff == 0: y_diff = pow(-1.0, randi() % 2)
#choose either x/y or y/x
var x_y = pos1
var y_x = pos2
if (randi() % 2) > 0:
	x_y = pos2
	y_x = pos1
for x in range(pos1.x, pos2.x, x_diff):
	Map.set_cell(x, x_y.y, 0)
	Map.set_cell(x, x_y.y + y_diff, 0) #widen corridor
for y in range(pos1.y, pos2.y, y_diff):
	Map.set_cell(y_x.x, y, 0)
	Map.set_cell(y_x.x + x_diff, y, 0) #widen corridor

This code makes his corridors being 2 tiles wide, however I would like them to be 4 wide since my map uses an autotile and his’ uses single tiles. I tried to mess up with this for a bit but can’t figure out how to do it. Could anyone please help me ? :slight_smile:

could you link the tutorial?

Millard | 2020-06-07 19:15

thanks, I’ll have to look at them. :slight_smile:

Millard | 2020-06-08 14:57

:bust_in_silhouette: Reply From: njamster

The comments are pretty self explanatory, aren’t they?

# ...
for x in range(pos1.x, pos2.x, x_diff):
    Map.set_cell(x, x_y.y, 0)
    Map.set_cell(x, x_y.y + 1*y_diff, 0) #widen corridor
    Map.set_cell(x, x_y.y + 2*y_diff, 0) #widen corridor more
    Map.set_cell(x, x_y.y + 3*y_diff, 0) #widen corridor even more
for y in range(pos1.y, pos2.y, y_diff):
    Map.set_cell(y_x.x, y, 0)
    Map.set_cell(y_x.x + 1*x_diff, y, 0) #widen corridor
    Map.set_cell(y_x.x + 2*x_diff, y, 0) #widen corridor more
    Map.set_cell(y_x.x + 3*x_diff, y, 0) #widen corridor even more

This is widening the corridor only to the right / bottom.

Here’s a version of a 3-tile-corridor widened by one tile on both sides:

# ...
for x in range(pos1.x, pos2.x, x_diff):
    Map.set_cell(x, x_y.y, 0)
    Map.set_cell(x, x_y.y - y_diff, 0) #widen corridor up
    Map.set_cell(x, x_y.y + y_diff, 0) #widen corridor down
for y in range(pos1.y, pos2.y, y_diff):
    Map.set_cell(y_x.x, y, 0)
    Map.set_cell(y_x.x - x_diff, y, 0) #widen corridor up
    Map.set_cell(y_x.x + x_diff, y, 0) #widen corridor down

Thank you for your answer ! I actually tried to put other lines of Map.set_cell() but without adding 1, 2 or 3 and then multiplying it so the best I could achieve was that only some corridors were being 3 wide and all of the others stayed 2 wide and it was driving me crazy lol

Lothrinn | 2020-06-06 12:36