feat: make dragon exit after some time
This commit is contained in:
parent
4f5ad345ad
commit
1378252483
3 changed files with 30 additions and 1 deletions
|
@ -5,8 +5,13 @@ 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)
|
||||
@export var min_exit_time: float
|
||||
@export var max_exit_time: float
|
||||
|
||||
signal on_pick(dragon_id: int, position: Vector2, hat: Texture2D, shirt: Texture2D, shoes: Texture2D, dragon_name: String)
|
||||
signal on_quit(dragon_id: int)
|
||||
|
||||
var rng: RandomNumberGenerator = RandomNumberGenerator.new()
|
||||
var id: int
|
||||
|
||||
|
||||
|
@ -15,10 +20,23 @@ func _ready() -> void:
|
|||
_play_initial_animation()
|
||||
|
||||
|
||||
func _queue_exit():
|
||||
await get_tree().create_timer(rng.randf_range(min_exit_time, max_exit_time)).timeout
|
||||
var 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(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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue