|
|
|
|
@ -9,9 +9,11 @@ const SMOKE_EXPLOSION = preload("res://smoke_explosion/smoke_explosion.tscn")
|
|
|
|
|
|
|
|
|
|
@onready var player = get_node("/root/Game/Player")
|
|
|
|
|
|
|
|
|
|
@export var health = 2
|
|
|
|
|
@export var speed = 100
|
|
|
|
|
@export var xp = 1
|
|
|
|
|
@export var mob_data := {
|
|
|
|
|
"health": 2,
|
|
|
|
|
"speed": 100,
|
|
|
|
|
"xp": 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
animation_player.play("walk")
|
|
|
|
|
@ -19,18 +21,18 @@ func _ready() -> void:
|
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
|
|
|
if not player: return
|
|
|
|
|
var direction = global_position.direction_to(player.global_position)
|
|
|
|
|
velocity = direction * speed
|
|
|
|
|
velocity = direction * mob_data.speed
|
|
|
|
|
move_and_slide()
|
|
|
|
|
|
|
|
|
|
func take_damage() -> void:
|
|
|
|
|
health -= 1
|
|
|
|
|
if health <= 0:
|
|
|
|
|
mob_data.health -= 1
|
|
|
|
|
if mob_data.health <= 0:
|
|
|
|
|
var smoke = SMOKE_EXPLOSION.instantiate()
|
|
|
|
|
get_parent().add_child(smoke)
|
|
|
|
|
smoke.global_position = global_position
|
|
|
|
|
explosion_sound.play()
|
|
|
|
|
await explosion_sound.finished
|
|
|
|
|
mob_died.emit(xp)
|
|
|
|
|
mob_died.emit(mob_data.xp)
|
|
|
|
|
queue_free()
|
|
|
|
|
else:
|
|
|
|
|
take_damage_sound.play()
|
|
|
|
|
|