From 276b7664bd4a475a3ca93a682c16b49c504c58f7 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Mon, 6 May 2024 16:30:46 +0200 Subject: update --- Scenes/Maps/Base01.gd | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'Scenes/Maps/Base01.gd') diff --git a/Scenes/Maps/Base01.gd b/Scenes/Maps/Base01.gd index adeac93..83947e4 100644 --- a/Scenes/Maps/Base01.gd +++ b/Scenes/Maps/Base01.gd @@ -10,6 +10,32 @@ func _ready(): [], 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 @@ -71,3 +97,34 @@ func place_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 -- cgit v1.2.3