diff --git a/npc/npc.gd b/npc/npc.gd index 51d4be6..97d2bad 100644 --- a/npc/npc.gd +++ b/npc/npc.gd @@ -3,6 +3,9 @@ extends Node2D var id_path: Array[Vector2i] +func is_walking() -> bool: + return not id_path.is_empty() + # Called when the node enters the scene tree for the first time. func _ready() -> void: randomize() diff --git a/world/npcs.gd b/world/npcs.gd index 8117dc5..a37dea3 100644 --- a/world/npcs.gd +++ b/world/npcs.gd @@ -13,10 +13,12 @@ func add_npc(pos: Vector2i): # 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)) + randomize() + add_npc(Vector2i(11, 8)) + add_npc(Vector2i(9, 9)) + add_npc(Vector2i(12, 11)) + + func set_npc_target(npc: NPC, target: Vector2i): @@ -29,5 +31,8 @@ func set_npc_target(npc: NPC, target: Vector2i): npc.id_path = id_path # Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta: float) -> void: +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