Пример #1
0
 def carve_v_corridor(y1:int, y2:int, x:int, z:int, floor_int: int, area: Area):
     """
     Carve a vertical corridor from z, x, y1 to z, x, y2
     """
     for y in range(min(y1, y2), max(y1, y2)+1):
         area.map[z, x, y] = floor_int
         area.fov_map[z, x, y] = 1
Пример #2
0
 def carve_h_corridor(x1:int, x2:int, y:int, z:int, floor_int:int, area:Area):
     """
     Carve a horizontal corridor from z, x1, y to z, x2, y
     """
     # print(f"Floor int: {floor_int}")
     for x in range(min(x1, x2), max(x1, x2)+1):
         area.map[z, x, y] = floor_int
         area.fov_map[z, x, y] = 1
Пример #3
0
    def generate_school(area:Area):
        rooms:List[str] = GrammarRule.generate(rule_school)
        
        room_list:List[Room] = []

        grid_point:List[tuple] = []
        prev_elem:Room = None
        for x in range(0,area.x_length+1, GRID_SIZE):
            for y in range(0,area.y_length+1, GRID_SIZE):
                if(x >= 0 and x < area.x_length and y >= 0 and y < area.y_length):
                    grid_point.append((x, y))
        for elem in rooms:
            #randZ = random.randrange(1 + elem.z_length, area.z_length - 2 - elem.z_length)
            grid_coords = random.choice(grid_point)
            grid_point.remove(grid_coords)
            room_list.append(RoomGenerator.generate_room(0, grid_coords[0], grid_coords[1], area, elem))
            if(prev_elem != None):
                SchoolGenerator.connect_points(
                    0, 
                    random.randrange(room_list[-1].x1, room_list[-1].x2),
                    random.randrange(prev_elem.x1, prev_elem.x2),
                    random.randrange(room_list[-1].y1, room_list[-1].y2),
                    random.randrange(prev_elem.y1, prev_elem.y2),
                    1,
                    area,
                    )
            prev_elem = room_list[-1]
        for structure in room_list:
            #Refloor every room with its floor and add the walls
            #TODO: Fix the corners not getting walls
            for x in range(structure.x1, structure.x2):
                if(structure.y1 - 1 > 0 and "blocks_movement" in area.tileset[area.map[structure.z, x, structure.y1 - 1]].flags):
                    area.map[structure.z, x, structure.y1 - 1] = structure.wall
                if("blocks_movement" in area.tileset[area.map[structure.z, x, structure.y2]].flags):
                    area.map[structure.z, x, structure.y2] = structure.wall
                for y in range(structure.y1, structure.y2):
                    area.map[structure.z, x, y] = structure.floor
                    if(structure.x1 - 1 > 0 and "blocks_movement" in area.tileset[area.map[structure.z, structure.x1 - 1, y]].flags):
                        area.map[structure.z, structure.x1-1, y] = structure.wall
                    if("blocks_movement" in area.tileset[area.map[structure.z, structure.x2, y]].flags):
                        area.map[structure.z, structure.x2, y] = structure.wall
        #Create the FoV map at the end. 
        #TODO: Handle z
        for x in range(0, area.x_length):
            for y in range(0, area.y_length):
                point = area.map[0,x,y]
                if(not "blocks_vision" in area.tileset[point].flags):
                    area.fov_map[0, x, y] = 1
                else:
                    area.fov_map[0, x, y] = 0
                tile_objects = area.get_object(0, x, y)
                if(tile_objects):
                    for tile_obj in tile_objects:
                        if "blocks_vision" in tile_obj.flags:
                            area.fov_map[0, x, y] = 0
                            break
        return room_list
Пример #4
0
def test_area():
    area = Area(1, 10, 10)
    area.map[0, 2, 2] = 1
    area.fov_map[0, 2, 2] = 1
    area.map[0, 1, 2] = 1
    area.fov_map[0, 1, 2] = 1
    area.map[0, 1, 1] = 1
    area.fov_map[0, 1, 1] = 1
    area.map[0, 2, 1] = 1
    area.fov_map[0, 2, 1] = 1
    return area
Пример #5
0
 def __init__(self, config: Dict = {}):
     self.config = config
     #setup font
     tcod.console_set_custom_font(
         "terminal8x12_gs_ro.png",
         tcod.FONT_LAYOUT_ASCII_INROW | tcod.FONT_TYPE_GREYSCALE,
     )
     tileset = {
         0:
         Entity(-1, -1, -1, '#', (100, 100, 100), {
             'blocks_movement': True,
             'blocks_vision': True
         }),
         1:
         Entity(-1, -1, -1, '.', (100, 100, 100)),
         2:
         Entity(-1, -1, -1, '#', (0, 0, 255), {
             'blocks_movement': True,
             'blocks_vision': True
         }),
         3:
         Entity(-1, -1, -1, '.', (0, 0, 255)),
         4:
         Entity(-1, -1, -1, '#', (180, 180, 180), {
             'blocks_movement': True,
             'blocks_vision': True
         }),
         5:
         Entity(-1, -1, -1, '.', (180, 180, 180)),
     }
     self.curr_area: Area = Area(2, 200, 200, tileset=tileset)
     self.SCREEN_WIDTH: int = 50
     self.SCREEN_HEIGHT: int = 50
     self.InputHandler: InputHandler = InputHandler()
     self.player: Player = Player(0, 24, 24, '@', (255, 255, 255))
     self.global_queue = ActionQueue()
     self.global_time = 0
     #TODO: Figure out panel heights for this
     self.bot_ui = UIPanel(0, self.SCREEN_HEIGHT - 5, 5, self.SCREEN_WIDTH)
     self.top_ui = UIPanel(0, 0, 5, self.SCREEN_WIDTH)
Пример #6
0
def big_area():
    area = Area(1, 50, 50)
    return area
Пример #7
0
def test_can_add_and_get_object(test_entity):
    area = Area(2, 5, 5)
    area.add_object(test_entity)
    assert area.get_object(test_entity.z, test_entity.x, test_entity.y) == [test_entity]
Пример #8
0
def test_can_instantiate_area():
    assert Area
    area = Area(1,1,1)
    assert isinstance(area, Area)
Пример #9
0
def test_can_remove_entity(test_entity):
    area = Area(2, 5, 5)
    area.add_object(test_entity)
    assert area.get_object(test_entity.z, test_entity.x, test_entity.y) == [test_entity]
    area.remove_object(test_entity)
    assert area.get_object(test_entity.z, test_entity.x, test_entity.y) == None
Пример #10
0
def test_can_add_and_get_multiple_objects(test_entity):
    copy_entity = deepcopy(test_entity)
    area = Area(2, 5, 5)
    area.add_object(test_entity)
    area.add_object(copy_entity)
    assert area.get_object(test_entity.z, test_entity.x,test_entity.y) == [test_entity, copy_entity]