diff options
Diffstat (limited to 'Scenes/Maps/Base01.gd')
-rw-r--r-- | Scenes/Maps/Base01.gd | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/Scenes/Maps/Base01.gd b/Scenes/Maps/Base01.gd new file mode 100644 index 0000000..adeac93 --- /dev/null +++ b/Scenes/Maps/Base01.gd @@ -0,0 +1,73 @@ +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() + ) + + +# 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) |