extends "res://Scenes/Maps/Map.gd" func _ready(): super._ready() place_boxes( get_node("Areas/MapArea/TileMap"), 40, [], get_node("Areas/MapArea/Transitions").get_children() ) place_boxes( get_node("Areas/MapArea2/TileMap"), 40, [], get_node("Areas/MapArea2/Objects").get_children() ) get_node("Areas/MapArea2").transitioned_to.connect(func(): handle_doors( get_node("Areas/MapArea2/Objects").get_children(), door_condition_enemies(Utilities.get_enemy_children(get_node("Areas/MapArea2/TileMap"))) ) ) place_boxes( get_node("Areas/MapArea6/TileMap"), 40, [], get_node("Areas/MapArea6/Objects").get_children() ) get_node("Areas/MapArea6").transitioned_to.connect(func(): handle_doors( get_node("Areas/MapArea6/Objects").get_children(), door_condition_enemies(Utilities.get_enemy_children(get_node("Areas/MapArea6/TileMap"))) ) ) # set box to random position without polygon points func place_boxes( tilemap: TileMap, number_of_boxes: int, entities: Array = [], entry_entities: Array = [], include_edges: bool = true ): var number_of_layers = 7 var placeable_cells = [] for layer_idx in range(number_of_layers): placeable_cells += tilemap.get_used_cells(layer_idx).filter(func(coords): var data: TileData = tilemap.get_cell_tile_data(layer_idx, coords) # not data == scene collection source if ( placeable_cells.has(coords) and (data and data.get_collision_polygons_count(0) > 0 or not data) ): placeable_cells.remove_at(placeable_cells.find(coords)) return data and data.get_collision_polygons_count(0) == 0 ) for entity in entities: placeable_cells.erase(tilemap.local_to_map(entity.position)) var tile_size = tilemap.tile_set.tile_size for entity in entry_entities: placeable_cells.erase(tilemap.local_to_map(entity.position)) placeable_cells.erase(tilemap.local_to_map( entity.position + Vector2(0, tile_size.y) )) placeable_cells.erase(tilemap.local_to_map( entity.position + Vector2(tile_size.x, 0) )) placeable_cells.erase(tilemap.local_to_map( entity.position + Vector2(0, -tile_size.y) )) placeable_cells.erase(tilemap.local_to_map( entity.position + Vector2(-tile_size.x, 0) )) if include_edges: var rect := tilemap.get_used_rect() for x in range(rect.position.x, rect.end.x - 1): placeable_cells.erase(Vector2i(x, 0)) placeable_cells.erase(Vector2i(x, rect.end.y - 1)) for y in range(rect.position.y, rect.end.y - 1): placeable_cells.erase(Vector2i(0, y)) placeable_cells.erase(Vector2i(rect.end.x - 1, y)) placeable_cells.shuffle() var BoxScene = preload("res://Scenes/Entities/Objects/Box.tscn") for number in range(number_of_boxes): var box = BoxScene.instantiate() box.position = tilemap.map_to_local(placeable_cells[number]) tilemap.add_child(box) func handle_doors(doors: Array, condition): for door in doors: door.enable() if condition.check(): for door in doors: door.disable() condition.fulfilled.connect(func(): for door in doors: door.disable() ) func door_condition_enemies(enemies: Array): var condition = Utilities.Condition.new() condition.function = func(): for enemy in enemies: enemy.tree_exited.connect(func(): enemies.erase(enemy) if enemies.is_empty(): condition.fulfilled.emit() ) if enemies.is_empty(): return true return false return condition