CyberTower/scripts/enemy_farm.gd
2024-02-16 23:35:39 +08:00

38 lines
791 B
GDScript

extends Node2D
signal enemy_defeat
@export var common_parent: Node2D
@export var path_follow: PathFollow2D
@export var target: PackedScene
@export var common_target: Node2D
@export var respawn_timer: Timer
func spawn():
var instance = target.instantiate()
# Randomize
path_follow.progress_ratio = randi()
instance.position = path_follow.position
var target_scale = randf_range(0.2, 0.95)
instance.scale = Vector2(target_scale, target_scale)
instance.speed = randi_range(800, 1400)
instance.target = common_target
instance.connect("enemy_defeat", _on_enemy_defeat)
# Add into common parent
common_parent.add_child(instance)
func _on_wave_finished():
respawn_timer.stop()
func _on_wave_started():
respawn_timer.start()
func _on_enemy_defeat():
enemy_defeat.emit()