def generate_map():
#This creates a map filled with walls to be carved later
game_map = [[TILES["WALL"] for _ in range(MAP_WIDTH)] for _ in range(MAP_HEIGHT)]
# this stores the rooms
all_rooms = []
num_random_rooms = random.randint(10, 20) # Adjust as needed
# generates the rooms
for _ in range(num_random_rooms): #sets the ammount of rooms per floor may make random later but for now we move
width = random.randint(4,8)
height = random.randint(4,8)
x = random.randint(1, MAP_WIDTH - width - 1)
y = random.randint(1, MAP_HEIGHT - height - 1)
new_room = {"x":x, "y":y, "width": width, "height": height}
#checks for any over laps before placing the rooms hence the omega long parameter
#the any parameter checks if all the conditions inside it to see if any are true or false
if not any(
(new_room["x"] < room["x"] + room["width"] and
new_room["x"] + new_room["width"] > room["x"] and
new_room["y"] < room["y"] + room["height"] and
new_room["y"] + new_room["height"] > room["y"])
for room in all_rooms
):
#this is wwhat carves/ places the rooms with athe help of the dreaded nested for loop (doctos)
for y in range(new_room["y"], new_room["y"] + new_room["height"]):
for x in range(new_room["x"], new_room["x"] + new_room["width"]):
game_map[y][x] = TILES["FLOOR"]
all_rooms.append(new_room)
#this is what connects the rooms wth corridors
for i in range (1, len(all_rooms)):
# is i-1 because its the previous room, could also have made it so the current room is i +1 and make prev room be i but that makes less sense intuitively
prev_room = all_rooms[i -1]
curr_room = all_rooms[i]
#grabs the centers of each room so we knwo where to put the corridors
#standard stuff getting middle by adding and then dividing by 2 really if you need this reminder comment you should n be programming and should consider killing yourself
prev_center = (prev_room["x"]+ prev_room["width"] // 2, prev_room["y"] +prev_room["height"] // 2)
curr_center = (curr_room["x"] + curr_room["width"] // 2, curr_room["y"] +curr_room["height"] // 2)
#magic that makes the horizontal corridor
for x in range (min(prev_center[0], curr_center[0]), max(prev_center[0], curr_center[0])+ 1):
game_map[prev_center[1]][x] = TILES["FLOOR"]
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ vertical corridor
for y in range (min(prev_center[1], curr_center[1]), max(prev_center[1], curr_center[1])+ 1):
game_map[y][curr_center[0]] = TILES["FLOOR"]
return game_map