代码调整

This commit is contained in:
cakipaul 2025-01-31 18:44:30 +08:00
parent faeb0dfb98
commit a42fa8ae73
13 changed files with 92 additions and 31 deletions

View File

@ -35,6 +35,52 @@ ProAnimatedSprite2D增强 AnimatedSprite2D 的表现,在其基础上增加
- 正常游戏Main -> GroundLoader -> Ground
- 开发阶段:直接编辑 Ground
### Ground 说明
#### AnimationPlayer每个 Ground 都有一个 AnimationPlayer脚本继承自定义的 AnimationRoot
主要功能说明:
1. 正常的 AnimationPlayer 功能
2. oneshot_animation 场景首次加载时播放的 animation
主要方法与数据说明:
1. _default_data() : 本场景的默认存档数据
2. _on_ground_ready(): 在父节点 Ground 加载完成后回调
3. set_data(property: StringName, value: Variant):用于设置需要存档的数据
4. ground_archive存档数据
#### Entity 说明
位置res://scene/entity/
子目录说明:
1. ambient光照
2. general音效等
3. partical粒子效果
4. ux用户交互
主要类型说明:
1. ambush触发区域触发后执行回调
1. 可以配置是否一次性
2. 可配置触发方式enter, area_enter, interact
3. 可在场景加载时触发
4. 触发效果有播放对话期间锁定玩家播放动画回调方法AnimationPlayer 的方法注意“_”开头的方法会被忽略
2. inspectable可在检阅窗口进行审视的物品可以附加文案
3. local_inspectable运镜+检阅,无需检阅窗口
4. note显示文案
1. 显示方式os玩家头顶气泡ballon下方字幕可播放配音
5. npc
6. portal传送门
1. 名称有: left默认, right默认, 1, 2, 3, ...
2. 关键参数targer_scene 与 target_portaltarget_portal 为 none 时不启用)
3. 三种模式default通道opened打开的门locked锁定的门对应不同图标与操作音效
4. 锁定的门可以配置启用钥匙prop_key可在使用后自动消耗该钥匙
## 存档结构
- 存档命名为:"save"+三位数字

View File

@ -18,7 +18,7 @@ class_name ProAnimatedSprite2D extends AnimatedSprite2D
const ACTION_CONFIG = {
"animation_intro": "", "intro_loop": 1, "animation_wait_time": 0.0, "animation_next": ""
}
# 参数 {duration} 目前无需求,暂且保留
const MOVE_CONFIG = {"animation": "", "velocity": Vector2.ZERO, "duration": 10000000.0}

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=7 format=3 uid="uid://wyj4qdjyn4ql"]
[ext_resource type="Script" path="res://scene/entity/old/inspectable.gd" id="1_0pc4s"]
[ext_resource type="Script" path="res://scene/entity/inspectable.gd" id="1_0pc4s"]
[ext_resource type="PackedScene" uid="uid://c85t6stvytvjn" path="res://scene/entity/general/sfx.tscn" id="2_wrnix"]
[ext_resource type="AudioStream" uid="uid://dky3j8lwcy5sk" path="res://asset/audio/sfx/ui/物品查看.mp3" id="3_kilnm"]
[ext_resource type="Texture2D" uid="uid://bei1s1uucktso" path="res://asset/art/tool/neutral_point_light.webp" id="3_vbivp"]

View File

@ -140,7 +140,7 @@ func play_footstep_sound() -> void:
func move_player_to_portal(portal_name: String) -> void:
var portal_node = get_node_or_null("DeployLayer/portal_" + portal_name) as Node2D
if portal_node:
if portal_node and player:
player.global_position.x = portal_node.global_position.x
if portal_name == "left":
player.set_facing_direction(Vector2.RIGHT)

View File

