CyberTower/scripts/enemy_farm.gd

45 lines
1.0 KiB
GDScript3
Raw Permalink 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-17 04:04:43 +00:00
@export var respawn_duration = 2.0
@export var respawn_multiplier = 0.25
2024-02-16 15:35:39 +00:00
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():
2024-02-17 04:04:43 +00:00
for child in common_parent.get_children():
if not child is Timer:
child.queue_free()
2024-02-16 15:35:39 +00:00
respawn_timer.stop()
2024-02-17 04:04:43 +00:00
func _on_wave_started(count):
var additional = respawn_multiplier * (count - 1)
respawn_timer.wait_time = respawn_duration - additional
2024-02-16 15:35:39 +00:00
respawn_timer.start()
func _on_enemy_defeat():
enemy_defeat.emit()