Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Dead_lucky_32 |
I dont see the problem if anyone could help that would be great, please and thank you.
func build_level():
# Start with blank map
rooms.clear()
map.clear()
tile_map.clear()
level_size = LEVEL_SIZES[level_num]
for x in range(level_size.x):
map.append([])
for y in range(level_size.y):
map[x].append([Tile.Stone])
tile_map.set_cell(x, y, Tile.Stone)
var free_regions = [Rect2(Vector2(2, 2), level_size - Vector2(4, 4))]
var num_rooms = LEVEL_ROOM_COUNTS[level_num]
for i in range(num_rooms):
add_room(free_regions)
if free_regions.empty():
break
connect_rooms()
Here are is the second Function where the problem keeps saying it is
func connect_rooms():
# Build an AStar graph of the area where we can add corridors
var stone_graph = AStar.new()
var point_id = 0
for x in range(level_size.x):
for y in range(level_size.y):
if map[x][y] == Tile.Stone:
stone_graph.add_point(point_id, Vector3(x, y, 0))
# Connect to the Left if also Stone
if x > 0 && map[x - 1][y] == Tile.Stone:
var left_point = stone_graph.get_closest_point(Vector3(x - 1, y, 0))
stone_graph.connect_points(point_id, left_point)
# Connect to the Above if also Stone
if y > 0 && map[x][y - 1] == Tile.Stone:
var above_point = stone_graph.get_closest_point(Vector3(x, y - 1, 0))
stone_graph.connect_points(point_id, above_point)
point_id += 1
# Build an AStar graph of room connection
var room_graph = AStar.new()
point_id = 0
for room in rooms:
var room_center = room.position + room.size / 2
room_graph.add_point(point_id, Vector3(room_center.x, room_center.y, 0))
point_id += 1
# Add random connections until everything is connected
while !is_everything_connected(room_graph):
add_random_connection(stone_graph, room_graph)