xiandie/scene/ground/scene/c01/s06_孤儿院长廊围墙.gd

389 lines
13 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@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_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:
# $"../DeployLayer/猫鼠游戏胜利ambush/Fog".visible = true
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/游戏中途桌椅"
obstacles.get_node("遮盖").visible = false
interactable_obstacles = $"../DeployLayer/Interactable桌椅"
interactable_obstacles.interacted.connect(_on_push_obstacles)
cat_rat_game_fail_ambush = $"../DeployLayer/【胖小孩背着残疾小孩】/【单残疾小孩】/猫鼠游戏失败ambush"
standing_kid1.get_node("Npc对话1").interacted.connect(_on_talked.bind(1))
standing_kid2.get_node("Npc对话2").interacted.connect(_on_talked.bind(2))
game_kid.get_node("Npc对话3").interacted.connect(_on_talked.bind(3))
# 等待游戏开始后启用
cat_rat_game_fail_ambush.enabled = false
cat_rat_game_start_ambush = $"../DeployLayer/猫鼠游戏开始ambush"
# 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)
# 解除镜头 x 右侧限制
SceneManager.get_camera_marker().limit_right = 10000
# 玩家不能超过开始跑的位置
var player = SceneManager.get_player() as MainPlayer
if player.position.x > 1800:
player.update_x_with_camera_followed(1800)
func _dean_flip_book() -> void:
if dean.animation == "院长呼吸":
# 翻书后会自动播放呼吸动画
dean.play("院长翻书")
# 在游戏开始前,更早的对话
func pre_game_intro():
SceneManager.lock_player()
var camera = SceneManager.get_camera_marker() as CameraFocusMarker
camera.tween_zoom(1.5, 3.5)
var p = $"../DeployLayer/四小孩画鬼差的对话ambush/FocusPoint"
camera.focus_node(p, 3.0)
await Util.wait(2.0)
DialogueManager.show_dialogue_balloon(dialogue_c01, "c01_s06_四个小孩画鬼差的对话")
await DialogueManager.dialogue_ended
# 重置镜头
SceneManager.focus_player_and_reset_zoom(2.5)
await Util.wait(2.5)
await SceneManager.pop_os_with_str("c01_s06_熟悉的墙画")
SceneManager.unlock_player()
func game_intro() -> void:
standing_kid1.get_node("Npc对话1").enabled = false
standing_kid2.get_node("Npc对话2").enabled = false
game_kid.get_node("Npc对话3").enabled = false
# 禁用猫鼠游戏开始 ambush 检测
cat_rat_game_start_ambush.enabled = false
var camera = SceneManager.get_camera_marker() as CameraFocusMarker
camera.tween_zoom(1.5, 3.0)
camera.focus_node(focus_point, 3.0)
standing_kid1.play("【站立小孩-1】挠痒呼吸")
standing_kid2.play("【站立小孩-2】转身")
# 只有 1、2 是跟班3 不参与
# standing_kid3.play("【站立小孩-3】转身")
game_kid.play("【胖小孩背着残疾小孩】侧面呼吸")
SceneManager.get_player().set_facing_direction(Vector2.LEFT)
SceneManager.freeze_player(0)
# DialogueManager.show_dialogue_balloon(
# dialogue_c01, "c01_s06_谈论鬼差与猫鼠游戏", [GlobalConfig.DIALOG_IGNORE_INPUT]
# )
DialogueManager.show_dialogue_balloon(dialogue_c01, "c01_s06_谈论鬼差与猫鼠游戏")
DialogueManager.dialogue_ended.connect(_game_counting_down, CONNECT_ONE_SHOT)
func _game_counting_down(_res = null):
$"Sfx猫鼠游戏".play()
DialogueManager.show_dialogue_balloon(dialogue_c01, "c01_s06_猫鼠游戏BGM开始")
await DialogueManager.dialogue_ended
# 重置镜头
SceneManager.focus_player_and_reset_zoom(2.5)
SceneManager.release_player()
DialogueManager.show_dialogue_balloon(dialogue_c01, "c01_s06_猫鼠游戏倒计时")
# 禁止玩家向左移动,同时可以使右侧腾出空间,玩家可以继续向右移动
var player = SceneManager.get_player() as MainPlayer
var left = player.global_position.x
player.player_movement_rect.position.x = left
Util.timer(1.0, _kids_start_run)
cat.visible = true
cat.play("【墙上黑猫】跑步")
cat.get_node("猫咪嘶吼音效").play()
# 玩家与三个小孩的互动计数
func _on_talked(id: int):
#talk count
if (
standing_kid1.get_node("Npc对话1").icount > 0
and standing_kid2.get_node("Npc对话2").icount > 0
and game_kid.get_node("Npc对话3").icount > 0
):
if (
(id == 1 and standing_kid1.get_node("Npc对话1").icount == 1)
or (id == 2 and standing_kid2.get_node("Npc对话2").icount == 1)
or (id == 3 and game_kid.get_node("Npc对话3").icount == 1)
):
# 三个小孩都对话完毕
await DialogueManager.dialogue_ended
SceneManager.lock_player()
await Util.wait(1)
await SceneManager.pop_os_with_str("c01_s06_四小孩对话结束")
SceneManager.unlock_player()
var kid_run_tween
func _kids_start_run():
standing_kid1.get_node("猫鼠游戏重置ambush").enabled = true
standing_kid2.get_node("猫鼠游戏重置ambush").enabled = true
if kid_run_tween:
kid_run_tween.kill()
kid_run_tween = create_tween()
# 奔跑
kid_run_tween.tween_callback(standing_kid1.play.bind("【站立小孩-1】侧面跑步"))
kid_run_tween.tween_interval(0.3)
kid_run_tween.tween_callback(standing_kid2.play.bind("【站立小孩-2】侧面跑步"))
kid_run_tween.tween_interval(0.7)
kid_run_tween.tween_callback(game_kid.play.bind("【胖小孩背着残疾小孩】奔跑"))
# 提示玩家按 shift 键奔跑
SceneManager.pop_center_notification("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
interactable_obstacles.enabled = false
obstacles.play("桌椅颤抖-翻倒")
$"桌椅撞倒音效".play()
_on_mid_ambush_success()
var player = SceneManager.get_player() as MainPlayer
# 禁止玩家越过桌椅
player.player_movement_rect.position.x = 2850
obstacles.play("桌椅颤抖-翻倒")
$"桌椅撞倒音效".play()
SceneManager.pop_debug_dialog_info("音效", "桌椅翻倒")
var current_round_failed = false
# 小孩1首先跑到桌椅旁
func obstacles_ambush1_triggered():
if obstacles_success:
standing_kid1.play("【站立小孩-1】侧面呼吸")
else:
current_round_failed = true
# 小孩2跑到桌椅旁
func obstacles_ambush2_triggered():
if obstacles_success:
standing_kid2.play("【站立小孩-2】侧面呼吸")
# 胖小孩跑到桌椅旁
func obstacles_ambush3_triggered():
if obstacles_success:
game_kid.play("【胖小孩背着残疾小孩】摔倒")
# 只有第一个小孩没跑过去的时候,残疾小孩发动
if not current_round_failed:
game_kid.sprite_frames.set_animation_loop("【胖小孩背着残疾小孩】摔倒", false)
game_kid.animation_finished.connect(_on_kid_fall_finished, CONNECT_ONE_SHOT)
# 残疾小孩冲刺
func _on_kid_fall_finished():
obstacles.get_node("遮盖").visible = true
game_kid_limp.modulate.a = 1
game_kid.play("【胖小孩背着残疾小孩】胖子独自呼吸")
game_kid_limp.play("【单残疾小孩】爬行")
cat_shadow.play("【墙上小孩猫影子】变身")
# 启用失败 ambush 检测
cat_rat_game_fail_ambush.enabled = true
# cat_shadow 渐隐
var tween = create_tween()
tween.tween_interval(10.0)
tween.tween_property(cat_shadow, "modulate:a", 0.0, 4.0)
func _on_mid_ambush_success():
obstacles_success = true
# TODO 获得成就
# 重新开始
func game_restart():
if kid_run_tween:
kid_run_tween.kill()
current_round_failed = false
interactable_obstacles.enabled = true
obstacles_pushed = false
standing_kid1.play("【站立小孩-1】侧面呼吸")
standing_kid2.play("【站立小孩-2】侧面呼吸")
game_kid.play("【胖小孩背着残疾小孩】侧面呼吸")
SceneManager.freeze_player(0)
SceneManager.pop_debug_dialog_info("音效", "玩家被抓住,猫鼠游戏重新开始")
await Util.wait(1.5)
# 过场黑屏
SceneManager.toggle_ground_mask(true)
await Util.wait(0.5)
# 重置桌椅
obstacles_pushed = false
obstacles_success = false
obstacles.get_node("遮盖").visible = false
obstacles.play("桌椅正常")
var player = SceneManager.get_player()
player.player_movement_rect.position.x = 1750
player.global_position.x = 1800
var kids_start_run_initial_x = [1620, 1660, 1730]
standing_kid1.global_position.x = kids_start_run_initial_x[0]
standing_kid2.global_position.x = kids_start_run_initial_x[1]
game_kid.global_position.x = kids_start_run_initial_x[2]
SceneManager.toggle_ground_mask(false)
await Util.wait(1.0)
# 开始跑
SceneManager.release_player()
$"Sfx猫鼠游戏".set("parameters/switch_to_clip", "Intro")
DialogueManager.show_dialogue_balloon(dialogue_c01, "c01_s06_猫鼠游戏倒计时")
await Util.wait(1.5)
_kids_start_run()
# 成功
func game_succeed():
if not obstacles_success:
game_kid.play_with_loop("【胖小孩背着残疾小孩】侧面呼吸")
else:
game_kid_limp.pause()
cat_shadow.pause()
transport_player_to_next_scene(true)
# 失败
func game_failed():
if kid_run_tween:
kid_run_tween.kill()
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):
if win:
_show_next_scene(true)
SceneManager.pop_debug_dialog_info("音效", "猫鼠游戏胜利,无缝转场")
else:
Util.timer(0.7, _show_next_scene.bind(false))
SceneManager.pop_debug_dialog_info("音效", "猫鼠游戏失败,传送下一场景")
# var s07_ground := preload("res://scene/ground/scene/c01/s07_书店外.tscn")
# var s07_ground_node = s07_ground.instantiate()
# func _notification(what: int) -> void:
# if what == NOTIFICATION_PREDELETE:
# if s07_ground_node:
# s07_ground_node.queue_free()
func _show_next_scene(seamless: bool):
# var node = s07_ground_node
# # 防止在 NOTIFICATION_PREDELETE 时被释放,所以先置空
# s07_ground_node = null
# var ground_node = node.get_child(0) as Ground2D
# node.remove_child(ground_node)
# node.queue_free()
if seamless:
# 无缝转场过程
SceneManager.get_ground_loader().transition_to_scene("c01_s07", "1", 0.0)
else:
SceneManager.get_ground_loader().transition_to_scene("c01_s07", "1")