handles enemy respawning properly

This commit is contained in:
Patrick Nueser
2024-06-28 16:12:11 +02:00
parent 1e4be7ba8d
commit 3cf084e69b
17 changed files with 1342 additions and 21 deletions

View File

@ -23,12 +23,19 @@ func spawn_enemies():
var e = enemy.instantiate()
var pos = Vector2(x * (16 + 8) + 24, 16 * 4 + y * 16)
add_child(e)
e.start(pos)
e.died.connect(_on_enemy_died)
e.call_deferred("start", pos)
e.connect("died", Callable(self, "_on_enemy_died"))
e.add_to_group("enemies")
enemies_count = 27
func _on_enemy_died(value):
score += value
$CanvasLayer/UI.update_score(score)
enemies_count -= 1
if enemies_count == 0:
call_deferred("spawn_enemies")
func _on_start_pressed():
start_button.hide()
@ -41,11 +48,3 @@ func _on_player_died():
game_over.hide()
start_button.show()
func _on_child_entered_tree(node):
if node.is_in_group("enemies"):
enemies_count += 1
func _on_child_exiting_tree(node):
if node.is_in_group("enemies"):
enemies_count -= 1