40 lines
967 B
GDScript
40 lines
967 B
GDScript
extends Node
|
|
class_name NPC
|
|
|
|
@export var maxHealth: int = 0
|
|
@export var idle_sprite: String = "Healthy"
|
|
var health: int = maxHealth
|
|
@onready var player = get_tree().get_first_node_in_group("player")
|
|
|
|
signal died
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
spawn()
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
pass
|
|
|
|
func spawn() -> void:
|
|
pass
|
|
|
|
func take_damage(dmg: int) -> void:
|
|
self.health -= dmg;
|
|
if self.health < 0:
|
|
self.die()
|
|
|
|
func die() -> void:
|
|
died.emit()
|
|
queue_free()
|
|
# TODO: should associate this class with a loot table (or equivalent), and can then implement logic for dying in parent class here.
|
|
|
|
func move(destination: Vector3) -> void:
|
|
push_error("Function move() not implemented.")
|
|
|
|
func play_sprite(anim: String) -> void:
|
|
if "sprite" in self:
|
|
self.sprite.play(anim)
|
|
if "wrapper" in self:
|
|
self.wrapper.play_sprite(anim)
|