diff --git a/maps/rooms/RDL-1.png b/maps/rooms/RDL-1.png new file mode 100644 index 0000000..2822b6e Binary files /dev/null and b/maps/rooms/RDL-1.png differ diff --git a/maps/rooms/RDL-2.png b/maps/rooms/RDL-2.png new file mode 100644 index 0000000..0a4a660 Binary files /dev/null and b/maps/rooms/RDL-2.png differ diff --git a/maps/rooms/TD-1.png b/maps/rooms/TD-1.png new file mode 100644 index 0000000..0b2b0bd Binary files /dev/null and b/maps/rooms/TD-1.png differ diff --git a/maps/rooms/TD-2.png b/maps/rooms/TD-2.png new file mode 100644 index 0000000..698f752 Binary files /dev/null and b/maps/rooms/TD-2.png differ diff --git a/maps/rooms/TL-1.png b/maps/rooms/TL-1.png new file mode 100644 index 0000000..33a1aba Binary files /dev/null and b/maps/rooms/TL-1.png differ diff --git a/maps/rooms/TL-2.png b/maps/rooms/TL-2.png new file mode 100644 index 0000000..76fb85d Binary files /dev/null and b/maps/rooms/TL-2.png differ diff --git a/maps/rooms/TR-1.png b/maps/rooms/TR-1.png new file mode 100644 index 0000000..fa9b455 Binary files /dev/null and b/maps/rooms/TR-1.png differ diff --git a/maps/rooms/TR-2.png b/maps/rooms/TR-2.png new file mode 100644 index 0000000..d3fda28 Binary files /dev/null and b/maps/rooms/TR-2.png differ diff --git a/maps/rooms/TRDL-1.png b/maps/rooms/TRDL-1.png new file mode 100644 index 0000000..41bcac5 Binary files /dev/null and b/maps/rooms/TRDL-1.png differ diff --git a/maps/rooms/TRDL-2.png b/maps/rooms/TRDL-2.png new file mode 100644 index 0000000..be1d1de Binary files /dev/null and b/maps/rooms/TRDL-2.png differ diff --git a/maps/rooms/back.png b/maps/rooms/back.png new file mode 100644 index 0000000..4e393b3 Binary files /dev/null and b/maps/rooms/back.png differ diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..63f1753 --- /dev/null +++ b/utils.py @@ -0,0 +1,97 @@ +# -*- coding: UTF-8 -*- + +### Tangled Mind +### Author: Arthur 'Grizzly' Grisel-Davy + +from glob import glob +import random + +def fetch_rooms(path): + """Fetch all the basic tiles asset from the path. + Return a dictionary + """ + + wildcard = '*-*.png' + filenames = glob(path+wildcard) + print(f"Found {len(filenames)} rooms") + + assembly = {'T':[], + 'R':[], + 'D':[], + 'L':[],} + + for filename in filenames: + label = filename.split("/")[-1].split('-')[0] + if 'T' in label: + assembly['D'].append((label,filename)) + if 'R' in label: + assembly['L'].append((label,filename)) + if 'D' in label: + assembly['T'].append((label,filename)) + if 'L' in label: + assembly['R'].append((label,filename)) + + return assembly + + + +def map_generator(n): + """Map generator generate a map with a main path of n rooms + """ + + room_side = 1000 + + assembly = fetch_rooms('./maps/rooms/') + #assembly = {'T/R/D/L':[(label1,path1),(label2,path2),...]} + + start_key = random.choice(list(assembly.keys())) + start_label,start_room = random.choice(assembly[start_key]) + + position = [0,0] + carte = [(start_room,position)] + + # Select an arbitrary first direction of arrival + dir_from = random.choice(start_label) + current_label = start_label + + for i in range(n): + # select the next direction, can't be the direction of arrival + dir_next = random.choice(current_label.replace(dir_from,'')) + + # Select the next room + next_label,next_room = random.choice(assembly[dir_next]) + + # 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' + + # Build the map + carte.append((next_room,next_position)) + + # Update the label for next turn + current_label = next_label + position = next_position + + # Display the result: + for room in carte: + print(f"Room {room[0].split('/')[-1]} at position {room[1]}") + + print('Done.') + + + + +