Fix texture packs

This commit is contained in:
Yohann D'ANELLO 2020-11-06 20:18:27 +01:00
parent 02d3394439
commit b3d789e3e7
3 changed files with 28 additions and 18 deletions

View File

@ -7,6 +7,9 @@ class TexturePack:
FLOOR: str
PLAYER: str
ASCII_PACK: "TexturePack"
SQUIRREL_PACK: "TexturePack"
def __init__(self, name: str, **kwargs):
self.name = name
self.__dict__.update(**kwargs)

View File

@ -46,7 +46,7 @@ class Map:
lines = [line for line in lines if line]
height = len(lines)
width = len(lines[0])
tiles = [[Tile(c)
tiles = [[Tile.from_ascii_char(c)
for x, c in enumerate(line)] for y, line in enumerate(lines)]
return Map(width, height, tiles)
@ -65,6 +65,13 @@ class Tile(Enum):
WALL = auto()
FLOOR = auto()
@classmethod
def from_ascii_char(cls, ch: str) -> "Tile":
for tile in Tile:
if tile.char(TexturePack.ASCII_PACK) == ch:
return tile
raise ValueError(ch)
def char(self, pack: TexturePack) -> str:
return getattr(pack, self.name)

View File

@ -1,17 +1,17 @@
███████ █████████████
█.....█ █...........█
█.....█ █████...........█
█.....█ █...............█
█.█████ █.███...........█
█.█ █.█ █...........█
█.█ █.█ █████████████
█.█ █.█
█.████ █.█
█....█ █.█
████.███████████████████.█
█.....................█ █████████████████
█.....................█ █...............█
█.....................███████...............█
█...........................................█
█.....................███████...............█
███████████████████████ █████████████████
####### #############
#.....# #...........#
#.....# #####...........#
#.....# #...............#
#.##### #.###...........#
#.# #.# #...........#
#.# #.# #############
#.# #.#
#.#### #.#
#....# #.#
####.###################.#
#.....................# #################
#.....................# #...............#
#.....................#######...............#
#...........................................#
#.....................#######...............#
####################### #################