Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __sub__(self, other):
if isinstance(other, Direction):
other = other.value
elif isinstance(other, (Point, Size)):
pass
else:
return NotImplemented
return Point(self.x - other[0], self.y - other[1])
#self.zones = {}
#self.zones['kadath'] = [RuinLayout(), RuinLayout(), RuinLayout()]
# TODO but really there should be a thing that generates a zone, too,
# with its own handful of parameters. also, "zone" is a bad name for a
# region.
# I suppose for now we'll just hardcode this, but...
# TODO how will all this work? where do the connections between maps
# live? do we decide the general structure (e.g. a split-off section
# of the dungeon with X floors) and then tell the fractors to conform
# to that?
# TODO maybe maps should just know their own names
# TODO check that all maps are connected?
self.maps = {}
self.maps['map0'] = RuinFractor(Size(120, 30)).generate_map(down='map1')
self.maps['map1'] = RuinedHallFractor(Size(120, 30)).generate_map(up='map0', down='map2')
self.maps['map2'] = PerlinFractor(Size(150, 40)).generate_map(up='map1', down='map3')
self.maps['map3'] = PerlinFractor(Size(60, 30)).generate_map(up='map2')
#self.maps['map3'] = BinaryPartitionFractor(Size(80, 24), minimum_size=Size(10, 8)).generate_map(up='map2')
self.current_map_name = None
self.current_map = None
# TODO should this obj just switch to the first map when it starts?
# that doesn't seem right.
self.starting_map = 'map0'
def randomize(cls, region, *, minimum_size=Size(5, 5)):
"""Place a room randomly in a region, randomizing its size and position.
"""
# TODO need to guarantee the region is big enough
size = Size(
random_normal_range(minimum_size.width, region.width),
random_normal_range(minimum_size.height, region.height),
)
left = region.left + random.randint(0, region.width - size.width)
top = region.top + random.randint(0, region.height - size.height)
rect = Rectangle(Point(left, top), size)
return cls(rect)
def from_edges(cls, *, top, bottom, left, right):
return cls(Point(left, top), Size(right - left + 1, bottom - top + 1))
#self.zones['kadath'] = [RuinLayout(), RuinLayout(), RuinLayout()]
# TODO but really there should be a thing that generates a zone, too,
# with its own handful of parameters. also, "zone" is a bad name for a
# region.
# I suppose for now we'll just hardcode this, but...
# TODO how will all this work? where do the connections between maps
# live? do we decide the general structure (e.g. a split-off section
# of the dungeon with X floors) and then tell the fractors to conform
# to that?
# TODO maybe maps should just know their own names
# TODO check that all maps are connected?
self.maps = {}
self.maps['map0'] = RuinFractor(Size(120, 30)).generate_map(down='map1')
self.maps['map1'] = RuinedHallFractor(Size(120, 30)).generate_map(up='map0', down='map2')
self.maps['map2'] = PerlinFractor(Size(150, 40)).generate_map(up='map1', down='map3')
self.maps['map3'] = PerlinFractor(Size(60, 30)).generate_map(up='map2')
#self.maps['map3'] = BinaryPartitionFractor(Size(80, 24), minimum_size=Size(10, 8)).generate_map(up='map2')
self.current_map_name = None
self.current_map = None
# TODO should this obj just switch to the first map when it starts?
# that doesn't seem right.
self.starting_map = 'map0'
def randomize(cls, region, *, minimum_size=Size(5, 5)):
"""Place a room randomly in a region, randomizing its size and position.
"""
# TODO need to guarantee the region is big enough
size = Size(
random_normal_range(minimum_size.width, region.width),
random_normal_range(minimum_size.height, region.height),
)
left = region.left + random.randint(0, region.width - size.width)
top = region.top + random.randint(0, region.height - size.height)
rect = Rectangle(Point(left, top), size)
return cls(rect)
# TODO just thinking about how this would work, for now
#self.zones = {}
#self.zones['kadath'] = [RuinLayout(), RuinLayout(), RuinLayout()]
# TODO but really there should be a thing that generates a zone, too,
# with its own handful of parameters. also, "zone" is a bad name for a
# region.
# I suppose for now we'll just hardcode this, but...
# TODO how will all this work? where do the connections between maps
# live? do we decide the general structure (e.g. a split-off section
# of the dungeon with X floors) and then tell the fractors to conform
# to that?
# TODO maybe maps should just know their own names
# TODO check that all maps are connected?
self.maps = {}
self.maps['map0'] = RuinFractor(Size(120, 30)).generate_map(down='map1')
self.maps['map1'] = RuinedHallFractor(Size(120, 30)).generate_map(up='map0', down='map2')
self.maps['map2'] = PerlinFractor(Size(150, 40)).generate_map(up='map1', down='map3')
self.maps['map3'] = PerlinFractor(Size(60, 30)).generate_map(up='map2')
#self.maps['map3'] = BinaryPartitionFractor(Size(80, 24), minimum_size=Size(10, 8)).generate_map(up='map2')
self.current_map_name = None
self.current_map = None
# TODO should this obj just switch to the first map when it starts?
# that doesn't seem right.
self.starting_map = 'map0'
# TODO but really there should be a thing that generates a zone, too,
# with its own handful of parameters. also, "zone" is a bad name for a
# region.
# I suppose for now we'll just hardcode this, but...
# TODO how will all this work? where do the connections between maps
# live? do we decide the general structure (e.g. a split-off section
# of the dungeon with X floors) and then tell the fractors to conform
# to that?
# TODO maybe maps should just know their own names
# TODO check that all maps are connected?
self.maps = {}
self.maps['map0'] = RuinFractor(Size(120, 30)).generate_map(down='map1')
self.maps['map1'] = RuinedHallFractor(Size(120, 30)).generate_map(up='map0', down='map2')
self.maps['map2'] = PerlinFractor(Size(150, 40)).generate_map(up='map1', down='map3')
self.maps['map3'] = PerlinFractor(Size(60, 30)).generate_map(up='map2')
#self.maps['map3'] = BinaryPartitionFractor(Size(80, 24), minimum_size=Size(10, 8)).generate_map(up='map2')
self.current_map_name = None
self.current_map = None
# TODO should this obj just switch to the first map when it starts?
# that doesn't seem right.
self.starting_map = 'map0'
def render(self, size, focus=False):
size = Size(*size)
map = self.world.current_map
map_rect = map.rect
player_position = map.find(self.world.player).position
if not self.viewport:
# Let's pretend the map itself is the viewport, and the below logic
# can adjust it as necessary.
self.viewport = self.world.current_map.rect
horizontal = self._adjust_viewport(
self.viewport.horizontal_span,
size.width,
player_position.x,
map.rect.horizontal_span,
)
vertical = self._adjust_viewport(