Close remaining open paths
This commit is contained in:
parent
6430830630
commit
9795abe51d
2 changed files with 27 additions and 3 deletions
|
@ -149,7 +149,7 @@ class Player():
|
||||||
|
|
||||||
if keystate[self.key_left]:
|
if keystate[self.key_left]:
|
||||||
self.speed[0] -= acceleration
|
self.speed[0] -= acceleration
|
||||||
if self.speed[0] < -cap_speed: self.speed[0] = -cap_speed
|
if self.speed[0] < -cap_speed: self.speed[0] = -cap_speed
|
||||||
|
|
||||||
if keystate[self.key_right]:
|
if keystate[self.key_right]:
|
||||||
self.speed[0] += acceleration
|
self.speed[0] += acceleration
|
||||||
|
|
28
utils.py
28
utils.py
|
@ -72,6 +72,8 @@ def map_generator(n):
|
||||||
mask = pygame.mask.from_surface(start_room)
|
mask = pygame.mask.from_surface(start_room)
|
||||||
carte = [(start_room,mask,position)]
|
carte = [(start_room,mask,position)]
|
||||||
|
|
||||||
|
open_paths = []
|
||||||
|
|
||||||
|
|
||||||
counter = 0
|
counter = 0
|
||||||
retry = 0
|
retry = 0
|
||||||
|
@ -82,7 +84,13 @@ def map_generator(n):
|
||||||
dir_next = random.choice(current_label.replace(dir_from,''))
|
dir_next = random.choice(current_label.replace(dir_from,''))
|
||||||
else:
|
else:
|
||||||
dir_next = current_label
|
dir_next = current_label
|
||||||
|
dir_from = ''
|
||||||
|
|
||||||
|
# stor open paths for later closing
|
||||||
|
for other_direction in current_label.replace(dir_from,'').replace(dir_next,''):
|
||||||
|
other_dir_from = change_side[other_direction]
|
||||||
|
other_position = [a+room_side*b for a,b in zip(position,deplacements[other_direction])]
|
||||||
|
open_paths.append((other_dir_from,other_position))
|
||||||
|
|
||||||
# Select the next room
|
# Select the next room
|
||||||
if counter < n: # The next room is not the final room.
|
if counter < n: # The next room is not the final room.
|
||||||
|
@ -113,10 +121,26 @@ def map_generator(n):
|
||||||
if retry > 10:
|
if retry > 10:
|
||||||
raise ValueError("Too much retries")
|
raise ValueError("Too much retries")
|
||||||
|
|
||||||
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 before closing paths.")
|
||||||
|
|
||||||
|
#Close all the open paths
|
||||||
|
for open_path in open_paths:
|
||||||
|
if open_path[1] not in positions:
|
||||||
|
room = unique_rooms[open_path[0]]
|
||||||
|
mask = pygame.mask.from_surface(room)
|
||||||
|
position = open_path[1]
|
||||||
|
carte.append((room,mask,position))
|
||||||
|
positions.append(position)
|
||||||
|
|
||||||
|
background = pygame.image.load(back_path).convert()
|
||||||
|
|
||||||
|
print("Open paths:")
|
||||||
|
print(open_paths)
|
||||||
|
|
||||||
|
if not check_map(carte):
|
||||||
|
raise ValueError("Invalid Map after closing paths.")
|
||||||
|
|
||||||
return(carte,(int(room_side/2),int(room_side/2)),background)
|
return(carte,(int(room_side/2),int(room_side/2)),background)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue