2024-12-08 13:00:34 +04:00
|
|
|
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:
|
2024-12-08 13:21:51 +04:00
|
|
|
randomize()
|
|
|
|
add_npc(Vector2i(11, 8))
|
|
|
|
add_npc(Vector2i(9, 9))
|
|
|
|
add_npc(Vector2i(12, 11))
|
|
|
|
|
|
|
|
|
2024-12-08 13:00:34 +04:00
|
|
|
|
|
|
|
|
|
|
|
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.
|
2024-12-08 13:21:51 +04:00
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
for npc in npcs:
|
|
|
|
if not npc.is_walking():
|
|
|
|
set_npc_target(npc, Vector2i(randi()%64,randi()%64))
|
2024-12-08 13:00:34 +04:00
|
|
|
pass
|