@ -111,15 +111,16 @@ func _update_archive():
func _do_transition(scene_name: String):
# SceneManager.freeze_player(0)
ground = get_node_or_null("Ground") as Ground2D
if ground:
# 提前移除,防止命名冲突
remove_child(ground)
# 防止命名冲突
ground.name = "removed_ground"
call_deferred("remove_child", ground)
ground.queue_free()
var ground_node = _load_ground_node(scene_name)
# 先设置 ground再添加到场景中
# 因为 ground 在 enter_tree 时会用到 SceneManager 的方法
# 其中间接用到了 GroundLoader 的 ground
ground = ground_node
ground = _load_ground_node(scene_name)
_add_ground()
# 预先加载邻居场景
_post_transition()
@ -128,8 +129,8 @@ func _do_transition(scene_name: String):
func _add_ground():
ground.name = "Ground"
add_child(ground)
ground.name = "Ground"
if not Engine.is_editor_hint():
# move player to portal
ground.move_player_to_portal(entrance_portal)

View File

@ -6,7 +6,7 @@ var frame: Note2D
var paper: Interactable2D
var right_door: Portal2D
var piano: Interactable2D
var bed_reading: AnimatedSprite2D
# 覆盖该方法
func _default_data() -> Dictionary:
@ -31,6 +31,8 @@ func _on_ground_ready() -> void:
paper = $"../DeployLayer/oneshot纸片"
right_door = $"../DeployLayer/portal_right"
piano = $"../DeployLayer/钢琴"
bed_reading = $"../DeployLayer/小小蝶看书"
bed_reading.frame_changed.connect(_on_bed_reading_frame_changed)
# 画框是否已经正位
data.frame_relocated = ambush.played and ambush.one_shot
# 禁用鸡毛掸子
@ -66,6 +68,11 @@ func _on_ground_ready() -> void:
piano.interacted.connect(_on_piano_interacted)
func _on_bed_reading_frame_changed():
if bed_reading.animation == "c01_小小蝶_床上看书" and bed_reading.frame == 10:
# 播放结束0.5s 后释放角色
get_tree().create_timer(0.5).timeout.connect(SceneManager.release_player)
func _on_note_read():
frame.enabled = false

View File

@ -235,7 +235,7 @@ tracks/16/keys = {
[sub_resource type="Animation" id="Animation_7k2c8"]
resource_name = "intro"
length = 7.5
length = 7.0
capture_included = true
tracks/0/type = "value"
tracks/0/imported = false
@ -307,7 +307,7 @@ tracks/5/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [7.0, -1, false],
"args": [0.0, -1, false],
"method": &"freeze_player"
}]
}

View File

@ -92,9 +92,7 @@ func _game_counting_down(_res = null):
# 重置镜头
SceneManager.focus_player_and_reset_zoom()
DialogueManager.show_dialogue_balloon(
dialogue_c01,
"c01_s06_猫鼠游戏",
[GlobalConfig.DIALOG_IGNORE_INPUT]
dialogue_c01, "c01_s06_猫鼠游戏", [GlobalConfig.DIALOG_IGNORE_INPUT]
)
# 禁止玩家向左移动,同时可以使右侧腾出空间,玩家可以继续向右移动
var player = SceneManager.get_player() as MainPlayer
@ -230,19 +228,24 @@ func _post_catch():
func transport_player_to_next_scene(win: bool):
if win:
_show_next_scene(true)
SceneManager.pop_debug_dialog_info("音效", "猫鼠游戏胜利,无缝转场")
else:
SceneManager.get_shading_layer().tween_fog(
ShadingLayer.FOG_FRAME_MAX,
ShadingLayer.FOG_COLOR_DARK_GRAY,
ShadingLayer.FOG_COLOR_BLACK,
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:
get_tree().create_timer(0.7).timeout.connect(_show_next_scene.bind(false))
SceneManager.pop_debug_dialog_info("音效", "猫鼠游戏失败,传送下一场景")
func _show_next_scene():
func _show_next_scene(seamless: bool):
if seamless:
#TODO 无缝转场过程细化
SceneManager.get_ground_loader().transition_to_scene("c01_s07", "left", true)
else:
SceneManager.get_ground_loader().transition_to_scene("c01_s07", "left", false)

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=22 format=3 uid="uid://brck77w81fhvc"]
[gd_scene load_steps=24 format=3 uid="uid://brck77w81fhvc"]
[ext_resource type="PackedScene" uid="uid://dayyx4jerj7io" path="res://scene/ground/ground.tscn" id="1_wrr6r"]
[ext_resource type="Script" path="res://scene/ground/scene/c02/s02_animation.gd" id="2_5p8ev"]
@ -16,6 +16,8 @@
[ext_resource type="Texture2D" uid="uid://c4c7t2lttcf0a" path="res://asset/art/临时草稿/煤油灯.png" id="14_db4pu"]
[ext_resource type="Texture2D" uid="uid://doqtpiaf1weqc" path="res://asset/art/临时草稿/煤油灯_点燃.png" id="15_5rpxj"]
[ext_resource type="Texture2D" uid="uid://b7gyapghy3tsy" path="res://asset/art/neutral_point_light.png" id="16_asses"]
[ext_resource type="AudioStream" uid="uid://dvwiuesd0qi1l" path="res://asset/audio/sfx/ui/门牌互动音.wav" id="16_d08tt"]
[ext_resource type="AudioStream" uid="uid://dky3j8lwcy5sk" path="res://asset/audio/sfx/ui/物品查看.mp3" id="17_lqks2"]
[sub_resource type="Animation" id="Animation_abofy"]
resource_name = "oneshot_天冷"
@ -159,9 +161,11 @@ interacted_texture = ExtResource("15_5rpxj")
prop_key = "prop_火柴"
[node name="SfxInvalid" parent="Ground/DeployLayer/Interactable煤油灯" index="0"]
stream = ExtResource("16_d08tt")
file = "门牌互动音.wav"
[node name="SfxSuccess" parent="Ground/DeployLayer/Interactable煤油灯" index="1"]
stream = ExtResource("17_lqks2")
file = "物品查看.mp3"
[node name="CollisionShape2D" parent="Ground/DeployLayer/Interactable煤油灯/Area2D" index="0"]

View File

@ -5,7 +5,7 @@
[ext_resource type="Texture2D" uid="uid://cl8no405v4hsk" path="res://asset/art/scene/c02/s05_1012外间现实版/bg_1012外间.png" id="3_8jr2p"]
[ext_resource type="Texture2D" uid="uid://d04bppjl5h3vo" path="res://asset/art/scene/c02/s05_1012外间现实版/fg_1012外间.png" id="4_quka7"]
[ext_resource type="Texture2D" uid="uid://bykkjm7wker46" path="res://asset/art/scene/c02/s05_1012外间现实版/ux_公寓告示1.png" id="5_8vm4y"]
[ext_resource type="PackedScene" uid="uid://wyj4qdjyn4ql" path="res://scene/entity/old/inspectable.tscn" id="6_stoff"]
[ext_resource type="PackedScene" uid="uid://wyj4qdjyn4ql" path="res://scene/entity/inspectable.tscn" id="6_stoff"]
[node name="S05" type="Node2D"]

View File

@ -169,7 +169,7 @@ func _get_speed(direction: Vector2) -> Vector2:
func _physics_process(_delta: float) -> void:
if action_locked or action_freezed or Engine.is_editor_hint():
if action_locked or action_freezed or Engine.is_editor_hint() or not is_visible_in_tree():
velocity = Vector2.ZERO
return
var x_direction := Input.get_axis("left", "right")

View File

@ -85,9 +85,6 @@ animations = [{
"texture": ExtResource("12_k6v1x")
}, {
"duration": 1.0,
"texture": ExtResource("13_kjyug")
}, {
"duration": 1.0,
"texture": ExtResource("14_yy2gj")
}, {
"duration": 1.0,
@ -97,6 +94,9 @@ animations = [{
"texture": ExtResource("16_86yqr")
}, {
"duration": 1.0,
"texture": ExtResource("13_kjyug")
}, {
"duration": 1.0,
"texture": ExtResource("17_5psqe")
}, {
"duration": 1.0,