2023-10-06 19:25:13 +07:00
|
|
|
extends PathFollow2D
|
|
|
|
|
|
|
|
var config = null
|
|
|
|
var enemy_id: int = 0
|
|
|
|
var health: int = 0
|
|
|
|
var speed: int = 0
|
|
|
|
|
|
|
|
func set_config(config_path):
|
|
|
|
config = load(config_path).new()
|
|
|
|
|
|
|
|
func set_enemy(id: int):
|
|
|
|
enemy_id = id
|
|
|
|
health = config.enemy[enemy_id]['health']
|
|
|
|
speed = config.enemy[enemy_id]['speed']
|
|
|
|
|
|
|
|
func _process(delta):
|
|
|
|
update_healthbar()
|
|
|
|
if health <= 0:
|
|
|
|
queue_free()
|
|
|
|
set_progress(get_progress() + speed * delta)
|
|
|
|
|
|
|
|
func update_healthbar():
|
2023-10-06 22:47:24 +07:00
|
|
|
$EnemyBody/HealthBar.value = health
|
2023-10-06 19:25:13 +07:00
|
|
|
|
|
|
|
if health >= 100:
|
2023-10-06 22:47:24 +07:00
|
|
|
$EnemyBody/HealthBar.visible = false
|
2023-10-06 19:25:13 +07:00
|
|
|
else:
|
2023-10-06 22:47:24 +07:00
|
|
|
$EnemyBody/HealthBar.visible = true
|
2023-10-06 19:25:13 +07:00
|
|
|
|
|
|
|
func hit(damage : int):
|
|
|
|
health = health - damage
|