29 lines
594 B
GDScript
29 lines
594 B
GDScript
extends CharacterBody2D
|
|
|
|
var health = 3
|
|
|
|
@onready var player = get_node("/root/Game/Player")
|
|
|
|
func _ready() -> void:
|
|
%Slime.play_walk()
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
var direction = global_position.direction_to(player.global_position)
|
|
velocity = direction * 200.0
|
|
move_and_slide()
|
|
|
|
func take_damage() -> void:
|
|
const SMOKE_EXPLOSION = preload("res://smoke_explosion/smoke_explosion.tscn")
|
|
|
|
%Slime.play_hurt()
|
|
health -= 1
|
|
|
|
if health == 0:
|
|
queue_free()
|
|
var s = SMOKE_EXPLOSION.instantiate()
|
|
get_parent().add_child(s)
|
|
s.global_transform = global_transform
|
|
|
|
|
|
|