From 5614893442624b8d94bef5d9d918062e1fb651ea Mon Sep 17 00:00:00 2001 From: chendian <-> Date: Fri, 13 Sep 2024 03:07:54 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=81=E5=AE=9A=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- render/texture/decal/lock.png | Bin 1021 -> 0 bytes resource/ui/hud/lock.png | Bin 0 -> 1287 bytes .../decal => resource/ui/hud}/lock.png.import | 6 ++-- scene/ui/hud_screen.tscn | 3 +- script/character/character.gd | 4 +++ script/character/player/player_action.gd | 28 +++++++++++++----- script/character/player/player_input.gd | 4 +-- script/character/skill.gd | 6 ++-- script/character/status.gd | 1 + script/ui/hud/lock_item.gd | 5 ++++ 10 files changed, 42 insertions(+), 15 deletions(-) delete mode 100644 render/texture/decal/lock.png create mode 100644 resource/ui/hud/lock.png rename {render/texture/decal => resource/ui/hud}/lock.png.import (72%) diff --git a/render/texture/decal/lock.png b/render/texture/decal/lock.png deleted file mode 100644 index 7cb1fd38896c3805376015a5e5e137bad0f5ca47..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1021 zcmVPx&w@E}nRCt{2TiaFRFc7`74L}E^gSZ3S0dx>L2pv!YbP%=z*b0&klC1zbNVWmr z{qTs4g?#*o?AQ+X9FBu6$@91xy~e-~E*sLvOGwTEBmic5DX4)2ouQcUpe$3hKKS-D*_>BHkKeXvV^v4_K)qYb2$IiD+h`4vSJn$^h)R!lA%}H> z%G9kKBKEB8+MDs(2J*YG~N zbt8iL1Z*GG2s{o~`ytW33>v4L5gLy$eq&1$?FX;CgBrnMc}gSBlINdwH3ai%d3)xX zvHmm~oe{44W?8mwTG3i>a1p;QG=Mi}v02yz7c*l5^R)@HEc>WiVbO{<1BU6&)hw8j z_Z@1pzzrX@=`tc1#}-C}UtYNf01%P)z69$FMyH3;LS%bX`a2j0f30V1 z7f1m>M0S3~sle!#x_j0DGrdmM066M4b2t1T2;|$>Q^m%=@nry#ss2p-LK8v)6m&hp z+vptK>aPlBeG{JL^7}E?WQ<^yS8PLtLKwXf0?Lyl-Sbcov`D)ZuNS1XN_l5{2W^jrOQQW(8Pm58^J2CGDpi5v^6|R4P8P_)*hZ6%106;p3{H5w!h<*X{QD&XXx0?Xx)*=28Ey^H0^Nw zZ0@C`nMWKyn@dQh-Y0kmt@|P(|6<7=9qQq?fS23it&Ab3qVrE@neQni0A?g-03ad> r3`-OTk~@9=iR0(9f4Y|O2bYZh@oLcdyQ_jb00000NkvXXu0mjfXI|ZG diff --git a/resource/ui/hud/lock.png b/resource/ui/hud/lock.png new file mode 100644 index 0000000000000000000000000000000000000000..cab5482df77ca2caba27de48a7bb874d30aa7575 GIT binary patch literal 1287 zcmV+i1^D`jP)Px(!AV3xRCt{2o$YnoIt+$^E|6>xZxC-#ZIEt|Y>?gwGD5q7eJ4meLA-(836c%$ zyMW&NL!b@ORAjprMNoXs=}~IYG9ZHB7f2En3We#yF@6NVJrT``XeJ-c0o=9(VcrqZ zM*jOjL>p%Q6GOhCnVkLr?f^UkSmW3>xZ0N@e86Ej!dtql>ah-gPm zN%+?Bh+mTSmWV1ztDnDO<|Q-#dquIM0N@9mp+7VK6HB(g2Eb!o*YC<|w*VFZ9y-!5 z0+zn$Nc$k^w=SXl*5j~R4aYh9Ck=r6x~|_;#=J>}-JI~<#W~6YxB>7G_`UnRx9SM3qdxL0#rs{g0}xY4Ch457Eg4i-H!sjLyAd-rzY!ee1n{c#H#-5=1=?Zgub~9~GNx>dKxe*i)D`jy zKvqWJWqx>=A7RWJK_K%19C!Bu29Sjj_?hn;K&TO@sfHCV3f0&Gn7~`xmxc8^0xs}q zuxs*FfcFBjQQo0nLTLmB8i6^4fc1e-Lc{>PbiSNSP)7dZKHIke)G+BXwqOxi67>#u zPhlip~DBHysh}s86T7zjokmB!||!Vhn8_@Ftwv&3x$Fa{s#{PD}vrhbKw90002ovPDHLkV1n>oU{e49 literal 0 HcmV?d00001 diff --git a/render/texture/decal/lock.png.import b/resource/ui/hud/lock.png.import similarity index 72% rename from render/texture/decal/lock.png.import rename to resource/ui/hud/lock.png.import index d9b0274..6a9239a 100644 --- a/render/texture/decal/lock.png.import +++ b/resource/ui/hud/lock.png.import @@ -3,15 +3,15 @@ importer="texture" type="CompressedTexture2D" uid="uid://dx2vp753yvh4y" -path="res://.godot/imported/lock.png-32166d0b031590623c7496bf56c8f4a7.ctex" +path="res://.godot/imported/lock.png-e2a5c1eddc1a695c4c501a4c652e0820.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://render/texture/decal/lock.png" -dest_files=["res://.godot/imported/lock.png-32166d0b031590623c7496bf56c8f4a7.ctex"] +source_file="res://resource/ui/hud/lock.png" +dest_files=["res://.godot/imported/lock.png-e2a5c1eddc1a695c4c501a4c652e0820.ctex"] [params] diff --git a/scene/ui/hud_screen.tscn b/scene/ui/hud_screen.tscn index 3fac5ee..233953b 100644 --- a/scene/ui/hud_screen.tscn +++ b/scene/ui/hud_screen.tscn @@ -11,7 +11,7 @@ [ext_resource type="Texture2D" uid="uid://0f3lam5c3k0y" path="res://resource/ui/hud/player_status_hp.png" id="5_b0cyb"] [ext_resource type="Script" path="res://script/ui/hud/lock_item.gd" id="5_usy8x"] [ext_resource type="Texture2D" uid="uid://g4b4cjfdaxsx" path="res://resource/ui/hud/player_status_mp_sub_empty.png" id="6_fqaaa"] -[ext_resource type="Texture2D" uid="uid://dx2vp753yvh4y" path="res://render/texture/decal/lock.png" id="6_hmslt"] +[ext_resource type="Texture2D" uid="uid://dx2vp753yvh4y" path="res://resource/ui/hud/lock.png" id="6_hmslt"] [ext_resource type="Script" path="res://script/ui/hud/weapon_item.gd" id="7_3g1k3"] [ext_resource type="Texture2D" uid="uid://bvuv86ujfaqfx" path="res://resource/ui/hud/player_status_mp_sub.png" id="7_wiq06"] [ext_resource type="Texture2D" uid="uid://bp7cve5pxkvv0" path="res://resource/ui/hud/boss_status_hp_empty.png" id="9_3sg6t"] @@ -218,6 +218,7 @@ script = ExtResource("5_usy8x") [node name="Lock" type="Sprite2D" parent="HudPage/LockItem"] texture = ExtResource("6_hmslt") +hframes = 2 [node name="AnimationPlayer" type="AnimationPlayer" parent="HudPage/LockItem"] libraries = { diff --git a/script/character/character.gd b/script/character/character.gd index a28b053..ea0e4da 100644 --- a/script/character/character.gd +++ b/script/character/character.gd @@ -193,6 +193,10 @@ func set_target(target: int): set_status("target", target) +func set_is_lock(value: bool): + set_status("is_lock", value) + + func cast_particle(resource: Resource, is_attach: bool, offset: Vector3 = Vector3.ZERO, scale: Vector3 = Vector3.ONE): effect.cast_particle(resource, is_attach, offset, scale) diff --git a/script/character/player/player_action.gd b/script/character/player/player_action.gd index da16797..e5e1103 100644 --- a/script/character/player/player_action.gd +++ b/script/character/player/player_action.gd @@ -6,20 +6,33 @@ class_name PlayerAction @onready var status: Status = (%Status as Status) @onready var combo: Combo = (%Combo as Combo) -var is_lock_pressed: bool var lock_cd_dict: Dictionary = {} +var is_lock: bool func _process(delta) -> void: - var has_target: bool = status.target != 0 + #更新主动锁定目标cd for key in lock_cd_dict: if lock_cd_dict[key] > 0: lock_cd_dict[key] -= delta else: lock_cd_dict.erase(key) - if is_lock_pressed == has_target: + #没有锁定目标 尝试被动锁定 + if not status.target and not is_lock: + var enemy_list: Array[Character] = Global.character_mgr.get_enemy_list(character.id()) + var pos_player: Vector2 = character.pos2D() + enemy_list.filter( func(a: Character): return a.pos2D().distance_squared_to(pos_player)<3) + enemy_list.sort_custom( + func(a: Character, b: Character): + return a.pos2D().distance_squared_to(pos_player) < b.pos2D().distance_squared_to(pos_player) + ) + if enemy_list: + character.set_target(enemy_list[0].id()) + character.set_is_lock(is_lock) + #锁定状态有变化 尝试主动锁定 + if status.is_lock == is_lock: return - if is_lock_pressed: + if is_lock: var enemy_list: Array[Character] = Global.character_mgr.get_enemy_list(character.id()) var pos_player: Vector2 = character.pos2D() enemy_list.sort_custom( @@ -33,8 +46,9 @@ func _process(delta) -> void: if enemy_list: character.set_target(enemy_list[0].id()) else: - lock_cd_dict[character.target()] = 1 #1秒内无法再次锁定 - character.set_target(0) + if status.target: + lock_cd_dict[status.target] = 0.5 #0.5秒内无法再次主动锁定 + character.set_is_lock(is_lock) func check_action(key: String, is_pressed: bool) -> bool: @@ -60,7 +74,7 @@ func check_action_pressed(key: String) -> bool: func lock(is_pressed: bool): - is_lock_pressed = is_pressed + is_lock = is_pressed func switch(is_pressed: bool): diff --git a/script/character/player/player_input.gd b/script/character/player/player_input.gd index 969dbe0..f7290d0 100644 --- a/script/character/player/player_input.gd +++ b/script/character/player/player_input.gd @@ -57,7 +57,7 @@ func get_switch_action(action_name: String)->String: return action_name if not status.is_switch: return action_name - if status.target: + if status.is_lock: return "lock_%s" % action_name else: return "free_%s" % action_name @@ -68,7 +68,7 @@ func get_skill_action(action_name: String)->String: return action_name var index: int = skill_action_list.find(action_name) action_name = switch_action_list[index] - if status.target: + if status.is_lock: return "lock_%s" % action_name else: return "free_%s"% action_name diff --git a/script/character/skill.gd b/script/character/skill.gd index be48326..5077b4e 100644 --- a/script/character/skill.gd +++ b/script/character/skill.gd @@ -46,9 +46,11 @@ func cast_skill_by_name(name: String, cast_dir: Vector2): func cast_skill(cfg: SkillCfg, cast_dir: Vector2, action_key: String = "") -> bool: - if cast_dir.length() == 0: + var is_no_dir: bool = cast_dir.length() == 0 + if is_no_dir: cast_dir = Vector2.RIGHT if status.is_right else Vector2.LEFT - if !cfg.free_lock and status.target: + var is_cast_to_target: bool = status.target and (status.is_lock or is_no_dir) + if !cfg.free_lock and is_cast_to_target: var target: Character = Global.character_mgr.get_character(status.target) if target: cast_dir = character.pos2D().direction_to(target.pos2D()).normalized() diff --git a/script/character/status.gd b/script/character/status.gd index 08c94e7..d20d22a 100644 --- a/script/character/status.gd +++ b/script/character/status.gd @@ -22,6 +22,7 @@ class_name Status @export var mp_sub_max: float #次级mp最大值 @export var is_dead: bool #是否死亡 @export var target: int #目标角色 +@export var is_lock: bool #是否主动锁定 @export var throw_target: int #投技目标 @export var break_level_def: int #硬直抗性等级 @export_category("表现状态") diff --git a/script/ui/hud/lock_item.gd b/script/ui/hud/lock_item.gd index dacc2fe..e49bc29 100644 --- a/script/ui/hud/lock_item.gd +++ b/script/ui/hud/lock_item.gd @@ -1,6 +1,7 @@ extends Control @onready var animation: AnimationPlayer = $AnimationPlayer as AnimationPlayer +@onready var lock: Sprite2D = $Lock as Sprite2D @onready var camera: CameraManager = Global.camera_mgr var target: Character @@ -19,3 +20,7 @@ func _process(delta): func on_target_changed(target_id: int): target = Global.character_mgr.get_character(target_id) visible = target != null + + +func on_is_lock_changed(is_lock: bool): + lock.frame = 0 if is_lock else 1