gae_wild_jam/scripts/enemy_base.gd

45 lines
1.0 KiB
GDScript

class_name EnemyBase
extends CharacterBody2D
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
var is_dying = false
var speed
var witch
var player
func _ready() -> void:
witch = get_node("/root/Game/Witch")
player = get_node("/root/Game/Player")
pass # Replace with function body
func _die():
is_dying = true
animated_sprite_2d.play("death")
await animated_sprite_2d.animation_finished
queue_free()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _chase_witch() -> void:
var direction = Vector2(witch.global_position - global_position)
velocity = direction * speed
velocity = direction * speed
if direction == Vector2.ZERO:
animated_sprite_2d.play("idle")
elif abs(direction.x) >= abs(direction.y):
if direction.x < 0:
animated_sprite_2d.play("walk_left")
else:
animated_sprite_2d.play("walk_right")
else:
if direction.y < 0:
animated_sprite_2d.play("walk_up")
else:
animated_sprite_2d.play("walk_down")
move_and_slide()