blob: 7c54dfcdbdeea4de628716d65752f7f837c37e70 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
extends Node2D
@onready var map_config = preload("res://resources/map_generator_resource.tres")
@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 * map_config.tile_size + Vector2i.ONE * (map_config.tile_size / 2))
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)
|