Add new room type : chunk rooms
This commit is contained in:
		@@ -13,7 +13,7 @@ DEFAULT_PARAMS = {
 | 
				
			|||||||
    "max_rooms": 20,
 | 
					    "max_rooms": 20,
 | 
				
			||||||
    "max_room_tries": 15,
 | 
					    "max_room_tries": 15,
 | 
				
			||||||
    "cross_room": 1,
 | 
					    "cross_room": 1,
 | 
				
			||||||
    "corridor_chance": .6,
 | 
					    "corridor_chance": .2,
 | 
				
			||||||
    "min_v_corr": 2,
 | 
					    "min_v_corr": 2,
 | 
				
			||||||
    "max_v_corr": 6,
 | 
					    "max_v_corr": 6,
 | 
				
			||||||
    "min_h_corr": 4,
 | 
					    "min_h_corr": 4,
 | 
				
			||||||
@@ -24,6 +24,10 @@ DEFAULT_PARAMS = {
 | 
				
			|||||||
    "loop_max": 5,
 | 
					    "loop_max": 5,
 | 
				
			||||||
    "loop_threshold": 15,
 | 
					    "loop_threshold": 15,
 | 
				
			||||||
    "spawn_per_region": [1, 2],
 | 
					    "spawn_per_region": [1, 2],
 | 
				
			||||||
 | 
					    "room_chances" : {
 | 
				
			||||||
 | 
					        "circular" : 5,
 | 
				
			||||||
 | 
					        "chunks" : 1,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def dist(level, y1, x1, y2, x2):
 | 
					def dist(level, y1, x1, y2, x2):
 | 
				
			||||||
@@ -253,6 +257,47 @@ class Generator:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return y + length * dy, x + length * dx, dy, dx
 | 
					        return y + length * dy, x + length * dx, dy, dx
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def create_chunk_room(self, spawnable: bool = True) \
 | 
				
			||||||
 | 
					            -> Tuple[List[List[Tile]], int, int, int, int]:
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        Create and return as a tile grid a room that is composed of multiple
 | 
				
			||||||
 | 
					        overlapping circles of the same radius
 | 
				
			||||||
 | 
					        Also return door info so we know how to place the room in the level
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        height, width = 15, 15
 | 
				
			||||||
 | 
					        nb_chunks, r = 6, 3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        h_sup, w_sup, h_off, w_off = self.corr_meta_info()
 | 
				
			||||||
 | 
					        room = [[Tile.EMPTY] * (width + w_sup) \
 | 
				
			||||||
 | 
					                for _dummy in range(height + h_sup)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        def draw_chunk(room, y, x):
 | 
				
			||||||
 | 
					            for i in range(y - r, y + r + 1):
 | 
				
			||||||
 | 
					                d = (y - i)**2
 | 
				
			||||||
 | 
					                for j in range(x - r, x + r + 1):
 | 
				
			||||||
 | 
					                    if d + (x - j)**2 < r**2:
 | 
				
			||||||
 | 
					                        room[i][j] = Tile.FLOOR
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        draw_chunk(room, height//2 + 1, width//2 + 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        min_w, max_w = w_off + r + 1, width + w_off - r -1
 | 
				
			||||||
 | 
					        min_h, max_h = h_off + r + 1, height + h_off - r - 1
 | 
				
			||||||
 | 
					        for i in range(nb_chunks):
 | 
				
			||||||
 | 
					            y, x = randint(min_h, max_h), randint(min_w, max_w)
 | 
				
			||||||
 | 
					            while room[y][x] != Tile.FLOOR:
 | 
				
			||||||
 | 
					                y, x = randint(min_h, max_h), randint(min_w, max_w)
 | 
				
			||||||
 | 
					            draw_chunk(room, y, x)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # log all placed tiles as spawn positions
 | 
				
			||||||
 | 
					        if spawnable:
 | 
				
			||||||
 | 
					            self.register_spawn_area(room)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # attach exit
 | 
				
			||||||
 | 
					        door_y, door_x, dy, dx = self.attach_door(room, h_sup, w_sup,
 | 
				
			||||||
 | 
					                                                  h_off, w_off)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return room, door_y, door_x, dy, dx
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def create_circular_room(self, spawnable: bool = True) \
 | 
					    def create_circular_room(self, spawnable: bool = True) \
 | 
				
			||||||
            -> Tuple[List[List[Tile]], int, int, int, int]:
 | 
					            -> Tuple[List[List[Tile]], int, int, int, int]:
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
@@ -303,7 +348,19 @@ class Generator:
 | 
				
			|||||||
        door info. Set spawnable to False is the room should be marked as a
 | 
					        door info. Set spawnable to False is the room should be marked as a
 | 
				
			||||||
        potential spawning region on the map
 | 
					        potential spawning region on the map
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        return self.create_circular_room()
 | 
					        coef_dict = self.params["room_chances"]
 | 
				
			||||||
 | 
					        sum_coefs = sum(coef_dict[key] for key in coef_dict)
 | 
				
			||||||
 | 
					        target = randint(1, sum_coefs)
 | 
				
			||||||
 | 
					        for key in coef_dict:
 | 
				
			||||||
 | 
					            if target > coef_dict[key]:
 | 
				
			||||||
 | 
					                target -= coef_dict[key]
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                break
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if key == "circular":
 | 
				
			||||||
 | 
					            return self.create_circular_room(spawnable = spawnable)
 | 
				
			||||||
 | 
					        elif key == "chunks":
 | 
				
			||||||
 | 
					            return self.create_chunk_room(spawnable = spawnable)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def register_spawn_area(self, area: List[List[Tile]]) -> None:
 | 
					    def register_spawn_area(self, area: List[List[Tile]]) -> None:
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user