feat: instantiate dragons with initial animation
This commit is contained in:
parent
48b6cd42cf
commit
c422a83f59
6 changed files with 62 additions and 9 deletions
|
@ -8,11 +8,12 @@ size = Vector2(128, 128)
|
|||
|
||||
[node name="Dragon" type="Area2D" node_paths=PackedStringArray("dragon")]
|
||||
script = ExtResource("1_jccds")
|
||||
dragon = NodePath("Dragon")
|
||||
|
||||
[node name="Dragon" parent="." instance=ExtResource("2_l1h0r")]
|
||||
position = Vector2(-64, -64)
|
||||
dragon = NodePath("CollisionShape2D/Dragon")
|
||||
animation_duration = 10.0
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, 1)
|
||||
shape = SubResource("RectangleShape2D_6eaxg")
|
||||
|
||||
[node name="Dragon" parent="CollisionShape2D" instance=ExtResource("2_l1h0r")]
|
||||
position = Vector2(-64, -65)
|
||||
|
|
|
@ -3,6 +3,7 @@ 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)
|
||||
|
||||
|
@ -11,13 +12,20 @@ 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, dragon.hat.texture, dragon.shirt.texture, dragon.shoes.texture, dragon.name_label.text)
|
||||
on_pick.emit(id, position + $CollisionShape2D.position, dragon.hat.texture, dragon.shirt.texture, dragon.shoes.texture, dragon.name_label.text)
|
||||
queue_free()
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue