33 lines
715 B
GDScript
33 lines
715 B
GDScript
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:
|
|
randomize()
|
|
add_npc(Vector2i(11, 8))
|
|
add_npc(Vector2i(9, 9))
|
|
add_npc(Vector2i(12, 11))
|
|
|
|
|
|
|
|
|
|
func set_npc_target(npc: NPC, target: Vector2i):
|
|
npc.set_target(target)
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _physics_process(delta: float) -> void:
|
|
for npc in npcs:
|
|
if not npc.is_walking():
|
|
set_npc_target(npc, Vector2i(randi()%64,randi()%64))
|
|
pass
|