testproject/npc/npc.gd

31 lines
745 B
GDScript3
Raw Normal View History

class_name NPC
extends Node2D
var id_path: Array[Vector2i]
2024-12-08 13:21:51 +04:00
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()
$Sprite2D.set_nation(randi()%$Sprite2D.Nations.max)
set_spacesuit(false)
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta: float) -> void:
if id_path.is_empty(): return
var target_pos = Vector2(id_path.front()*World.tile_size)
global_position = global_position.move_toward(target_pos, 1)
if global_position == target_pos:
id_path.pop_front()
func set_spacesuit(suit: bool) -> void:
$Sprite2D.set_spacesuit(suit)