添加关卡管理器插件

This commit is contained in:
RedisTKey 2025-12-30 10:15:32 +08:00
parent b306abb739
commit 80bf92faf6
14 changed files with 255 additions and 91 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,17 +0,0 @@
[gd_scene load_steps=3 format=3 uid="uid://ctqkbmyjo65bk"]
[ext_resource type="Script" uid="uid://dn0ksjoswquf5" path="res://addons/reedscene/scene/SceneManager.gd" id="1_0sb54"]
[ext_resource type="Script" uid="uid://bwvbeodhvhrmw" path="res://addons/reedfx/vfx/VFXLayer.gd" id="2_ghnqe"]
[node name="GameMain" type="Node" node_paths=PackedStringArray("TransitionNode")]
script = ExtResource("1_0sb54")
TransitionNode = NodePath("Transition")
metadata/_custom_type_script = "uid://dn0ksjoswquf5"
[node name="Transition" type="Control" parent="."]
layout_mode = 3
anchors_preset = 0
[node name="ReedVFXLayer" type="CanvasLayer" parent="."]
script = ExtResource("2_ghnqe")
metadata/_custom_type_script = "uid://bwvbeodhvhrmw"

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=38 format=3 uid="uid://gwhff4qaouxy"]
[ext_resource type="Script" uid="uid://dq1g1qp66chwy" path="res://_player/agens.gd" id="1_rkqpu"]
[ext_resource type="Script" uid="uid://dq1g1qp66chwy" path="res://_player/avatar.gd" id="1_rkqpu"]
[ext_resource type="Script" uid="uid://isu8onknb75o" path="res://_player/states/character_state_machine.gd" id="1_wvs5h"]
[ext_resource type="Script" uid="uid://15n8yfyr4eqj" path="res://_player/states/grounded.gd" id="2_5p50s"]
[ext_resource type="Texture2D" uid="uid://doxhsab56pe50" path="res://_asset/all.png" id="2_8nsdm"]
@ -47,7 +47,7 @@ script = ExtResource("21_5r2pj")
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ogl63"]
size = Vector2(10, 25)
[node name="Agens" type="CharacterBody2D" groups=["PLAYER"]]
[node name="Avatar" type="CharacterBody2D" groups=["PLAYER"]]
collision_layer = 2
collision_mask = 0
platform_wall_layers = 4

View File

