2024-10-16 15:16:54 -06:00
|
|
|
# base NPCEnemy class
|
2024-10-15 08:37:50 -06:00
|
|
|
class_name NPCEnemy
|
2024-10-13 20:43:25 -06:00
|
|
|
extends NPC
|
2024-10-13 20:42:32 -06:00
|
|
|
|
|
|
|
|
2024-10-17 16:50:40 -06:00
|
|
|
@export var killType: WorldArea.KillTypes = WorldArea.KillTypes.NATURAL
|
2024-10-13 20:42:32 -06:00
|
|
|
|
2024-10-15 15:04:40 -06:00
|
|
|
var target
|
|
|
|
var speed := 300
|
|
|
|
var prevCollisions := 0
|
|
|
|
|
2024-10-13 20:42:32 -06:00
|
|
|
|
|
|
|
func _init() -> void:
|
2024-10-17 14:11:10 -06:00
|
|
|
self.npcDifficulty = NPCDifficulties.NORMAL
|
|
|
|
self.npcTier = NPCTiers.I
|
2024-10-13 20:42:32 -06:00
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
# add to enemies
|
|
|
|
add_to_group("enemies")
|
|
|
|
|
2024-10-15 08:14:02 -06:00
|
|
|
# set health
|
2024-10-13 20:42:32 -06:00
|
|
|
_random_mod_health()
|
2024-10-15 08:14:02 -06:00
|
|
|
|
|
|
|
# set health bar
|
|
|
|
%Healthbar.max_value = maxHealth
|
|
|
|
%Healthbar.value = maxHealth
|
2024-10-13 20:42:32 -06:00
|
|
|
|
2024-10-17 16:50:40 -06:00
|
|
|
|
2024-10-15 08:14:02 -06:00
|
|
|
func _process(_delta: float) -> void:
|
|
|
|
%Healthbar.value = maxHealth - damageTaken
|
|
|
|
if damageTaken >= maxHealth:
|
2024-10-17 16:50:40 -06:00
|
|
|
# save vars to emit
|
|
|
|
var enemyDifficulty = self.npcDifficulty
|
|
|
|
var enemyKillType = self.killType
|
2024-10-15 08:14:02 -06:00
|
|
|
# delete node
|
2024-10-17 16:50:40 -06:00
|
|
|
self.remove_from_group("enemies")
|
2024-10-15 08:14:02 -06:00
|
|
|
self.queue_free()
|
2024-10-17 16:50:40 -06:00
|
|
|
# send signal that I died to be counted, etc.
|
|
|
|
SignalBus.enemy_died.emit(enemyDifficulty, enemyKillType)
|
|
|
|
|
2024-10-15 15:04:40 -06:00
|
|
|
|
|
|
|
func _physics_process(_delta):
|
|
|
|
velocity = position.direction_to(target) * speed
|
|
|
|
# look_at(target)
|
2024-10-17 16:50:40 -06:00
|
|
|
# FIXME: want enemy to stop when touching something, to prevent vibrating
|
2024-10-15 15:04:40 -06:00
|
|
|
if position.distance_to(target) > 10 and get_slide_collision_count() == prevCollisions:
|
|
|
|
move_and_slide()
|
|
|
|
prevCollisions = get_slide_collision_count()
|