gae_wild_jam/scripts/enemy_base.gd

58 lines
1.4 KiB
GDScript

class_name EnemyBase
extends CharacterBody2D
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
@export var drop_table: Array[DropTable]
var is_dying = false
var speed
var witch
var player
var death_sound = preload("res://assets/music&sfx/sfx/hit2.wav")
signal died
func _ready() -> void:
add_to_group("enemies")
died.connect(get_node("/root/Game/DropManager").on_enemy_died)
witch = get_node("/root/Game/Witch")
player = get_node("/root/Game/Player")
pass # Replace with function body
func _die():
is_dying = true
collision_layer = 0
animated_sprite_2d.play("death")
var player = AudioStreamPlayer.new()
add_child(player)
player.stream = death_sound
player.bus = "SFX"
player.play()
died.emit(self)
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()