extends CharacterBody2D

enum States {
	IDLE,
	PECKING
}

@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D

var current_state := States.IDLE
var pecking_sched := randf_range(8.0, 25.0)
var pecking_timer := 0.0

func _ready() -> void:
	_print_sched()


func _process(delta: float) -> void:
	if current_state == States.IDLE:
		pecking_timer += delta
		if pecking_timer >= pecking_sched:
			current_state = States.PECKING
			animated_sprite_2d.play("pecking")
			await animated_sprite_2d.animation_finished
			animated_sprite_2d.play("idle")
			pecking_sched = randf_range(8.0, 25.0)
			pecking_timer = 0
			current_state = States.IDLE
			_print_sched()


func _print_sched() -> void:
	print("%s Pecking Schedule: %f" % [name, pecking_sched])
