diff options
Diffstat (limited to 'scripts/wave_spawner.gd')
-rw-r--r-- | scripts/wave_spawner.gd | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/scripts/wave_spawner.gd b/scripts/wave_spawner.gd new file mode 100644 index 0000000..3f63c71 --- /dev/null +++ b/scripts/wave_spawner.gd @@ -0,0 +1,35 @@ +extends Node2D + +@onready var fodder_enemy = preload("res://scenes/soldier.tscn") +@onready var map = get_node("../Map") + +var curve : Curve2D + +func _ready() -> void: + curve = Curve2D.new() + + var path : Array[Vector2i] = map.get_enemy_path() + + # add off-screen points + path.insert(0, path[0] - Vector2i(1, 0)) + path.append(path[path.size() - 1] + Vector2i(1, 0)) + + # adjust to grid size + for i in map.get_enemy_path(): + curve.add_point(i * 16 + Vector2i.ONE * 8) + +func _on_timer_timeout(): + var path = Path2D.new() + path.curve = curve + + var follow_path = PathFollow2D.new() + follow_path.set_progress(0) + follow_path.rotates = false + follow_path.loop = false + + var enemy = fodder_enemy.instantiate() + + follow_path.add_child(enemy) + path.add_child(follow_path) + + add_child(path) |