From 81054b3572175ae32bddf4f636e6bb9408b4fd71 Mon Sep 17 00:00:00 2001 From: DIvan2000 Date: Sun, 8 Dec 2024 13:21:51 +0400 Subject: [PATCH] =?UTF-8?q?=D0=91=D1=80=D0=BE=D0=B6=D0=B4=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20npc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- npc/npc.gd | 3 +++ world/npcs.gd | 15 ++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) 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