diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-05-03 09:32:22 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-05-03 09:32:22 +0200 |
commit | 516d22c1737a9c94026b5ff0c9856bc5549aa416 (patch) | |
tree | cd9ef3089d1c8bdfc440b5673f7ad0d0dce787a9 /Scenes/Maps/Base01.gd | |
parent | d192b1546ab39180cdc28d2621c117539e3d26d6 (diff) |
update
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) |