@ -51,94 +51,123 @@ func _draw() -> void:
func _process(delta: float) -> void:
queue_redraw()
func _physics_process(delta: float) -> void:
##用於更新輸入的朝向
m_input_intent_direction = Input.get_vector(
"move_left",
"move_right",
"move_up",
"move_down"
)
spawn_hook_comp.set_ray_direction(m_input_intent_direction)
func _unhandled_input(event: InputEvent) -> void:
if event.is_echo():
return
#jump input
if event.is_action_pressed(&"jump"):
m_jump_press = true
_handle_jump_press()
if event.is_action_released(&"jump"):
m_jump_press = false
_handle_jump_release()
#dash input
if event.is_action_pressed(&"dash"):
m_dash_press = true
_handle_dash_press()
if event.is_action_released(&"dash"):
m_dash_press = false
#climb input
if event.is_action_pressed(&"climb"):
m_climb_press = true
_handle_climb_press()
if event.is_action_released(&"climb"):
m_climb_press = false
_handle_climb_release()
#grap hook input
if event.is_action_pressed(&"grap_hook"):
m_grap_hook_press = true
_handle_grap_hook_press()
if event.is_action_released(&"grap_hook"):
m_grap_hook_press = false
_handle_grap_hook_release()
func set_move_input(dir: Vector2) -> void:
m_input_intent_direction = dir
func get_move_input() -> Vector2:
return m_input_intent_direction
#func _physics_process(delta: float) -> void:
#
###用於更新輸入的朝向
#m_input_intent_direction = Input.get_vector(
#"move_left",
#"move_right",
#"move_up",
#"move_down"
#)
#
#spawn_hook_comp.set_ray_direction(m_input_intent_direction)
#func _unhandled_input(event: InputEvent) -> void:
#if event.is_echo():
#return
#
##jump input
#if event.is_action_pressed(&"jump"):
#m_jump_press = true
#_handle_jump_press()
#
#if event.is_action_released(&"jump"):
#m_jump_press = false
#_handle_jump_release()
#
##dash input
#if event.is_action_pressed(&"dash"):
#m_dash_press = true
#_handle_dash_press()
#
#if event.is_action_released(&"dash"):
#m_dash_press = false
#
##climb input
#if event.is_action_pressed(&"climb"):
#m_climb_press = true
#_handle_climb_press()
#
#if event.is_action_released(&"climb"):
#m_climb_press = false
#_handle_climb_release()
#
##grap hook input
#if event.is_action_pressed(&"grap_hook"):
#m_grap_hook_press = true
#_handle_grap_hook_press()
#
#if event.is_action_released(&"grap_hook"):
#m_grap_hook_press = false
#_handle_grap_hook_release()
#region 输入处理
'''对于单次的输入触发动作,我们发送一个格式为
want_to_...hsm
'''
##处理 jump 单次输入
func _handle_jump_press() -> void:
if not m_jump_press:
return
func press_jump() -> void:
hsm.dispatch(&"trigger_jump")
func _handle_jump_release() -> void:
func release_jump() -> void:
hsm.dispatch(&"completed_jump")
##处理 Dash 单次输入
func _handle_dash_press() -> void:
if not m_dash_press:
return
func press_dash() -> void:
hsm.dispatch(&"trigger_dash")
##处理 climb 输入
func _handle_climb_press() -> void:
if not m_climb_press:
return
func press_climb() -> void:
hsm.dispatch(&"trigger_climb")
func _handle_climb_release() -> void:
func release_climb() -> void:
hsm.dispatch(&"completed_climb")
##处理 Grap Hook 输入
func _handle_grap_hook_press() -> void:
func press_grap_hook() -> void:
hsm.dispatch(&"trigger_grap_hook")
func _handle_grap_hook_release() -> void:
func release_grap_hook() -> void:
hsm.dispatch(&"completed_grap_hook")
#endregion
##处理 jump 单次输入
#func _handle_jump_press() -> void:
#if not m_jump_press:
#return
#
#hsm.dispatch(&"trigger_jump")
#
#func _handle_jump_release() -> void:
#hsm.dispatch(&"completed_jump")
#
###处理 Dash 单次输入
#func _handle_dash_press() -> void:
#if not m_dash_press:
#return
#hsm.dispatch(&"trigger_dash")
#
###处理 climb 输入
#func _handle_climb_press() -> void:
#if not m_climb_press:
#return
#hsm.dispatch(&"trigger_climb")
#
#func _handle_climb_release() -> void:
#hsm.dispatch(&"completed_climb")
#
###处理 Grap Hook 输入
#func _handle_grap_hook_press() -> void:
#hsm.dispatch(&"trigger_grap_hook")
#
#func _handle_grap_hook_release() -> void:
#hsm.dispatch(&"completed_grap_hook")
##玩家方向改变时更新
func _handle_direction_changed(value: Direction):
match value:

View File

@ -0,0 +1,68 @@
class_name PlayerController extends Node2D
@export var auto_controlled_avatar: Player
##当前控制的Avatar
var _controlled_avatar: Player
## 当前输入状态
var move_input: Vector2 = Vector2.ZERO
func _ready() -> void:
if auto_controlled_avatar:
bind_avatar(auto_controlled_avatar)
##绑定avatar
func bind_avatar(p_avatar: Player) -> void:
_controlled_avatar = p_avatar
##解绑avatar
func unbind_avatar() -> void:
if not _controlled_avatar: return
_controlled_avatar = null
##解绑avatar
func get_avatar() -> Player:
return _controlled_avatar
##删除Avatar
func free_avatar() ->void:
if _controlled_avatar:
_controlled_avatar.queue_free()
func _physics_process(delta: float) -> void:
if _controlled_avatar == null:
return
move_input = Input.get_vector(
"move_left",
"move_right",
"move_up",
"move_down"
)
_controlled_avatar.set_move_input(move_input)
##获取输入并通知avatar
func _unhandled_input(event: InputEvent) -> void:
if _controlled_avatar == null or event.is_echo():
return
if event.is_action_pressed(&"jump"):
_controlled_avatar.press_jump()
elif event.is_action_released(&"jump"):
_controlled_avatar.release_jump()
if event.is_action_pressed(&"dash"):
_controlled_avatar.press_dash()
if event.is_action_pressed(&"climb"):
_controlled_avatar.press_climb()
elif event.is_action_released(&"climb"):
_controlled_avatar.release_climb()
if event.is_action_pressed(&"grap_hook"):
_controlled_avatar.press_grap_hook()
elif event.is_action_released(&"grap_hook"):
_controlled_avatar.release_grap_hook()

