12345678910111213141516171819202122232425 |
- extends AnimatableBody2D
- @export var color : String
- @export var speed : float = 1
- @export var height : int = 1
- @onready var start_position = position
- @onready var end_position = Vector2(position.x, position.y - 32 * height)
- @onready var path_length = start_position.y - end_position.y
- var curr_tween
- func on_button_toggled(button_color, button_enabled):
- if button_color == color:
- if curr_tween:
- curr_tween.kill()
- curr_tween = get_tree().create_tween()
- var target_position
- if button_enabled:
- target_position = Vector2(start_position.x, end_position.y)
- else:
- target_position = Vector2(start_position.x, start_position.y)
- var time = position.distance_to(target_position) / path_length * speed
- curr_tween.tween_property(self, "position", target_position, time)
|