37 lines
1.1 KiB
GDScript
37 lines
1.1 KiB
GDScript
extends Area2D
|
|
class_name DragonEntity
|
|
|
|
|
|
@export var dragon: DragonSprite
|
|
@export_range(3, 20) var animation_duration: float
|
|
|
|
signal on_pick(dragon_id: int, position: Vector2, hat: Texture2D, shirt: Texture2D, shoes: Texture2D, dragon_name: String)
|
|
|
|
var id: int
|
|
|
|
|
|
func _ready() -> void:
|
|
set_process_input(true)
|
|
_play_initial_animation()
|
|
|
|
|
|
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)
|
|
|
|
|
|
func _input_event(viewport, event, shape_idx) -> void:
|
|
if event is InputEventMouseButton \
|
|
and event.button_index == MOUSE_BUTTON_LEFT \
|
|
and event.is_pressed():
|
|
on_pick.emit(id, position + $CollisionShape2D.position, dragon.hat.texture, dragon.shirt.texture, dragon.shoes.texture, dragon.name_label.text)
|
|
queue_free()
|
|
|
|
|
|
func dress(hat: Texture2D, shirt: Texture2D, shoes: Texture2D):
|
|
dragon.dress(hat, shirt, shoes)
|
|
|
|
|
|
func set_dragon_name(dragon_name: String):
|
|
dragon.set_dragon_name(dragon_name)
|