diff --git a/models.py b/models.py index 40546ac..eecb951 100644 --- a/models.py +++ b/models.py @@ -150,7 +150,6 @@ class Player(): if keystate[self.key_left]: self.speed[0] -= acceleration if self.speed[0] < -cap_speed: self.speed[0] = -cap_speed - print("PLOP") if keystate[self.key_right]: self.speed[0] += acceleration diff --git a/utils.py b/utils.py index a1bb975..6ae133d 100644 --- a/utils.py +++ b/utils.py @@ -54,6 +54,8 @@ def map_generator(n): """ 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/') #assembly = {'T/R/D/L':[(label1,path1),(label2,path2),...]} @@ -72,7 +74,8 @@ def map_generator(n): counter = 0 - while counter < n: + retry = 0 + while counter <= n: # select the next direction, can't be the direction of arrival if len(current_label) > 1: @@ -82,26 +85,17 @@ def map_generator(n): # Select the next room - next_label,next_room = random.choice(assembly[dir_next]) - asset = pygame.image.load(next_room).convert_alpha() + if counter < n: # The next room is not the final room. + next_label,next_room = random.choice(assembly[dir_next]) + asset = pygame.image.load(next_room).convert_alpha() + + else: + # The next room is the finale room. + asset = unique_rooms[change_side[dir_next]] + mask = pygame.mask.from_surface(asset) - - # 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': - next_position = [position[0]+room_side,position[1]] - dir_from = 'L' - - if dir_next == 'D': - next_position = [position[0],position[1]+room_side] - dir_from = 'T' - - if dir_next == 'L': - next_position = [position[0]-room_side,position[1]] - dir_from = 'R' + next_position = [position[0]+room_side*deplacements[dir_next][0],position[1]+room_side*deplacements[dir_next][1]] + dir_from = change_side[dir_next] # Check if we are not overwriting an existing room and store the current one. if next_position not in positions: @@ -114,16 +108,15 @@ def map_generator(n): current_label = next_label position = next_position positions.append(position) + else: + retry +=1 + if retry > 10: + raise ValueError("Too much retries") background = pygame.image.load(back_path).convert() if not check_map(carte): 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)