Code Duplication    Length = 28-28 lines in 2 locations

examples/samples_libtcodpy.py 1 location

@@ 1065-1092 (lines=28) @@
1062
def render_bsp(first, key, mouse):
1063
    global bsp, bsp_generate, bsp_refresh, bsp_map
1064
    global bsp_random_room, bsp_room_walls, bsp_depth, bsp_min_room_size
1065
    if bsp_generate or bsp_refresh:
1066
        # dungeon generation
1067
        if bsp is None:
1068
            # create the bsp
1069
            bsp = libtcod.bsp_new_with_size(0, 0, SAMPLE_SCREEN_WIDTH,
1070
                                            SAMPLE_SCREEN_HEIGHT)
1071
        else:
1072
            # restore the nodes size
1073
            libtcod.bsp_resize(bsp, 0, 0, SAMPLE_SCREEN_WIDTH,
1074
                               SAMPLE_SCREEN_HEIGHT)
1075
        bsp_map = list()
1076
        for x in range(SAMPLE_SCREEN_WIDTH):
1077
            bsp_map.append([False] * SAMPLE_SCREEN_HEIGHT)
1078
        if bsp_generate:
1079
            # build a new random bsp tree
1080
            libtcod.bsp_remove_sons(bsp)
1081
            if bsp_room_walls:
1082
                libtcod.bsp_split_recursive(bsp, 0, bsp_depth,
1083
                                            bsp_min_room_size + 1,
1084
                                            bsp_min_room_size + 1, 1.5, 1.5)
1085
            else:
1086
                libtcod.bsp_split_recursive(bsp, 0, bsp_depth,
1087
                                            bsp_min_room_size,
1088
                                            bsp_min_room_size, 1.5, 1.5)
1089
        # create the dungeon from the bsp
1090
        libtcod.bsp_traverse_inverted_level_order(bsp, traverse_node)
1091
        bsp_generate = False
1092
        bsp_refresh = False
1093
    libtcod.console_clear(sample_console)
1094
    libtcod.console_set_default_foreground(sample_console, libtcod.white)
1095
    rooms = 'OFF'

examples/samples_tcod.py 1 location

@@ 911-938 (lines=28) @@
908
            if left.y + left.h - 1 < right.y or right.y + right.h - 1 < left.y:
909
                # no overlapping zone. we need a Z shaped corridor
910
                y1 = libtcod.random_get_int(None, left.y, left.y + left.h - 1)
911
                y2 = libtcod.random_get_int(None,
912
                                            right.y, right.y + right.h - 1)
913
                x = libtcod.random_get_int(None, left.x + left.w, right.x)
914
                hline_left(bsp_map, x - 1, y1)
915
                vline(bsp_map, x, y1, y2)
916
                hline_right(bsp_map, x + 1, y2)
917
            else:
918
                # straight horizontal corridor
919
                miny = max(left.y, right.y)
920
                maxy = min(left.y + left.h - 1, right.y + right.h - 1)
921
                y = libtcod.random_get_int(None, miny, maxy)
922
                hline_left(bsp_map, right.x - 1, y)
923
                hline_right(bsp_map, right.x, y)
924
    return True
925
926
bsp = None
927
bsp_generate = True
928
bsp_refresh = False
929
class BSPSample(Sample):
930
    def __init__(self):
931
        self.name = 'Bsp toolkit'
932
933
    def on_draw(self, delta_time):
934
        global bsp, bsp_generate, bsp_refresh, bsp_map
935
        global bsp_random_room, bsp_room_walls, bsp_depth, bsp_min_room_size
936
        if bsp_generate or bsp_refresh:
937
            # dungeon generation
938
            if bsp is None:
939
                # create the bsp
940
                bsp = libtcod.bsp_new_with_size(0, 0, SAMPLE_SCREEN_WIDTH,
941
                                                SAMPLE_SCREEN_HEIGHT)