def flood_fill(self, x, y):
        """
        flood fill the separate regions of the level, discard
        the regions that are smaller than a minimum size, and
        create a reference for the rest.
        """
        # TODO: Optimize calculations for flood fill in cellular automata
        cave = set()
        tile = (x, y)
        to_be_filled = set([tile])
        while to_be_filled:
            # print('to_be_filled:', to_be_filled)
            tile = to_be_filled.pop()

            if tile not in cave:
                cave.add(tile)
                create_wall(self.game_map, tile[0], tile[1])

                # check adjacent cells
                x = tile[0]
                y = tile[1]
                north = (x, y - 1)
                south = (x, y + 1)
                east = (x + 1, y)
                west = (x - 1, y)

                for direction in [north, south, east, west]:

                    if not self.game_map.is_blocked(direction[0],
                                                    direction[1]):
                        if direction not in to_be_filled and direction not in cave:
                            to_be_filled.add(direction)

        if len(cave) >= self.ROOM_MIN_SIZE:
            self.caves.append(cave)
    def create_caves(self, map_width, map_height):
        # ==== Create distinct caves ====
        for i in range(0, self.iterations):
            # Pick a random point with a buffer around the edges of the map
            tile_x = randint(2, map_width - 3)  # (2,map_width-3)
            tile_y = randint(2, map_height - 3)  # (2,map_height-3)

            # if the cell's neighboring walls > self.neighbors, set it to 1
            if self.get_adjacent_walls(tile_x, tile_y) > self.neighbors:
                # self.game_map.tiles[tile_x][tile_y] = 1
                create_wall(self.game_map, tile_x, tile_y)
            # or set it to 0
            elif self.get_adjacent_walls(tile_x, tile_y) < self.neighbors:
                create_floor(self.game_map, tile_x, tile_y)

        # ==== Clean Up Map ====
        self.clean_up_map(map_width, map_height)
Beispiel #3
0
    def create_walled_room(self,
                           room_x,
                           room_y,
                           room_width,
                           room_height,
                           ruined=True):
        # Sets Tiles in to Become Passable, but add walls around
        for x in range(room_x, room_x + room_width):
            for y in range(room_y, room_y + room_height):
                if x == room_x or \
                        x == room_x + room_width - 1 or \
                        y == room_y or \
                        y == room_y + room_height - 1:

                    if ruined:
                        if randint(0, 100) < 80:
                            create_wall(self.game_map, x, y)
                    else:
                        create_wall(self.game_map, x, y)
                else:
                    if ruined and randint(0, 100) < 25:
                        create_floor(self.game_map, x, y)
                    else:
                        place_tile(self.game_map, x, y, "47")
Beispiel #4
0
def close_extra_spaces(game_map):
    for x in range(game_map.width):
        for y in range(game_map.height):

            if check_open_sides(game_map, x, y):
                create_wall(game_map, x, y)