extends Area2D class_name DragonEntity @export var dragon: DragonSprite @export_range(3, 20) var animation_duration: float @export var min_exit_time: float @export var max_exit_time: float signal on_pick(properties: DragonProperties) signal on_quit(dragon_id: int) var rng: RandomNumberGenerator = RandomNumberGenerator.new() var properties: DragonProperties func _ready() -> void: set_process_input(true) _play_initial_animation() func _queue_exit(): await get_tree().create_timer(rng.randf_range(min_exit_time, max_exit_time)).timeout var tween: Tween = get_tree().create_tween() tween.tween_property($CollisionShape2D, "position", Vector2(get_window().size.x + 200, 0), animation_duration) tween.tween_callback(_proceed_exit) func _proceed_exit(): on_quit.emit(properties.id) queue_free() func _play_initial_animation() -> void: $CollisionShape2D.position = Vector2(get_window().size.x + 200, 0) var tween = get_tree().create_tween() tween.tween_property($CollisionShape2D, "position", Vector2(0, 0), animation_duration) tween.tween_callback(_queue_exit) func _input_event(_viewport, event, _shape_idx) -> void: if event is InputEventMouseButton \ and event.button_index == MOUSE_BUTTON_LEFT \ and event.is_pressed(): properties.position = position + $CollisionShape2D.position on_pick.emit(properties) queue_free() func dress(properties: DragonProperties): dragon.dress(properties)