How can I make a floor generation in a roguelike game with a side view through already created rooms using Tilemap?

Godot 4.3

let’s say I created a square room and I need to connect it with other rooms, I don’t understand how to make corridors, I tried to put a 2D marker in the places where they should be and wrote in the code so that the rooms were created marker by marker, but in the end they were all scattered chaotically. I don’t care whether it will be through “doors” like in isaac or corridors like in etg, I just don’t understand how to do this. I want to have a set of ready-made rooms that will randomly join together. All the guides that I came across on the Internet did not suit me for various reasons.

I have two ideas, one is to have 16 room models and choose from them at random, and two, to create the ceiling and floor of the rooms and then create the walls one by one blocked or with hallways
I think the first way is very convenient

Yes, I have 16 rooms drawn using a tilemap, how exactly should I connect them? create another “mini room” that will connect the rooms at the exit points? But I don’t understand how to implement this in code.

Please share your code that you tried to write and didn’t work for you, we can try to help you improve it.

PS: similar topic to this one

Sorry for the long answer, I wanted to solve this problem myself but I couldn’t. The current result is that when you start the rooms are randomly scattered around the scene and it’s not clear by what principle… My original idea was to have rooms drawn with a tilemap, and for the OGs to connect to the crydor (which is also essentially a room) via Marker2D, located on the “holes” in the rooms. But in the end, nothing works. I’m ready to change the original structure of the scenes or whatever it takes to make it work. I don’t understand anything, I’ll soon be tearing my hair out and banging my head against the wall. I would send a video but it tells me that new users can’t send videos. I don’t know how to become a non-new user.
my code(in separate scene "levelGenerateEtage1’):
extends Node2D

@export var rooms: Array[PackedScene]
@export var corridor_scene: PackedScene

var spawned_rooms: Array =

func _ready():
print(“Start”)
generate_level()

func generate_level():
if rooms.is_empty():
print(“No rooms assigned!”)
return

var max_rooms = 7
var first_room = spawn_room(Vector2.ZERO)
if not first_room:
	print("Failed to spawn first room")
	return

spawned_rooms.append(first_room)

while spawned_rooms.size() < max_rooms:
	var parent_room = spawned_rooms.pick_random()
	var parent_door = find_door(parent_room)

	if parent_door:
		var new_room = spawn_room(parent_door.global_position)
		if new_room:
			var new_door = find_door(new_room)
			if new_door:
				spawn_corridor(parent_door.global_position, new_door.global_position)
				spawned_rooms.append(new_room)

func spawn_room(position: Vector2):
var room_scene = rooms.pick_random()
if not room_scene:
print(“No room scene found”)
return null

if not can_spawn_room(position):
	return null

var room_instance = room_scene.instantiate()
add_child(room_instance)
room_instance.global_position = position
print("Spawned room at:", position)

return room_instance

func can_spawn_room(position: Vector2) → bool:
for room in spawned_rooms:
if room.global_position.distance_to(position) < 50:
return false
return true

func find_door(room):
if not room:
return null

var door = room.get_node_or_null("Door")
if door and door is Marker2D:
	return door

print("No door marker found in", room.name)
return null

func spawn_corridor(start_pos: Vector2, end_pos: Vector2):
if not corridor_scene:
print(“No corridor scene assigned!”)
return

var corridor_instance = corridor_scene.instantiate()
add_child(corridor_instance)
corridor_instance.global_position = (start_pos + end_pos) / 2
print("Spawned corridor between:", start_pos, "and", end_pos)