def generate_room(self, section): """ Generate room :param section: section for generator to draw to :type section: Section """ middle_height = section_height(section) // 2 middle_width = section_width(section) // 2 if len([x for x in section_connections(section) if x.direction == 'right']) > 0: room_left_edge = self.rng.randint(2, middle_width - 2) else: room_left_edge = 1 if len([x for x in section_connections(section) if x.direction == 'left']) > 0: room_right_edge = self.rng.randint(middle_width + 2, section_width(section) - 2) else: room_right_edge = section_width(section) - 1 if len([x for x in section_connections(section) if x.direction == 'down']) > 0: room_top_edge = self.rng.randint(2, middle_height - 2) else: room_top_edge = 1 if len([x for x in section_connections(section) if x.direction == 'up']) > 0: room_bottom_edge = self.rng.randint(middle_height + 2, section_height(section) - 2) else: room_bottom_edge = section_height(section) - 1 for loc_y in range(room_top_edge + 1, room_bottom_edge): for loc_x in range(room_left_edge + 1, room_right_edge): section_floor(section, (loc_x, loc_y), self.floor_tile, 'room') section_wall(section, (loc_x, loc_y), self.empty_tile, None) center_x = (room_right_edge - room_left_edge) // 2 + room_left_edge center_y = (room_bottom_edge - room_top_edge) // 2 + room_top_edge add_room_connection(section, (center_x, room_top_edge), "up") add_room_connection(section, (center_x, room_bottom_edge), "down") add_room_connection(section, (room_left_edge, center_y), "left") add_room_connection(section, (room_right_edge, center_y), "right") self.add_corridors(section) self.room_corners = [] self.room_corners.append((room_left_edge + 1, room_top_edge + 1)) self.room_corners.append((room_right_edge - 1, room_top_edge + 1)) self.room_corners.append((room_right_edge - 1, room_bottom_edge - 1)) self.room_corners.append((room_left_edge + 1, room_bottom_edge - 1)) self.add_rows()
def add_pillar(self, section, corner, pillar): """ Add pillar if location is free """ location = (corner[0] + pillar[0], corner[1] + pillar[1]) if section_wall(section, location) == self.empty_tile: section_wall(section, location, self.pillar_tile, None) section_floor(section, location, None, None)
def generate_room(self, section): """ Generate room :param section: section for generator to draw to :type section: Section """ level_size = (section_width(section), section_height(section)) for x_loc in range(1, level_size[0]): for y_loc in range(1, level_size[1]): section_floor(section, (x_loc, y_loc), self.floor_tile, 'room') section_wall(section, (x_loc, y_loc), self.empty_tile, None)
def __carve_horizontal(self, start_point, end_point): """ Special case, carving is done in straigth horizontal line :param start_point: starting connection :type start_point: Connection :param end_point: ending connection :type end_point: Connection """ if start_point.location[0] > end_point.location[0]: start_x = end_point.location[0] end_x = start_point.location[0] else: start_x = start_point.location[0] end_x = end_point.location[0] y_loc = start_point.location[1] section = start_point.section for x_loc in range(start_x, end_x): section_wall(section, (x_loc, y_loc), self.wall_tile, 'corridor') section_floor(section, (x_loc, y_loc), self.floor_tile, None) section_wall(section, end_point.location, self.wall_tile, 'corridor') section_wall(section, start_point.location, self.wall_tile, 'corridor') section_floor(section, end_point.location, self.floor_tile, None) section_floor(section, start_point.location, self.floor_tile, None)
def generate_room(self, section): """ Generate room :param section: section for generator to draw to :type section: Section """ level_size = (section_width(section), section_height(section)) room_min_size = (3, 3) BSPStack = [] BSP = BSPSection((0, 0), (level_size[0] - 2, level_size[1] - 2), None) BSPStack.append(BSP) room_stack = [] while len(BSPStack) > 0: tempBSP = BSPStack.pop() tempBSP.split(min_size=(room_min_size[0] + 4, room_min_size[1] + 4)) if tempBSP.node1 is not None: BSPStack.append(tempBSP.node1) if tempBSP.node2 is not None: BSPStack.append(tempBSP.node2) if tempBSP.node1 is None and tempBSP.node2 is None: #leaf room_stack.append(tempBSP) for room in room_stack: corner1 = (room.corner1[0] + self.rng.randint(1, 4), room.corner1[1] + self.rng.randint(1, 4)) corner2 = (room.corner2[0] - self.rng.randint(1, 4), room.corner2[1] - self.rng.randint(1, 4)) for y in range(corner1[1], corner2[1] + 1): for x in range(corner1[0], corner2[0] + 1): section_floor(section, (x, y), self.floor_tile, 'room') section_wall(section, (x, y), self.empty_tile, None) area_queue = BSP.get_area_queue() area_queue.reverse() while len(area_queue) > 1: area1 = area_queue.pop() area2 = area_queue.pop() center1 = area1.get_center() center2 = area2.get_center() #connect these two areas if area1.direction == 1: #areas on top of each other if center1[1] < center2[1]: for y in range(center1[1], center2[1] + 1): section_floor(section, (center1[0], y), self.floor_tile, 'corridor') section_wall(section, (center1[0], y), self.empty_tile, None) else: for y in range(center2[1], center1[1] + 1): section_floor(section, (center1[0], y), self.floor_tile, 'corridor') section_wall(section, (center1[0], y), self.empty_tile, None) else: #areas next to each other if center1[0] < center2[0]: for x in range(center1[0], center2[0] + 1): section_floor(section, (x, center1[1]), self.floor_tile, 'corridor') section_wall(section, (x, center1[1]), self.empty_tile, None) else: for x in range(center2[0], center1[0] + 1): section_floor(section, (x, center1[1]), self.floor_tile, 'corridor') section_wall(section, (x, center1[1]), self.empty_tile, None)
def generate_room(self, section): """ Generate room :param section: section for generator to draw to :type section: Section """ middle_height = section_height(section) // 2 middle_width = section_width(section) // 2 if len([ x for x in section_connections(section) if x.direction == 'right' ]) > 0: room_left_edge = self.rng.randint(2, middle_width - 2) else: room_left_edge = 1 if len( [x for x in section_connections(section) if x.direction == 'left' ]) > 0: room_right_edge = self.rng.randint(middle_width + 2, section_width(section) - 2) else: room_right_edge = section_width(section) - 1 if len( [x for x in section_connections(section) if x.direction == 'down' ]) > 0: room_top_edge = self.rng.randint(2, middle_height - 2) else: room_top_edge = 1 if len([ x for x in section_connections(section) if x.direction == 'up' ]) > 0: room_bottom_edge = self.rng.randint(middle_height + 2, section_height(section) - 2) else: room_bottom_edge = section_height(section) - 1 for loc_y in range(room_top_edge + 1, room_bottom_edge): for loc_x in range(room_left_edge + 1, room_right_edge): section_floor(section, (loc_x, loc_y), self.floor_tile, 'room') section_wall(section, (loc_x, loc_y), self.empty_tile, None) center_x = (room_right_edge - room_left_edge) // 2 + room_left_edge center_y = (room_bottom_edge - room_top_edge) // 2 + room_top_edge add_room_connection(section, (center_x, room_top_edge), "up") add_room_connection(section, (center_x, room_bottom_edge), "down") add_room_connection(section, (room_left_edge, center_y), "left") add_room_connection(section, (room_right_edge, center_y), "right") self.add_corridors(section) self.room_corners = [] self.room_corners.append((room_left_edge + 1, room_top_edge + 1)) self.room_corners.append((room_right_edge - 1, room_top_edge + 1)) self.room_corners.append((room_right_edge - 1, room_bottom_edge - 1)) self.room_corners.append((room_left_edge + 1, room_bottom_edge - 1)) self.add_rows()