CyberTower/scripts/enemy_farm.gd

38 lines
791 B
GDScript3
Raw Normal View History

2024-02-16 12:35:30 +00:00
extends Node2D
2024-02-16 15:35:39 +00:00
signal enemy_defeat
2024-02-16 12:35:30 +00:00
@export var common_parent: Node2D
@export var path_follow: PathFollow2D
@export var target: PackedScene
@export var common_target: Node2D
2024-02-16 15:35:39 +00:00
@export var respawn_timer: Timer
2024-02-16 12:35:30 +00:00
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
2024-02-16 15:35:39 +00:00
instance.connect("enemy_defeat", _on_enemy_defeat)
2024-02-16 12:35:30 +00:00
# Add into common parent
common_parent.add_child(instance)
2024-02-16 15:35:39 +00:00
func _on_wave_finished():
respawn_timer.stop()
func _on_wave_started():
respawn_timer.start()
func _on_enemy_defeat():
enemy_defeat.emit()