|
|
@ -54,6 +54,8 @@ def map_generator(n):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
room_side = 1000
|
|
|
|
room_side = 1000
|
|
|
|
|
|
|
|
change_side = {'T':'D','R':'L','D':'T','L':'R'}
|
|
|
|
|
|
|
|
deplacements = {'T':[0,-1],'R':[1,0],'D':[0,1],'L':[-1,0]}
|
|
|
|
|
|
|
|
|
|
|
|
unique_filenames,assembly,back_path = fetch_rooms('./maps/rooms/')
|
|
|
|
unique_filenames,assembly,back_path = fetch_rooms('./maps/rooms/')
|
|
|
|
#assembly = {'T/R/D/L':[(label1,path1),(label2,path2),...]}
|
|
|
|
#assembly = {'T/R/D/L':[(label1,path1),(label2,path2),...]}
|
|
|
@ -72,7 +74,8 @@ def map_generator(n):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
counter = 0
|
|
|
|
counter = 0
|
|
|
|
while counter < n:
|
|
|
|
retry = 0
|
|
|
|
|
|
|
|
while counter <= n:
|
|
|
|
|
|
|
|
|
|
|
|
# select the next direction, can't be the direction of arrival
|
|
|
|
# select the next direction, can't be the direction of arrival
|
|
|
|
if len(current_label) > 1:
|
|
|
|
if len(current_label) > 1:
|
|
|
@ -82,26 +85,17 @@ def map_generator(n):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Select the next room
|
|
|
|
# Select the next room
|
|
|
|
next_label,next_room = random.choice(assembly[dir_next])
|
|
|
|
if counter < n: # The next room is not the final room.
|
|
|
|
asset = pygame.image.load(next_room).convert_alpha()
|
|
|
|
next_label,next_room = random.choice(assembly[dir_next])
|
|
|
|
mask = pygame.mask.from_surface(asset)
|
|
|
|
asset = pygame.image.load(next_room).convert_alpha()
|
|
|
|
|
|
|
|
|
|
|
|
# Compute the position of the next tile
|
|
|
|
|
|
|
|
if dir_next == 'T':
|
|
|
|
|
|
|
|
next_position = [position[0],position[1]-room_side]
|
|
|
|
|
|
|
|
dir_from = 'D'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if dir_next == 'R':
|
|
|
|
else:
|
|
|
|
next_position = [position[0]+room_side,position[1]]
|
|
|
|
# The next room is the finale room.
|
|
|
|
dir_from = 'L'
|
|
|
|
asset = unique_rooms[change_side[dir_next]]
|
|
|
|
|
|
|
|
|
|
|
|
if dir_next == 'D':
|
|
|
|
|
|
|
|
next_position = [position[0],position[1]+room_side]
|
|
|
|
|
|
|
|
dir_from = 'T'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if dir_next == 'L':
|
|
|
|
mask = pygame.mask.from_surface(asset)
|
|
|
|
next_position = [position[0]-room_side,position[1]]
|
|
|
|
next_position = [position[0]+room_side*deplacements[dir_next][0],position[1]+room_side*deplacements[dir_next][1]]
|
|
|
|
dir_from = 'R'
|
|
|
|
dir_from = change_side[dir_next]
|
|
|
|
|
|
|
|
|
|
|
|
# Check if we are not overwriting an existing room and store the current one.
|
|
|
|
# Check if we are not overwriting an existing room and store the current one.
|
|
|
|
if next_position not in positions:
|
|
|
|
if next_position not in positions:
|
|
|
@ -114,16 +108,15 @@ def map_generator(n):
|
|
|
|
current_label = next_label
|
|
|
|
current_label = next_label
|
|
|
|
position = next_position
|
|
|
|
position = next_position
|
|
|
|
positions.append(position)
|
|
|
|
positions.append(position)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
retry +=1
|
|
|
|
|
|
|
|
if retry > 10:
|
|
|
|
|
|
|
|
raise ValueError("Too much retries")
|
|
|
|
|
|
|
|
|
|
|
|
background = pygame.image.load(back_path).convert()
|
|
|
|
background = pygame.image.load(back_path).convert()
|
|
|
|
|
|
|
|
|
|
|
|
if not check_map(carte):
|
|
|
|
if not check_map(carte):
|
|
|
|
raise ValueError("Invalid Map.")
|
|
|
|
raise ValueError("Invalid Map.")
|
|
|
|
else:
|
|
|
|
|
|
|
|
print("Map checked and valid!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for room in carte:
|
|
|
|
|
|
|
|
print(room)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return(carte,(int(room_side/2),int(room_side/2)),background)
|
|
|
|
return(carte,(int(room_side/2),int(room_side/2)),background)
|
|
|
|
|
|
|
|
|
|
|
|