Store the start position in a map
This commit is contained in:
parent
279ef2439d
commit
d75f4290ff
|
@ -14,6 +14,8 @@ class Map:
|
||||||
"""
|
"""
|
||||||
width: int
|
width: int
|
||||||
height: int
|
height: int
|
||||||
|
start_y: int
|
||||||
|
start_x: int
|
||||||
tiles: List[List["Tile"]]
|
tiles: List[List["Tile"]]
|
||||||
entities: List["Entity"]
|
entities: List["Entity"]
|
||||||
# coordinates of the point that should be
|
# coordinates of the point that should be
|
||||||
|
@ -21,9 +23,12 @@ class Map:
|
||||||
currentx: int
|
currentx: int
|
||||||
currenty: int
|
currenty: int
|
||||||
|
|
||||||
def __init__(self, width: int, height: int, tiles: list):
|
def __init__(self, width: int, height: int, tiles: list,
|
||||||
|
start_y: int, start_x: int):
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
|
self.start_y = start_y
|
||||||
|
self.start_x = start_x
|
||||||
self.tiles = tiles
|
self.tiles = tiles
|
||||||
self.entities = []
|
self.entities = []
|
||||||
|
|
||||||
|
@ -63,13 +68,15 @@ class Map:
|
||||||
Load a map represented by its characters and build a Map object.
|
Load a map represented by its characters and build a Map object.
|
||||||
"""
|
"""
|
||||||
lines = content.split("\n")
|
lines = content.split("\n")
|
||||||
lines = [line for line in lines if line]
|
first_line = lines[0]
|
||||||
|
start_y, start_x = map(int, first_line.split(" "))
|
||||||
|
lines = [line for line in lines[1:] if line]
|
||||||
height = len(lines)
|
height = len(lines)
|
||||||
width = len(lines[0])
|
width = len(lines[0])
|
||||||
tiles = [[Tile.from_ascii_char(c)
|
tiles = [[Tile.from_ascii_char(c)
|
||||||
for x, c in enumerate(line)] for y, line in enumerate(lines)]
|
for x, c in enumerate(line)] for y, line in enumerate(lines)]
|
||||||
|
|
||||||
return Map(width, height, tiles)
|
return Map(width, height, tiles, start_y, start_x)
|
||||||
|
|
||||||
def draw_string(self, pack: TexturePack) -> str:
|
def draw_string(self, pack: TexturePack) -> str:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -9,7 +9,7 @@ class TestInterfaces(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
Create a map and check that it is well parsed.
|
Create a map and check that it is well parsed.
|
||||||
"""
|
"""
|
||||||
m = Map.load_from_string(".#\n#.\n")
|
m = Map.load_from_string("0 0\n.#\n#.\n")
|
||||||
self.assertEqual(m.width, 2)
|
self.assertEqual(m.width, 2)
|
||||||
self.assertEqual(m.height, 2)
|
self.assertEqual(m.height, 2)
|
||||||
self.assertEqual(m.draw_string(TexturePack.ASCII_PACK), ".#\n#.")
|
self.assertEqual(m.draw_string(TexturePack.ASCII_PACK), ".#\n#.")
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
####### #############
|
1 6
|
||||||
|
####### #############
|
||||||
#.....# #...........#
|
#.....# #...........#
|
||||||
#.....# #####...........#
|
#.....# #####...........#
|
||||||
#.....# #...............#
|
#.....# #...............#
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
########### #########
|
1 17
|
||||||
#.........# #.......#
|
########### #########
|
||||||
#.........# ############.......#
|
#.........# #.......#
|
||||||
#.........###############..........#.......##############
|
#.........# ############.......#
|
||||||
#.........#........................#....................#
|
#.........###############..........#.......##############
|
||||||
#.........#.............#..........#.......#............#
|
#.........#........................#....................#
|
||||||
########.########.............#..................#............#
|
#.........#.............#..........#.......#............#
|
||||||
#.........# #.............####.#######.......#............#
|
########.########.............#..................#............#
|
||||||
#.........# #.............##.........######################
|
#.........# #.............####.#######.......#............#
|
||||||
#.........# #####.##########.........# ###########
|
#.........# #.............##.........######################
|
||||||
#.........# #......# #.........# #.........#
|
#.........# #####.##########.........# ###########
|
||||||
########.##########......# #.........# #.........#
|
#.........# #......# #.........# #.........#
|
||||||
#...........##......# #.........# #.........#
|
########.##########......# #.........# #.........#
|
||||||
#...........##......# #.........# #.........#
|
#...........##......# #.........# #.........#
|
||||||
#...........##......# #.........# ################.######
|
#...........##......# #.........# #.........#
|
||||||
|
#...........##......# #.........# ################.######
|
||||||
#...........##......# #.........# #.................############
|
#...........##......# #.........# #.................############
|
||||||
#...........##......# ########.########.......#.........#..........#
|
#...........##......# ########.########.......#.........#..........#
|
||||||
#...........##......# #...............#.......#.........#..........#
|
#...........##......# #...............#.......#.........#..........#
|
||||||
|
@ -22,19 +23,19 @@
|
||||||
#.........# #...............###################..........#
|
#.........# #...............###################..........#
|
||||||
#.........############ #...............# #..........#
|
#.........############ #...............# #..........#
|
||||||
#.........#..........# #...............# ############
|
#.........#..........# #...............# ############
|
||||||
#....................#####.###########.#############
|
#....................#####.###########.#############
|
||||||
########.#########...................# #.............#
|
########.#########...................# #.............#
|
||||||
#........# #..........#........# #.............#########
|
#........# #..........#........# #.............#########
|
||||||
#........# ######.##########........# #.............#.......#
|
#........# ######.##########........# #.............#.......#
|
||||||
#........# #..........# #........# #.....................#
|
#........# #..........# #........# #.....................#
|
||||||
#........# #..........# #........# #.............#.......#
|
#........# #..........# #........# #.............#.......#
|
||||||
#........# #..........# #........# #.............#.......#
|
#........# #..........# #........# #.............#.......#
|
||||||
#........# #..........# #........# #.............#.......#
|
#........# #..........# #........# #.............#.......#
|
||||||
#........# #..........#########.##### #.............#.......#
|
#........# #..........#########.##### #.............#.......#
|
||||||
#........# #..........#.........# ##########.############.#######
|
#........# #..........#.........# ##########.############.#######
|
||||||
#........# #..........#.........# #..............# #..........#
|
#........# #..........#.........# #..............# #..........#
|
||||||
########## #..........#.........# #..............# #..........#
|
########## #..........#.........# #..............# #..........#
|
||||||
############.........# #..............# #..........#
|
############.........# #..............# #..........#
|
||||||
#.........# #..............# #..........#
|
#.........# #..............# #..........#
|
||||||
########### #..............# #..........#
|
########### #..............# #..........#
|
||||||
################ ############
|
################ ############
|
||||||
|
|
Loading…
Reference in New Issue