xiandie/scene/ground/scene/c01/s06_animation.gd

249 lines
8.5 KiB
GDScript

@tool
extends AnimationRoot
# 覆盖该方法
func _default_data() -> Dictionary:
return {}
func _ready() -> void:
super._ready()
var dean
var red_girl
# var drawing_kids
var focus_point
var standing_kid1
var standing_kid2
var standing_kid3
var game_kid
var game_kid_limp
var obstacles: ProAnimatedSprite2D
var interactable_obstacles: Interactable2D
var cat_rat_game_start_ambush: Ambush2D
var cat_rat_game_mid_ambush: Ambush2D
# var cat_rat_game_success_ambush: Ambush2D
var cat_rat_game_fail_ambush: Ambush2D
var cat
var cat_shadow
# 推动了桌椅
var obstacles_pushed = false
# 桌椅生效,砸了下来
var obstacles_success = false
func _on_ground_ready() -> void:
dean = $"../ParallaxForeground/BGParallaxLayer/门口_院长"
red_girl = $"../ParallaxForeground/BGParallaxLayer/门口_红衣姑娘"
# drawing_kids = $"../DeployLayer/drawing_kids"
focus_point = $"../DeployLayer/【站立小孩-2】/FocusPoint"
standing_kid1 = $"../DeployLayer/【站立小孩-1】"
standing_kid2 = $"../DeployLayer/【站立小孩-2】"
standing_kid3 = $"../DeployLayer/【站立小孩-3】"
game_kid = $"../DeployLayer/【胖小孩背着残疾小孩】"
obstacles = $"../DeployLayer/游戏中途桌椅"
interactable_obstacles = $"../DeployLayer/Interactable桌椅"
interactable_obstacles.interacted.connect(_on_push_obstacles)
cat_rat_game_fail_ambush = $"../DeployLayer/【胖小孩背着残疾小孩】/【单残疾小孩】/猫鼠游戏失败ambush"
# 等待游戏开始后启用
cat_rat_game_fail_ambush.enabled = false
cat_rat_game_start_ambush = $"../DeployLayer/猫鼠游戏开始ambush"
cat_rat_game_mid_ambush = $"../DeployLayer/猫鼠游戏中途ambush"
cat_rat_game_mid_ambush.triggered.connect(_on_cat_rat_game_obstacles_triggered)
# cat_rat_game_success_ambush = $"../DeployLayer/猫鼠游戏胜利ambush" as Ambush2D
game_kid_limp = $"../DeployLayer/【胖小孩背着残疾小孩】/【单残疾小孩】"
cat_shadow = $"../DeployLayer/【胖小孩背着残疾小孩】/【单残疾小孩】/【墙上小孩猫影子】"
cat = $"../DeployLayer/【墙上黑猫】"
cat.visible = false
game_kid_limp.modulate.a = 0.0
# 院长翻书
var timer = Timer.new()
timer.set_wait_time(5.0)
timer.one_shot = false
timer.autostart = true
add_child(timer)
timer.timeout.connect(_dean_flip_book)
func _dean_flip_book() -> void:
if dean.animation == "院长呼吸":
# 翻书后会自动播放呼吸动画
dean.play("院长翻书")
func game_intro() -> void:
var camera = SceneManager.get_camera_marker() as CameraFocusMarker
camera.tween_zoom(1.5)
camera.focus_node(focus_point)
standing_kid1.play("【站立小孩-1】挠痒呼吸")
standing_kid2.play("【站立小孩-2】转身")
standing_kid3.play("【站立小孩-3】转身")
game_kid.play("【胖小孩背着残疾小孩】侧面呼吸")
SceneManager.get_player().set_facing_direction(Vector2.LEFT)
DialogueManager.dialogue_ended.connect(_game_counting_down, CONNECT_ONE_SHOT)
func _game_counting_down(_res = null):
# 重置镜头
SceneManager.focus_player_and_reset_zoom()
DialogueManager.show_dialogue_balloon(
dialogue_c01,
"c01_s06_猫鼠游戏",
[GlobalConfig.DIALOG_IGNORE_INPUT]
)
# 禁止玩家向左移动,同时可以使右侧腾出空间,玩家可以继续向右移动
var player = SceneManager.get_player() as MainPlayer
var left = player.global_position.x
player.player_movement_rect.position.x = left
get_tree().create_timer(2.5).timeout.connect(_kids_start_run)
cat.visible = true
cat.play("【墙上黑猫】跑步")
SceneManager.get_shading_layer().show_default_fog(2.0)
func _kids_start_run():
# 再次运动
standing_kid1.play("【站立小孩-1】挠痒呼吸")
standing_kid2.play("【站立小孩-2】走路")
standing_kid3.play("【站立小孩-3】走路")
# 小胖等待 2s 后开始奔跑
get_tree().create_timer(2).timeout.connect(game_kid.play.bind("【胖小孩背着残疾小孩】奔跑"))
# 猫鼠游戏开始,启用失败 ambush 检测
cat_rat_game_fail_ambush.enabled = true
# 提示玩家按 shift 键奔跑
SceneManager.pop_center_notification(tr("ui_press_shift"))
# 解锁奔跑
ArchiveManager.archive.player_running_locked = false
SceneManager.get_player().running_locked = false
# debug 提示
SceneManager.pop_debug_dialog_info("音效", "猫鼠游戏追逐 BGM")
# 中途推桌椅
func _on_push_obstacles():
obstacles_pushed = true
# 胖子到达桌椅旁边
func _on_cat_rat_game_obstacles_triggered():
var player_x = SceneManager.get_player().global_position.x
# 桌椅右边缘的 x 坐标,桌椅生效条件:玩家在其右侧 + 交互过
var obstacles_x = 2200
if player_x < obstacles_x or not obstacles_pushed:
if GlobalConfig.DEBUG:
print("桌椅未发挥作用! player_x=", player_x, " obstacles_pushed=", obstacles_pushed)
obstacles.play("桌椅颤抖-正常")
SceneManager.pop_debug_dialog_info("美术", "桌椅颤抖-正常")
else:
# 禁止玩家越过桌椅
var player = SceneManager.get_player() as MainPlayer
player.player_movement_rect.position.x = obstacles_x
SceneManager.pop_debug_dialog_info("美术", "桌椅颤抖-翻倒, 【胖小孩背着残疾小孩】摔倒,获得成就")
obstacles.play("桌椅颤抖-翻倒")
game_kid.play("【胖小孩背着残疾小孩】摔倒")
game_kid.sprite_frames.set_animation_loop("【胖小孩背着残疾小孩】摔倒", false)
game_kid.animation_finished.connect(_on_kid_fall_finished, CONNECT_ONE_SHOT)
_on_mid_ambush_success()
SceneManager.pop_debug_dialog_info("音效", "桌椅翻倒")
func _on_kid_fall_finished():
game_kid_limp.modulate.a = 1
game_kid.play("【胖小孩背着残疾小孩】胖子独自呼吸")
game_kid_limp.play("【单残疾小孩】爬行")
cat_shadow.play("【墙上小孩猫影子】变身")
func _on_mid_ambush_success():
obstacles_success = true
# TODO 获得成就
# 成功
func game_succeed():
if not obstacles_success:
game_kid.play_with_loop("【胖小孩背着残疾小孩】侧面呼吸")
else:
game_kid_limp.pause()
cat_shadow.pause()
SceneManager.freeze_player(0)
transport_player_to_next_scene(true)
# 失败
func game_failed():
SceneManager.freeze_player(0)
if not obstacles_success:
game_kid.play_with_loop("【胖小孩背着残疾小孩】侧面呼吸")
game_kid.play("【胖小孩背着残疾小孩】摔倒")
game_kid.sprite_frames.set_animation_loop("【胖小孩背着残疾小孩】摔倒", false)
game_kid.animation_finished.connect(_crawling_kid_catch, CONNECT_ONE_SHOT)
else:
_crawling_kid_catch()
print("猫鼠游戏失败")
SceneManager.pop_debug_dialog_info("音效", "猫鼠游戏失败,玩家被抓住")
# 【单残疾小孩】 与玩家 x 距离 29px 时,播放「【单残疾小孩】抓住」
var crawling_distance = 29
# 【单残疾小孩】爬到玩家身边 29px 处,预备抓住
func _crawling_kid_catch():
game_kid.play("【胖小孩背着残疾小孩】胖子独自呼吸")
var player = SceneManager.get_player()
# 确保玩家朝向正确
player.set_facing_direction(Vector2.RIGHT)
var tween = create_tween()
tween.tween_property(cat_shadow, "modulate:a", 0.0, 0.5)
game_kid_limp.modulate.a = 1
# 小孩爬到玩家脚边的速度
var v_x = 30.0
var target_x = player.global_position.x - crawling_distance
var distance_x = target_x - game_kid_limp.global_position.x
if distance_x < 0:
game_kid_limp.flip_h = true
distance_x = -distance_x
var duration = distance_x / v_x
game_kid_limp.play_with_velocity("【单残疾小孩】爬行", Vector2(v_x, 0))
tween = create_tween()
tween.tween_property(game_kid_limp, "global_position:x", target_x, duration)
tween.tween_callback(_post_catch)
# 【单残疾小孩】已经到指定位置,播放抓住动画
func _post_catch():
game_kid_limp.global_position.x = (
SceneManager.get_player().global_position.x - crawling_distance
)
game_kid_limp.flip_h = false
game_kid_limp.play("【单残疾小孩】抓住")
game_kid_limp.animation_finished.connect(
transport_player_to_next_scene.bind(false), CONNECT_ONE_SHOT
)
SceneManager.get_player().visible = false
func transport_player_to_next_scene(win: bool):
SceneManager.get_shading_layer().tween_fog(
ShadingLayer.FOG_FRAME_MAX,
ShadingLayer.FOG_COLOR_DARK_GRAY,
ShadingLayer.FOG_OFFSET_DEFAULT,
1.0,
true
)
get_tree().create_timer(0.7).timeout.connect(_show_next_scene)
if win:
SceneManager.pop_debug_dialog_info("音效", "猫鼠游戏胜利,传送下一场景")
else:
SceneManager.pop_debug_dialog_info("音效", "猫鼠游戏失败,传送下一场景")
func _show_next_scene():
SceneManager.get_ground_loader().transition_to_scene("c01_s07", "left", false)