Add starting room
This commit is contained in:
parent
fcd20b3cdc
commit
b950e4f663
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 194 KiB |
Binary file not shown.
After Width: | Height: | Size: 6.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 6.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 6.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 6.2 KiB |
|
@ -73,9 +73,6 @@ class Carte():
|
||||||
def __init__(self,n):
|
def __init__(self,n):
|
||||||
self.carte, self.player_start_pos, self.back = map_generator(n)
|
self.carte, self.player_start_pos, self.back = map_generator(n)
|
||||||
|
|
||||||
for room in self.carte:
|
|
||||||
print(room[2])
|
|
||||||
|
|
||||||
def draw(self,surface,camera):
|
def draw(self,surface,camera):
|
||||||
offsetx,offsety = camera.get_offset()
|
offsetx,offsety = camera.get_offset()
|
||||||
for room in self.carte:
|
for room in self.carte:
|
||||||
|
@ -83,9 +80,11 @@ class Carte():
|
||||||
surface.blit(room[0],(room[2][0]-offsetx,room[2][1]-offsety))
|
surface.blit(room[0],(room[2][0]-offsetx,room[2][1]-offsety))
|
||||||
|
|
||||||
def collision(self,thing):
|
def collision(self,thing):
|
||||||
|
#print(f"player in position {thing.posx,thing.posy}")
|
||||||
for room in self.carte:
|
for room in self.carte:
|
||||||
if room[1].overlap(thing.mask, (thing.posx-thing.rect.center[0]-room[2][0],thing.posy-thing.rect.center[1]-room[2][1])):
|
if room[1].overlap(thing.mask, (thing.posx-thing.rect.center[0]-room[2][0],thing.posy-thing.rect.center[1]-room[2][1])):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -151,6 +150,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
|
||||||
|
print("PLOP")
|
||||||
|
|
||||||
if keystate[self.key_right]:
|
if keystate[self.key_right]:
|
||||||
self.speed[0] += acceleration
|
self.speed[0] += acceleration
|
||||||
|
|
43
utils.py
43
utils.py
|
@ -12,16 +12,18 @@ def fetch_rooms(path):
|
||||||
Return a dictionary
|
Return a dictionary
|
||||||
"""
|
"""
|
||||||
|
|
||||||
wildcard = '*-*.png'
|
common_wildcard = '[A-Z]*-*.png'
|
||||||
filenames = glob(path+wildcard)
|
unique_wildcard = '?-*.png'
|
||||||
print(f"Found {len(filenames)} rooms")
|
common_filenames = glob(path+common_wildcard)
|
||||||
|
unique_filenames = glob(path+unique_wildcard)
|
||||||
|
#print(f"Found {len(common_filenames)} common rooms and {len(unique_filenames)} uniques rooms.")
|
||||||
|
|
||||||
assembly = {'T':[],
|
assembly = {'T':[],
|
||||||
'R':[],
|
'R':[],
|
||||||
'D':[],
|
'D':[],
|
||||||
'L':[],}
|
'L':[],}
|
||||||
|
|
||||||
for filename in filenames:
|
for filename in common_filenames:
|
||||||
label = filename.split("/")[-1].split('-')[0]
|
label = filename.split("/")[-1].split('-')[0]
|
||||||
if 'T' in label:
|
if 'T' in label:
|
||||||
assembly['D'].append((label,filename))
|
assembly['D'].append((label,filename))
|
||||||
|
@ -34,7 +36,7 @@ def fetch_rooms(path):
|
||||||
|
|
||||||
background = glob(path+'*back*')[0]
|
background = glob(path+'*back*')[0]
|
||||||
|
|
||||||
return assembly,background
|
return unique_filenames,assembly,background
|
||||||
|
|
||||||
def check_map(carte):
|
def check_map(carte):
|
||||||
"""Function to check if a map is valid i.e. if no two rooms are at the same location
|
"""Function to check if a map is valid i.e. if no two rooms are at the same location
|
||||||
|
@ -51,33 +53,33 @@ def map_generator(n):
|
||||||
"""Map generator generate a map with a main path of n rooms
|
"""Map generator generate a map with a main path of n rooms
|
||||||
"""
|
"""
|
||||||
|
|
||||||
start_poss = {'T':(500,50),'R':(950,500),'D':(500,950),'L':(50,500)}
|
|
||||||
|
|
||||||
room_side = 1000
|
room_side = 1000
|
||||||
|
|
||||||
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),...]}
|
||||||
|
|
||||||
start_key = random.choice(list(assembly.keys()))
|
|
||||||
start_label,start_room = random.choice(assembly[start_key])
|
unique_rooms = {filename.split("/")[-1][0].upper():pygame.image.load(filename).convert_alpha() for filename in unique_filenames}
|
||||||
|
|
||||||
|
current_label= random.choice(list(unique_rooms.keys()))
|
||||||
|
start_room = unique_rooms[current_label]
|
||||||
|
|
||||||
# Place the first room in the list
|
# Place the first room in the list
|
||||||
positions = []
|
positions = []
|
||||||
position = [0,0]
|
position = [0,0]
|
||||||
asset = pygame.image.load(start_room).convert_alpha()
|
mask = pygame.mask.from_surface(start_room)
|
||||||
mask = pygame.mask.from_surface(asset)
|
carte = [(start_room,mask,position)]
|
||||||
carte = [(asset,mask,position)]
|
|
||||||
|
|
||||||
# Select an arbitrary first direction of arrival
|
|
||||||
dir_from = random.choice(start_label)
|
|
||||||
start_pos = start_poss[dir_from]
|
|
||||||
current_label = start_label
|
|
||||||
|
|
||||||
counter = 0
|
counter = 0
|
||||||
while counter < n:
|
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:
|
||||||
dir_next = random.choice(current_label.replace(dir_from,''))
|
dir_next = random.choice(current_label.replace(dir_from,''))
|
||||||
|
else:
|
||||||
|
dir_next = current_label
|
||||||
|
|
||||||
|
|
||||||
# Select the next room
|
# Select the next room
|
||||||
next_label,next_room = random.choice(assembly[dir_next])
|
next_label,next_room = random.choice(assembly[dir_next])
|
||||||
|
@ -116,11 +118,14 @@ def map_generator(n):
|
||||||
background = pygame.image.load(back_path).convert()
|
background = pygame.image.load(back_path).convert()
|
||||||
|
|
||||||
if not check_map(carte):
|
if not check_map(carte):
|
||||||
print("Invalid Map.")
|
raise ValueError("Invalid Map.")
|
||||||
else:
|
else:
|
||||||
print("Map checked and valid!")
|
print("Map checked and valid!")
|
||||||
|
|
||||||
return(carte,start_pos,background)
|
for room in carte:
|
||||||
|
print(room)
|
||||||
|
|
||||||
|
return(carte,(int(room_side/2),int(room_side/2)),background)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue