34 lines
850 B
GDScript3
34 lines
850 B
GDScript3
|
extends Node2D
|
||
|
|
||
|
const NPC_SCENE = preload("res://npc/npc.tscn")
|
||
|
|
||
|
var npcs: Array[NPC]
|
||
|
|
||
|
|
||
|
func add_npc(pos: Vector2i):
|
||
|
var npc: NPC = NPC_SCENE.instantiate()
|
||
|
npc.translate(pos*World.tile_size)
|
||
|
npcs.append(npc)
|
||
|
add_child(npc)
|
||
|
|
||
|
# Called when the node enters the scene tree for the first time.
|
||
|
func _ready() -> void:
|
||
|
add_npc(Vector2i(16, 8))
|
||
|
add_npc(Vector2i(40, 32))
|
||
|
set_npc_target(npcs[0], Vector2i(24, 48))
|
||
|
set_npc_target(npcs[1], Vector2i(24, 49))
|
||
|
|
||
|
|
||
|
func set_npc_target(npc: NPC, target: Vector2i):
|
||
|
var id_path = $"../TileMap".astar_grid.get_id_path(
|
||
|
$"../TileMap/ground".local_to_map(npc.global_position+$"../TileMap/ground".global_position),
|
||
|
target
|
||
|
).slice(1)
|
||
|
|
||
|
if not id_path.is_empty():
|
||
|
npc.id_path = id_path
|
||
|
|
||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||
|
func _process(delta: float) -> void:
|
||
|
pass
|