From b950e4f663f414f7bd785dca0a7fc4ceb13e50cf Mon Sep 17 00:00:00 2001 From: Arthur 'Grizzly' Grisel-Davy Date: Mon, 4 May 2020 19:29:22 -0400 Subject: [PATCH] Add starting room --- maps/rooms.svg | 3000 ++++++++++++++++++++++++++++++++++++++++++++ maps/rooms/d-1.png | Bin 0 -> 6344 bytes maps/rooms/l-1.png | Bin 0 -> 6347 bytes maps/rooms/r-1.png | Bin 0 -> 6372 bytes maps/rooms/t-1.png | Bin 0 -> 6374 bytes models.py | 6 +- utils.py | 45 +- 7 files changed, 3028 insertions(+), 23 deletions(-) create mode 100644 maps/rooms.svg create mode 100644 maps/rooms/d-1.png create mode 100644 maps/rooms/l-1.png create mode 100644 maps/rooms/r-1.png create mode 100644 maps/rooms/t-1.png diff --git a/maps/rooms.svg b/maps/rooms.svg new file mode 100644 index 0000000..84effbb --- /dev/null +++ b/maps/rooms.svg @@ -0,0 +1,3000 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TR + + + + + + + + + + + + + + + + + + + + + + + + + + + TRDL + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TD + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TL + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + RDL + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + t + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + r + d + l + + + + + + + + + + + + diff --git a/maps/rooms/d-1.png b/maps/rooms/d-1.png new file mode 100644 index 0000000000000000000000000000000000000000..a1b2563840f8a9d0c8c709069538faee8b2e01c3 GIT binary patch literal 6344 zcmeAS@N?(olHy`uVBq!ia0y~yV15C@9Be=l-^Ev+04bJYC(jTLAgJL;=>YOM3p^r= z85sDEfH31!Z9ZwBpk#?_L`iUdT1k0gQ7S`udAVL@UUqSEVnM22eo^}DcQ#TC3=*!M zE{-7;bKc%O=zD~L$JLR2=`oR+YKIGt=C-!{X_(3N@1nomyP4@g;~GNcZ!-gFhDJUh z!O0{GB$-&OfFuh?36SIv06LRFK;Z%-1A~IY0-#cd1_ySaK8Oa!Q4OP^gg0rNd&^i; zdRFE(Fzq({e>ksloB4-F&7ib4nsi1p*l4LTT9g8dg3$_Rw3Z!hT8vhTz@lKZ)k)u` z_JN(Y3=d+zpV_>(aeDT%8}}F(K1}~Hniog&;%HtR?e-4czJ5U-KSRZJ)8d?bV7GJr zXoqujL}zpuYjo^x2#-1)C_Ha-TbbcU?Yf!C)yyF~*E9U!lOG*=#5?pjTIf+y=sgf# Ycu%m-vC3i^FxxPAy85}Sb4q9e00W^zXaE2J literal 0 HcmV?d00001 diff --git a/maps/rooms/l-1.png b/maps/rooms/l-1.png new file mode 100644 index 0000000000000000000000000000000000000000..214c8184a0918b9a8980ec266498304b06abc398 GIT binary patch literal 6347 zcmeAS@N?(olHy`uVBq!ia0y~yV15C@9Be=l-^Ev+04bJYC(jTLAgJL;=>YOM3p^r= z85sDEfH31!Z9ZwBpk#?_L`iUdT1k0gQ7S`udAVL@UUqSEVnM22eo^}DcQ#TC3=$rm zE{-7;bKc%O=*!|Lz;aNo#BANf*H1p#9F(_W6%@OYZL-qt`x#@PaR*lQzhwl{4G!!; zf~AoU$Yx}c1(HlGRzQ-4qXbBD2ml?+AfRvos8qpW0W$-G14IMEsD{x{!kaYKzhw+4 zJ3HqsF9XAe;CD0AtC{olMibL$4gw|`+LSW~va1>5V~v3c4QR#w^Q@y~889413-Hle zYqY8!npJhfW?P0IyCGHQbaQ!zAIIv~9vv;#M%$&Mjd5U?WwZw}MEhwC#pi8qD_87J zJNFIP2Yyh0p;>pdV=&sa9vy%HHrGc-T}FqRzyorlwc8M_-Dnwc2X>~YOM3p^r= z85sDEfH31!Z9ZwBpk#?_L`iUdT1k0gQ7S`udAVL@UUqSEVnM22eo^}DcQ#TC3=)Z+ zE{-7;bKc(En0uH(faT!wgHn+yvzIs@oGJ8M{F)EzbiH>w(&sS(jSH*IELK25 zg`)&WatHuj#vq_@0VuEFuz;C?!J)x{oq?f&p^*FB$>b(SVlFBh7#VSVX>Xv z;ihSEPChXG+%GzBb6dLN<7ko^%}2l@ghqwO^KT4wyVCmJ@&c{+W6KXJ*JxzZXhAsA ztBZm>P~~ZN-1c)$euLI%S{rRR(5|%vOKYIYbTqAvHd04h=A+#a${RPJQl;WLsQ!BJ zbe82db6}fEU2XuX^#^z4fHmoXzUpT;?;Yr7AMIiSLt|K%aSg@Q3j`8_#Y%4yE4tYOM3p^r= z85sDEfH31!Z9ZwBpk#?_L`iUdT1k0gQ7S`udAVL@UUqSEVnM22eo^}DcQ#TC3=+wn zE{-7;bKc%O*ee~#!|GUW1B(@qP~j*6k{kj+M=}T~Twr8iP;gkl%)sE#;K0tn(7@2h2b5rBk_D1X zU=1vz8b(72Z_=9lJX0Gy9$!xY>T&< z0~2+9J3pw^HrfaqZK@8p_WAX1z=Zu{N&2&`dmHWF&D^|~aaGM|OMA583``ZHJ0I!RUYw e?FM{4NPm(My%9EF_$@HCF?hQAxvX<^H literal 0 HcmV?d00001 diff --git a/models.py b/models.py index b2f36e3..40546ac 100644 --- a/models.py +++ b/models.py @@ -73,9 +73,6 @@ class Carte(): def __init__(self,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): offsetx,offsety = camera.get_offset() for room in self.carte: @@ -83,9 +80,11 @@ class Carte(): surface.blit(room[0],(room[2][0]-offsetx,room[2][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])): return True + return False @@ -151,6 +150,7 @@ 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 6a243ee..a1bb975 100644 --- a/utils.py +++ b/utils.py @@ -12,16 +12,18 @@ def fetch_rooms(path): Return a dictionary """ - wildcard = '*-*.png' - filenames = glob(path+wildcard) - print(f"Found {len(filenames)} rooms") + common_wildcard = '[A-Z]*-*.png' + unique_wildcard = '?-*.png' + 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':[], 'R':[], 'D':[], 'L':[],} - for filename in filenames: + for filename in common_filenames: label = filename.split("/")[-1].split('-')[0] if 'T' in label: assembly['D'].append((label,filename)) @@ -34,7 +36,7 @@ def fetch_rooms(path): background = glob(path+'*back*')[0] - return assembly,background + return unique_filenames,assembly,background def check_map(carte): """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 """ - start_poss = {'T':(500,50),'R':(950,500),'D':(500,950),'L':(50,500)} - 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),...]} - 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 positions = [] position = [0,0] - asset = pygame.image.load(start_room).convert_alpha() - mask = pygame.mask.from_surface(asset) - carte = [(asset,mask,position)] + mask = pygame.mask.from_surface(start_room) + carte = [(start_room,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 while counter < n: # select the next direction, can't be the direction of arrival - dir_next = random.choice(current_label.replace(dir_from,'')) + if len(current_label) > 1: + dir_next = random.choice(current_label.replace(dir_from,'')) + else: + dir_next = current_label + # Select the next room next_label,next_room = random.choice(assembly[dir_next]) @@ -116,11 +118,14 @@ def map_generator(n): background = pygame.image.load(back_path).convert() if not check_map(carte): - print("Invalid Map.") + raise ValueError("Invalid Map.") else: 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)