View File

@ -0,0 +1 @@
uid://b46vvltshe40l

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://cvqehvdjpoar4"]
[ext_resource type="Script" uid="uid://b46vvltshe40l" path="res://_player/player_controller.gd" id="1_0acw7"]
[node name="PlayerController" type="Node2D" groups=["PLAYER"]]
script = ExtResource("1_0acw7")

View File

@ -4,5 +4,5 @@ func _enter() -> void:
return
func _update(delta: float) -> void:
if Input.get_axis(&"move_left",&"move_right") != 0.0:
if agent.get_move_input().x != 0.0:
get_root().dispatch(self.EVENT_FINISHED)

View File

@ -32,7 +32,7 @@ func _update(delta: float) -> void:
_reset_run_dust_counter()
func _handle_move_input() -> void:
var move_direction = Input.get_axis(&"move_left",&"move_right") as float
var move_direction = agent.get_move_input().x as float
if move_direction == 0.0:
get_root().dispatch(self.EVENT_FINISHED)
agent.locomotion_comp.add_movement_input(0.0) #用0唤起制动加速度

View File

@ -0,0 +1,28 @@
@tool
@icon("uid://p0oxphym6oqg")
'''
level的最小单元prop和act
leveln个小关卡n = scene的数量
Scene
1.Act Manager
2.Prop
ActManager下ActProp的不同stateAct切换时Prop对应的状态也会切换
ActManager的主要作用就是管理这些Act的切换
Prop可以简单的理解为场景中的非地形碰撞的AI
Prop会自带一个PropComponentProp自身的state和state的切换
State1 -> State2state1是关闭状态state2是打开状态
1. State1中定义State2中定义
2. State1 -> State2的流转函数State1->State2的具体行为
Scene的PropPropComponentScene会默认的给他发一个PropComponent
Prop上直接挂载PropComponentScene来添加更为合适
SceneScene通过PropComponent上的IDID获取到PropComponent所挂载的组件
PropComponent必须是处于Prop的最上层子节点集
'''
class_name ReedScene extends Node2D

View File

@ -0,0 +1 @@
uid://5e157vdk6175

View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1767022123209" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5024" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M118.783 885.98c0 35.689 28.991 64.681 64.681 64.681h656.605c35.689 0 64.681-28.991 64.681-64.681V619.927H118.783V885.98zM302.129 411.921l540.639-183.446c33.89-10.397 53.184-46.286 43.087-80.276l-13.896-46.586c-8.098-27.292-33.59-46.286-61.982-46.286-6.198 0-12.396 0.9-18.495 2.699l-0.4 0.1L139.177 279.36c-33.89 10.397-53.184 46.286-43.087 80.276l13.796 46.686c3.799 12.896 11.497 23.893 21.594 31.891-7.998 10.797-12.696 24.093-12.696 38.389v87.326h179.145l85.554-152.007h-81.354z" p-id="5025" fill="#8da5f3"></path><path d="M840.069 411.921h-388.37l-88.736 152.007H596.56l85.399-151.731h68.216l-88.576 151.731h243.15v-87.226c0.001-35.69-28.991-64.781-64.68-64.781z" p-id="5026" fill="#8da5f3"></path></svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -0,0 +1,43 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://p0oxphym6oqg"
path="res://.godot/imported/scene.svg-8a320ae079b96f7816a22c69b2f9dc97.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/reedscene/scene/scene.svg"
dest_files=["res://.godot/imported/scene.svg-8a320ae079b96f7816a22c69b2f9dc97.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false