après merge

This commit is contained in:
DylanVsn 2019-11-20 16:25:01 +01:00
parent 95ba87c66a
commit e7b67a6545
2 changed files with 27 additions and 9 deletions

View File

@ -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

View File

@ -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