summaryrefslogtreecommitdiff
path: root/Scripts/SpawnZone.gd
blob: fdcb10a2744daee858c8cdc4d63e8f2cf75a181d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
extends Area2D
class_name SpawnZone

var spawned : bool = false

@export var anim_to_play : Array[AnimationPlayer]
@export var spawn_to_enable : Array[Spawner]

func _ready() -> void:
	var timer = Timer.new()
	add_child(timer)
	timer.wait_time = .5
	timer.timeout.connect(_timeout)
	timer.start()

func _on_body_entered(body:Node2D) -> void:
	if spawned:
		return

	if body is Entity:
		if body.is_player:
			for anim in anim_to_play:
				anim.play("close")

			for spawner in spawn_to_enable:
				spawner.all_spawned_dead.connect(_a_spawner_finished)
				spawner.start()
			
			spawned = true

var finished_counter = 0

func _a_spawner_finished() -> void:
	if finished_counter >= len(spawn_to_enable) - 1:
		for anim in anim_to_play:
			anim.play("open")
	else:
		finished_counter += 1

func _timeout() -> void:
	monitoring = true