xiandie/scene/ground/scene/c02/s09_animation.gd
2025-06-16 12:43:09 +08:00

64 lines
1.7 KiB
GDScript

@tool
extends AnimationRoot
# 覆盖该方法
func _default_data() -> Dictionary:
return {}
func _ready() -> void:
super._ready()
if Engine.is_editor_hint():
return
func _on_ground_ready() -> void:
var counter = $"../DeployLayer/柜子"
# counter 默认在 s10 中 x 为 364.0
if ArchiveManager.get_global_value("c02_counter_pushed_out"):
counter.queue_free()
else:
var default_counter_x = 364.0
var counter_x = ArchiveManager.get_global_value("c02_counter_x", default_counter_x)
var diff = counter_x - default_counter_x
counter.position.x += diff
# rope_range
rope = $"../BGSprite2D/麻绳"
rope_length = rope.texture.get_size().x
var half_length = rope_length / 2.0
rope_range.x = rope.global_position.x - half_length
rope_range.y = rope.global_position.x + half_length
await get_tree().create_timer(0.1).timeout
var player= %MainPlayer
# 玩家位置更新时,更新麻绳隆起
player.position_updated.connect(_on_player_position_updated)
# 首次更新
_on_player_position_updated.call_deferred(player.global_position)
var rope: MeshInstance2D
var rope_range := Vector2(0, 0)
var rope_length := 0.0
var bgm_switched := false
func _on_player_position_updated(global_pos: Vector2) -> void:
# 切换 bgm
if global_pos.x < 2300 and not bgm_switched:
print("切换 bgm")
bgm_switched = true
$"背景音效_通道".easing_kill()
$"背景音效_红色".play()
var x = global_pos.x
if x < rope_range.x or x > rope_range.y:
return
var ratio = (x - rope_range.x) / rope_length
# 限制 bulge 最大范围
ratio = clampf(ratio, 0.0, 0.8)
rope.set_bulge(ratio)
func mouse_animation() -> void:
$"../DeployLayer/老鼠衔大洋".play()