après merge
This commit is contained in:
parent
95ba87c66a
commit
e7b67a6545
@ -5,5 +5,6 @@ GCF 255 0 255
|
|||||||
WAL 0 0 255
|
WAL 0 0 255
|
||||||
GSD 0 255 0
|
GSD 0 255 0
|
||||||
GWL 0 255 255
|
GWL 0 255 255
|
||||||
TPT 255 0 0
|
PST 255 255 0 // pacman start tile
|
||||||
FIT 255 255 255
|
BPD 255 0 0 // big pac-dot
|
||||||
|
PDT 255 255 255 // small pac-dot
|
||||||
|
@ -56,9 +56,10 @@ class Map:
|
|||||||
2: big pac-dot
|
2: big pac-dot
|
||||||
"""
|
"""
|
||||||
self._surf = pygame.Surface((Map.width * 20, Map.height * 20))
|
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):
|
if maze_img_file and os.path.isfile(maze_img_file):
|
||||||
try:
|
try:
|
||||||
self.phys_map = self.decode_map(maze_img_file)
|
self.decode_map(maze_img_file)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
else:
|
else:
|
||||||
@ -185,6 +186,8 @@ class Map:
|
|||||||
|
|
||||||
def draw(self, surf):
|
def draw(self, surf):
|
||||||
surf.blit(self._surf, (0, 0))
|
surf.blit(self._surf, (0, 0))
|
||||||
|
self._dot_surf.fill()
|
||||||
|
|
||||||
|
|
||||||
def decode_map(self, img_file):
|
def decode_map(self, img_file):
|
||||||
img = Image.open(img_file)
|
img = Image.open(img_file)
|
||||||
@ -194,22 +197,36 @@ class Map:
|
|||||||
(0 , 0, 255): PhysTile.WAL,
|
(0 , 0, 255): PhysTile.WAL,
|
||||||
(0 , 255, 0): PhysTile.GSD,
|
(0 , 255, 0): PhysTile.GSD,
|
||||||
(0 , 255, 255): PhysTile.GWL,
|
(0 , 255, 255): PhysTile.GWL,
|
||||||
(255, 0, 0): PhysTile.TPT,
|
(255, 0, 0): DotTile.BPD,
|
||||||
(255, 255, 0): PhysTile.FIT,
|
(255, 255, 0): "pacstart",
|
||||||
|
(255, 255, 255): DotTile.SPD
|
||||||
}
|
}
|
||||||
data = list(img.getdata())
|
data = list(img.getdata())
|
||||||
matrix = []
|
self.phys_map, self.dots_map = [], []
|
||||||
for row in range(img.height):
|
for row in range(img.height):
|
||||||
matrix.append([])
|
self.phys_map.append([])
|
||||||
|
self.dots_map.append([])
|
||||||
for col in range(img.width):
|
for col in range(img.width):
|
||||||
try:
|
try:
|
||||||
color = data[col + row*img.width][:3]
|
color = data[col + row*img.width][:3]
|
||||||
tile = dictionnary[color] # avoid alpha component
|
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))
|
self._surf.fill(color, pygame.Rect(col*20, row*20, 20, 20))
|
||||||
except:
|
except:
|
||||||
raise ValueError("Pixel " + str(col) + "," + str(row) + " is invalid")
|
raise ValueError("Pixel " + str(col) + "," + str(row) + " is invalid")
|
||||||
matrix[-1].append(tile)
|
|
||||||
return matrix
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user