Add different backs for start and stop, add texture to back
|
@ -6,6 +6,10 @@
|
|||
room_side : 1000
|
||||
wall_size : 150
|
||||
|
||||
wk_back : '*back.*'
|
||||
wk_back_start : '*back_start.*'
|
||||
wk_back_stop : '*back_stop.*'
|
||||
|
||||
|
||||
# general
|
||||
texture_path : 'asset/'
|
||||
|
|
6300
maps/rooms.svg
Before Width: | Height: | Size: 194 KiB After Width: | Height: | Size: 318 KiB |
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 67 KiB |
BIN
maps/rooms/back_start.png
Normal file
After Width: | Height: | Size: 69 KiB |
BIN
maps/rooms/back_stop.png
Normal file
After Width: | Height: | Size: 75 KiB |
12
models.py
|
@ -94,20 +94,20 @@ class Hud():
|
|||
|
||||
class Carte():
|
||||
def __init__(self,n):
|
||||
self.carte, self.player_start_pos, self.back = map_generator(n)
|
||||
self.carte, self.player_start_pos = map_generator(n)
|
||||
|
||||
def draw(self,surface,camera):
|
||||
offsetx,offsety = camera.get_offset()
|
||||
for room in self.carte:
|
||||
surface.blit(self.back,(room[2][0]-offsetx,room[2][1]-offsety))
|
||||
surface.blit(room[0],(room[2][0]-offsetx,room[2][1]-offsety))
|
||||
for k,room in enumerate(self.carte):
|
||||
|
||||
surface.blit(room[0],(room[3][0]-offsetx,room[3][1]-offsety))
|
||||
surface.blit(room[1],(room[3][0]-offsetx,room[3][1]-offsety))
|
||||
|
||||
def collision(self,thing):
|
||||
#print(f"player in position {thing.posx,thing.posy}")
|
||||
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[2].overlap(thing.mask, (thing.posx-thing.rect.center[0]-room[3][0],thing.posy-thing.rect.center[1]-room[3][1])):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
|
37
utils.py
|
@ -14,6 +14,12 @@ def fetch_rooms(path):
|
|||
Return a dictionary
|
||||
"""
|
||||
|
||||
with open(r'./config.yaml') as file:
|
||||
data = yaml.load(file,Loader=yaml.FullLoader)
|
||||
wk_back = data['wk_back']
|
||||
wk_back_start = data['wk_back_start']
|
||||
wk_back_stop = data['wk_back_stop']
|
||||
|
||||
common_wildcard = '[A-Z]*-*.png'
|
||||
unique_wildcard = '?-*.png'
|
||||
common_filenames = glob(path+common_wildcard)
|
||||
|
@ -36,19 +42,21 @@ def fetch_rooms(path):
|
|||
if 'L' in label:
|
||||
assembly['R'].append((label,filename))
|
||||
|
||||
background = glob(path+'*back*')[0]
|
||||
back = glob(path+wk_back)[0]
|
||||
back_start = glob(path+wk_back_start)[0]
|
||||
back_stop = glob(path+wk_back_stop)[0]
|
||||
|
||||
return unique_filenames,assembly,background
|
||||
return (unique_filenames,assembly,back,back_start,back_stop)
|
||||
|
||||
def check_map(carte):
|
||||
"""Function to check if a map is valid i.e. if no two rooms are at the same location
|
||||
"""
|
||||
positions = []
|
||||
for room in carte:
|
||||
if room[2] in positions:
|
||||
if room[3] in positions:
|
||||
return(False)
|
||||
else:
|
||||
positions.append(room[2])
|
||||
positions.append(room[3])
|
||||
return(True)
|
||||
|
||||
def enemy_placement(carte):
|
||||
|
@ -79,11 +87,11 @@ def enemy_placement(carte):
|
|||
posx = randint(padding_h, room_side-padding_h)
|
||||
posy = randint(padding_v, room_side-padding_v)
|
||||
|
||||
if room[1].overlap(enemy_mask, (posx-enemy_center[0],posy-enemy_center[1])):
|
||||
if room[2].overlap(enemy_mask, (posx-enemy_center[0],posy-enemy_center[1])):
|
||||
retry+=1
|
||||
else:
|
||||
#print(f'New enemy at {posx,posy}')
|
||||
positions.append((room[2][0] + posx,room[2][1] + posy))
|
||||
positions.append((room[3][0] + posx,room[3][1] + posy))
|
||||
carte_positions.append(positions)
|
||||
positions = []
|
||||
|
||||
|
@ -101,9 +109,12 @@ def map_generator(n):
|
|||
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,back_start_path,back_stop_path = fetch_rooms('./maps/rooms/')
|
||||
#assembly = {'T/R/D/L':[(label1,path1),(label2,path2),...]}
|
||||
|
||||
background = pygame.image.load(back_path).convert()
|
||||
background_start = pygame.image.load(back_start_path).convert()
|
||||
background_stop = pygame.image.load(back_stop_path).convert()
|
||||
|
||||
unique_rooms = {filename.split("/")[-1][0].upper():pygame.image.load(filename).convert_alpha() for filename in unique_filenames}
|
||||
|
||||
|
@ -114,7 +125,7 @@ def map_generator(n):
|
|||
positions = []
|
||||
position = [0,0]
|
||||
mask = pygame.mask.from_surface(start_room)
|
||||
carte = [(start_room,mask,position)]
|
||||
carte = [(background_start,start_room,mask,position)]
|
||||
|
||||
open_paths = []
|
||||
|
||||
|
@ -140,10 +151,12 @@ def map_generator(n):
|
|||
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()
|
||||
back = background
|
||||
|
||||
else:
|
||||
# The next room is the finale room.
|
||||
asset = unique_rooms[change_side[dir_next]]
|
||||
back = background_stop
|
||||
|
||||
mask = pygame.mask.from_surface(asset)
|
||||
next_position = [position[0]+room_side*deplacements[dir_next][0],position[1]+room_side*deplacements[dir_next][1]]
|
||||
|
@ -153,7 +166,7 @@ def map_generator(n):
|
|||
if next_position not in positions:
|
||||
counter += 1
|
||||
# Build the map
|
||||
carte.append((asset,mask,next_position))
|
||||
carte.append((back,asset,mask,next_position))
|
||||
positions.append(position)
|
||||
|
||||
# Update the variables for next turn
|
||||
|
@ -175,15 +188,13 @@ def map_generator(n):
|
|||
room = unique_rooms[open_path[0]]
|
||||
mask = pygame.mask.from_surface(room)
|
||||
position = open_path[1]
|
||||
carte.append((room,mask,position))
|
||||
carte.append((background,room,mask,position))
|
||||
positions.append(position)
|
||||
|
||||
background = pygame.image.load(back_path).convert()
|
||||
|
||||
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)))
|
||||
|
||||
|
||||
|
||||
|
|