From e7b67a65453e2d52abff71ec5a74722803fa3475 Mon Sep 17 00:00:00 2001 From: DylanVsn <43576618+DylanVsn@users.noreply.github.com> Date: Wed, 20 Nov 2019 16:25:01 +0100 Subject: [PATCH] =?UTF-8?q?apr=C3=A8s=20merge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pacmap_rule.txt | 5 +++-- src/pacmap.py | 31 ++++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/pacmap_rule.txt b/pacmap_rule.txt index c2d1f32..fab3e12 100644 --- a/pacmap_rule.txt +++ b/pacmap_rule.txt @@ -5,5 +5,6 @@ GCF 255 0 255 WAL 0 0 255 GSD 0 255 0 GWL 0 255 255 -TPT 255 0 0 -FIT 255 255 255 +PST 255 255 0 // pacman start tile +BPD 255 0 0 // big pac-dot +PDT 255 255 255 // small pac-dot diff --git a/src/pacmap.py b/src/pacmap.py index 99a9acf..2ca17ef 100755 --- a/src/pacmap.py +++ b/src/pacmap.py @@ -56,9 +56,10 @@ class Map: 2: big pac-dot """ self._surf = pygame.Surface((Map.width * 20, Map.height * 20)) + self._dot_surf = pygame.Surface((Map.width * 20, Map.height * 20)) if maze_img_file and os.path.isfile(maze_img_file): try: - self.phys_map = self.decode_map(maze_img_file) + self.decode_map(maze_img_file) except Exception as e: raise e else: @@ -185,6 +186,8 @@ class Map: def draw(self, surf): surf.blit(self._surf, (0, 0)) + self._dot_surf.fill() + def decode_map(self, img_file): img = Image.open(img_file) @@ -194,22 +197,36 @@ class Map: (0 , 0, 255): PhysTile.WAL, (0 , 255, 0): PhysTile.GSD, (0 , 255, 255): PhysTile.GWL, - (255, 0, 0): PhysTile.TPT, - (255, 255, 0): PhysTile.FIT, + (255, 0, 0): DotTile.BPD, + (255, 255, 0): "pacstart", + (255, 255, 255): DotTile.SPD } data = list(img.getdata()) - matrix = [] + self.phys_map, self.dots_map = [], [] for row in range(img.height): - matrix.append([]) + self.phys_map.append([]) + self.dots_map.append([]) for col in range(img.width): try: color = data[col + row*img.width][:3] tile = dictionnary[color] # avoid alpha component + if isinstance(tile, PhysTile): + self.phys_map[-1].append(tile) + self.dots_map[-1].append(DotTile.NDT) + if tile not in (PhysTile.WAL, PhysTile.GCF, PhysTile.GSD, PhysTile.GWL): + color = (0, 0, 0) # everything else is ground visually + elif isinstance(tile, DotTile): + self.phys_map[-1].append(PhysTile.GRD) + self.dots_map[-1].append(tile) + color = (0, 0, 0) + else: # pacstart + self.phys_map[-1].append(PhysTile.GRD) + self.dots_map[-1].append(DotTile.NDT) + self.pac_start = (len(self.phys_map), len(self.phys_map[-1])) + color = (0, 0, 0) self._surf.fill(color, pygame.Rect(col*20, row*20, 20, 20)) except: raise ValueError("Pixel " + str(col) + "," + str(row) + " is invalid") - matrix[-1].append(tile) - return matrix