Godot Version
4.3
Question
So i have some code to spawn prebuilt rooms, the problem is that some of them overlap with other rooms. I want to be able to detect when a room is going to overlap and change it to another room that can fit. How would i go about doing this?
Here is my code for spawning rooms if that helps:
var Int_Rooms_Up: Array = [load("res://Scenes/Rooms/Up/Int_Rooms/Int_Room1.tscn"), load("res://Scenes/Rooms/Up/Int_Rooms/Int_Room2.tscn")]
var End_Rooms_Up: Array = [load("res://Scenes/Rooms/Up/End_Rooms/EndRoom1.tscn")]
var Enemies: Array = [preload("res://Scenes/Enemies/screen_enemy.tscn")]
#Types and list of rooms
var room: Node2D
func _ready() -> void:
spawn_rooms()
#Activates the func that spawns the rooms
func spawn_rooms() -> void:
var end_chance:int = randi_range(1, 12)
if Global.rooms_left <= 1 or end_chance == 1:
print("end")
room = End_Rooms_Up.pick_random().instantiate()
if Global.rooms_left > 1 and end_chance != 1:
print("int")
room = Int_Rooms_Up.pick_random().instantiate()
room.global_position = get_parent().global_position + Vector2(0, -16)
get_parent().get_parent().get_parent().get_parent().add_child.call_deferred(room)
and here is a picture of the rooms overlaping: