Okay, I looked at the code, and I think the issue is in your check for unique room function. From what I can gather, the function is for making sure no two rooms are in the same position, correct? If so, then I would suggest changing the function to the following:
# Returns a boolean if the passed-in room node's position overlaps an already existing room
func check_for_unique_room(new_room):
# Go through all the rooms
for room in rooms:
# Don't process the passed-in room.
if new_room == room:
continue
# Get the position of the room using its name by splitting the name up
var room_data = room.name.split("_", true)
# the position should be on the third [2] and fourth [3] indexes
# (first is room, second is the room number)
var room_position_x = room_data[2]
var room_position_y = room_data[3]
# do the same for the passed-in room
var new_room_data = new_room.name.split("_", true)
var new_room_position_x = new_room_data[2]
var new_room_position_y = new_room_data[3]
# compare!
if (new_room_position_x == room_position_x and new_room_position_y == room_position_y):
# overlap! Return false!
return false
# If we didn't find any collisions/overlaps, then return true
return true
Then, I would recommend making the following modifications to the generate_dungeon function:
# for performance reasons, the room should probably be loaded outside of the function.
var dungeon_room_scene = preload("res://World/DungeonRoom.tscn")
func generate_dungeon():
randomize()
while rooms.size() <= roomCount:
# Not the first room...
if rooms.empty() == false:
var new_room = dungeon_room_scene.instance()
# set the name of the room
new_room.set_name("room_" + str(rooms.size()) + "_" + str(walker["x"]) + "_" + str(walker["y"]))
# make sure the room position is unique
var is_room_unique = check_for_unique_room(new_room)
# if it is not unique, then just continue
if is_room_unique == false:
continue
else:
# add the new room to the list, and then the scene
rooms.push_back(new_room)
add_child(new_room)
# calculate the position
var room_pos = Vector2((335 * 1.5)*walker["x"], (195 * 1.5)*walker["y"])+Vector2(-335 * 1.5, -195 * 1.5)
# set the position
new_room.set_position(room_pos)
# make the walker step!
walker_step()
# The first room...
else:
var new_room = dungeon_room_scene.instance()
# set the name of the room
new_room.set_name("room_" + str(rooms.size()) + "_" + str(walker["x"]) + "_" + str(walker["y"]))
# add the new room to the list and then the scene
rooms.push_back(new_room)
add_child(new_room)
# set the position
new_room.set_position(Vector2(0, 0))
# if there is no player, then spawn one!
if get_tree().get_root().has_node("Player") == false:
player = load("res://Player/Player.tscn").instance()
player.set_position(rooms[0].get_position() + Vector2((320 /2), (180/2)))
player.show()
get_parent().call_deferred("add_child", player)
print("Player = " + str(player.get_position()))
# make the walker step!
walker_step()
(You may eventually need to add a condition to make sure the code does not loop endlessly, but that's another problem for another day, and shouldn't be an issue in most cases.)
The rest looks fine though, and with those modifications, I believe it should work :smile: