Added controlable movement platform
This commit is contained in:
@@ -21,10 +21,14 @@ const ANIMATION_MAP : Dictionary[Type, Dictionary] = {
|
||||
|
||||
|
||||
@export var is_loop := false
|
||||
@export var type := Type.SelfMoving
|
||||
@export var path : Path2D
|
||||
@export var path_follow : PathFollow2D
|
||||
@export_range(0, 25, 0.1) var speed : float = 10.0
|
||||
@export var type := Type.SelfMoving:
|
||||
set(value):
|
||||
type = value
|
||||
if is_node_ready():
|
||||
_initialize_platform()
|
||||
|
||||
|
||||
var is_moving := false
|
||||
@@ -32,13 +36,26 @@ var is_reverse := false
|
||||
var tween: Tween
|
||||
|
||||
|
||||
@onready var restart_timer : Timer = $RestartTimer
|
||||
@onready var invert_timer : Timer = $InvertTimer
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
_initialize_platform()
|
||||
|
||||
|
||||
func toggle() -> void:
|
||||
if type == Type.SelfMoving: return
|
||||
|
||||
if is_moving:
|
||||
_stop_movement()
|
||||
else:
|
||||
_start_movement()
|
||||
|
||||
|
||||
func _initialize_platform() -> void:
|
||||
if not Engine.is_editor_hint() and type == Type.SelfMoving:
|
||||
start_movement()
|
||||
_start_movement()
|
||||
else:
|
||||
_select_animation()
|
||||
|
||||
@@ -49,12 +66,12 @@ func _select_animation() -> void:
|
||||
icon_sprite.play(ANIMATION_SELF_MOVING)
|
||||
return
|
||||
|
||||
var direction : String = ANIMATION_MAP[type][is_reverse]
|
||||
var direction : String = ANIMATION_MAP[type][not is_reverse]
|
||||
var suffix := ANIMATION_ACTIVE_SUFFIX if is_moving else ANIMATION_STATIC_SUFFIX
|
||||
icon_sprite.play(ANIMATION_MOVING_PREFIX + direction + suffix)
|
||||
|
||||
|
||||
func start_movement() -> void:
|
||||
func _start_movement() -> void:
|
||||
is_moving = true
|
||||
if tween and tween.is_running():
|
||||
tween.kill()
|
||||
@@ -67,22 +84,23 @@ func start_movement() -> void:
|
||||
tween = create_tween()
|
||||
var target_ratio := 0.0 if is_reverse else 1.0
|
||||
tween.tween_property(path_follow, "progress_ratio", target_ratio, duration)
|
||||
tween.finished.connect(_restart_movement)
|
||||
tween.finished.connect(_invert_movement)
|
||||
|
||||
|
||||
func stop_movement() -> void:
|
||||
func _stop_movement() -> void:
|
||||
is_moving = false
|
||||
if tween and tween.is_running():
|
||||
tween.kill()
|
||||
if not invert_timer.is_stopped():
|
||||
invert_timer.stop()
|
||||
_select_animation()
|
||||
|
||||
|
||||
func _restart_movement() -> void:
|
||||
is_moving = false
|
||||
func _invert_movement() -> void:
|
||||
if is_loop:
|
||||
path_follow.progress_ratio = 0
|
||||
else:
|
||||
is_reverse = not is_reverse
|
||||
|
||||
_select_animation()
|
||||
restart_timer.start()
|
||||
invert_timer.start()
|
||||
|
||||
Reference in New Issue
Block a user