I decided: every dungeon map has rooms
This commit is contained in:
parent
c2c67ae9ef
commit
5f6247ef13
1 changed files with 20 additions and 7 deletions
|
@ -24,12 +24,15 @@ class Map:
|
||||||
# Map tiles that the player has explored
|
# Map tiles that the player has explored
|
||||||
self.explored = np.full(tuple(self.size), fill_value=False, order='F')
|
self.explored = np.full(tuple(self.size), fill_value=False, order='F')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def rooms(self) -> List['Room']:
|
||||||
|
return self.generator.rooms
|
||||||
|
|
||||||
def random_walkable_position(self) -> Point:
|
def random_walkable_position(self) -> Point:
|
||||||
# TODO: Include hallways
|
# TODO: Include hallways
|
||||||
random_room: RectangularRoom = random.choice(self.generator.rooms)
|
random_room: RectangularRoom = random.choice(self.rooms)
|
||||||
floor = random_room.floor_bounds
|
floor: List[Point] = list(random_room.walkable_tiles)
|
||||||
random_position_in_room = Point(random.randint(floor.min_x, floor.max_x),
|
random_position_in_room = random.choice(floor)
|
||||||
random.randint(floor.min_y, floor.max_y))
|
|
||||||
return random_position_in_room
|
return random_position_in_room
|
||||||
|
|
||||||
def tile_is_in_bounds(self, point: Point) -> bool:
|
def tile_is_in_bounds(self, point: Point) -> bool:
|
||||||
|
@ -52,6 +55,7 @@ class Map:
|
||||||
class MapGenerator:
|
class MapGenerator:
|
||||||
def __init__(self, *, size: Size):
|
def __init__(self, *, size: Size):
|
||||||
self.size = size
|
self.size = size
|
||||||
|
self.rooms: List['Room'] = []
|
||||||
|
|
||||||
def generate(self) -> np.ndarray:
|
def generate(self) -> np.ndarray:
|
||||||
'''
|
'''
|
||||||
|
@ -212,8 +216,14 @@ class RoomsAndCorridorsGenerator(MapGenerator):
|
||||||
def __rect_from_bsp_node(self, node: tcod.bsp.BSP) -> Rect:
|
def __rect_from_bsp_node(self, node: tcod.bsp.BSP) -> Rect:
|
||||||
return Rect(Point(node.x, node.y), Size(node.width, node.height))
|
return Rect(Point(node.x, node.y), Size(node.width, node.height))
|
||||||
|
|
||||||
|
class Room:
|
||||||
|
'''An abstract room. It can be any size or shape.'''
|
||||||
|
|
||||||
class RectangularRoom:
|
@property
|
||||||
|
def walkable_tiles(self) -> Iterator[Point]:
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
class RectangularRoom(Room):
|
||||||
def __init__(self, bounds: Rect):
|
def __init__(self, bounds: Rect):
|
||||||
self.bounds = bounds
|
self.bounds = bounds
|
||||||
|
|
||||||
|
@ -222,8 +232,11 @@ class RectangularRoom:
|
||||||
return self.bounds.midpoint
|
return self.bounds.midpoint
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def floor_bounds(self) -> Rect:
|
def walkable_tiles(self) -> Rect:
|
||||||
return self.bounds.inset_rect(top=1, right=1, bottom=1, left=1)
|
floor_rect = self.bounds.inset_rect(top=1, right=1, bottom=1, left=1)
|
||||||
|
for y in range(floor_rect.min_y, floor_rect.max_y + 1):
|
||||||
|
for x in range(floor_rect.min_x, floor_rect.max_x + 1):
|
||||||
|
yield Point(x, y)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def walls(self) -> Iterator[Point]:
|
def walls(self) -> Iterator[Point]:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue