From 936b2ba2002ffc34bcac6e1515c2edcaacdd3bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=A8=E8=90=BD=E5=9F=BA=E5=9B=B4=E8=99=BE?= <3161880837@qq.com> Date: Sat, 6 Sep 2025 14:11:14 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E8=BF=BD=E8=B8=AA=E7=B3=BB=E7=BB=9F):?= =?UTF-8?q?=20=E7=BB=9F=E4=B8=80=E4=BD=BF=E7=94=A8getTrackingAnchor?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E8=8E=B7=E5=8F=96=E8=BF=BD=E8=B8=AA=E7=9B=AE?= =?UTF-8?q?=E6=A0=87=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改多个子弹脚本和EntityBase,使用统一的getTrackingAnchor方法获取追踪目标位置 在BulletBase中增加目标有效性检查 调整Wave配置和Rooster武器顺序 --- components/Characters/Rooster.tscn | 7 +++---- scripts/Contents/Bullets/Diamond.gd | 2 +- scripts/Contents/Bullets/LGBTBullet.gd | 2 +- scripts/Contents/Bullets/VectorStar.gd | 2 +- scripts/Contents/Wave.gd | 6 +++--- scripts/Statemachine/BulletBase.gd | 22 ++++++++++++---------- scripts/Statemachine/EntityBase.gd | 3 +++ 7 files changed, 24 insertions(+), 20 deletions(-) diff --git a/components/Characters/Rooster.tscn b/components/Characters/Rooster.tscn index 833031e..6125f03 100644 --- a/components/Characters/Rooster.tscn +++ b/components/Characters/Rooster.tscn @@ -48,12 +48,11 @@ process_mode = 4 [node name="PurpleCrystal" parent="weaponStore" index="0" instance=ExtResource("3_ms5sq")] -[node name="LGBT" parent="weaponStore" index="1" instance=ExtResource("4_pb8qn")] +[node name="VectorStar" parent="weaponStore" index="1" instance=ExtResource("6_fvy5n")] -[node name="BigLaser" parent="weaponStore" index="2" instance=ExtResource("4_plqwu")] +[node name="LGBT" parent="weaponStore" index="2" instance=ExtResource("4_pb8qn")] -[node name="VectorStar" parent="weaponStore" index="3" instance=ExtResource("6_fvy5n")] -debugRebuild = false +[node name="BigLaser" parent="weaponStore" index="3" instance=ExtResource("4_plqwu")] [node name="sprint" parent="sounds" index="0"] stream = ExtResource("4_66s6c") diff --git a/scripts/Contents/Bullets/Diamond.gd b/scripts/Contents/Bullets/Diamond.gd index 9175a11..420feba 100644 --- a/scripts/Contents/Bullets/Diamond.gd +++ b/scripts/Contents/Bullets/Diamond.gd @@ -9,4 +9,4 @@ func ai(): canDamageSelf = !(timeLived() >= traceTime) PresetAIs.forward(self, rotation) if timeLived() < traceTime: - PresetAIs.trace(self, launcher.currentFocusedBoss.position, 0.05) + PresetAIs.trace(self, launcher.currentFocusedBoss.getTrackingAnchor(), 0.05) diff --git a/scripts/Contents/Bullets/LGBTBullet.gd b/scripts/Contents/Bullets/LGBTBullet.gd index 0ef809c..112fe43 100644 --- a/scripts/Contents/Bullets/LGBTBullet.gd +++ b/scripts/Contents/Bullets/LGBTBullet.gd @@ -11,7 +11,7 @@ func ai(): speed *= 1.05 speed = clamp(speed, 0, 20) if is_instance_valid(tracer) and timeLived() < maxTraceTime: - PresetAIs.trace(self, tracer.position, clamp(speed / 50 * tracePower, 0, 1)) + PresetAIs.trace(self, tracer.getTrackingAnchor(), clamp(speed / 50 * tracePower, 0, 1)) PresetAIs.forward(self, rotation) func destroy(_b): EffectController.create(preload("res://components/Effects/LGBTBoom.tscn"), position).shot() diff --git a/scripts/Contents/Bullets/VectorStar.gd b/scripts/Contents/Bullets/VectorStar.gd index 68d1c49..5320a51 100644 --- a/scripts/Contents/Bullets/VectorStar.gd +++ b/scripts/Contents/Bullets/VectorStar.gd @@ -15,4 +15,4 @@ func ai(): else: forwarded = true if is_instance_valid(tracer): - rotation = position.angle_to_point(tracer.position) + rotation = position.angle_to_point(tracer.getTrackingAnchor()) diff --git a/scripts/Contents/Wave.gd b/scripts/Contents/Wave.gd index 78e55c6..ed7882f 100644 --- a/scripts/Contents/Wave.gd +++ b/scripts/Contents/Wave.gd @@ -11,9 +11,9 @@ var per: int = 0 static var current: int = 0 static var data: Array[Wave] = [ # entity, minCount, maxCount, isBoss, from, to, per - create(preload("res://components/Characters/Hen.tscn"), 1, 5, false, 0, INF, 1), - create(preload("res://components/Characters/Chick.tscn"), 0, 0, true, 8, INF, 6), - # create(preload("res://components/Characters/Chick.tscn"), 1, 1, true, 0, INF, 1), + # create(preload("res://components/Characters/Hen.tscn"), 1, 5, false, 0, INF, 1), + # create(preload("res://components/Characters/Chick.tscn"), 0, 0, true, 8, INF, 6), + create(preload("res://components/Characters/Chick.tscn"), 1, 1, true, 0, INF, 1), ] static func create( diff --git a/scripts/Statemachine/BulletBase.gd b/scripts/Statemachine/BulletBase.gd index 76a67a1..539417d 100644 --- a/scripts/Statemachine/BulletBase.gd +++ b/scripts/Statemachine/BulletBase.gd @@ -59,15 +59,16 @@ func _physics_process(_delta: float) -> void: if destroying: return if is_instance_valid(launcher) and (launcher.isPlayer() or is_instance_valid(launcher.currentFocusedBoss)): launcher.position -= Vector2.from_angle(rotation) * recoil - PresetAIs.trace( - self, - EntityTool.findClosetEntity(position, get_tree(), - !launcher.isPlayer(), - launcher.isPlayer(), - [launcher] - ).position, - launcher.fields.get(FieldStore.Entity.BULLET_TRACE) / 10 - ) + var targetEntity = EntityTool.findClosetEntity(position, get_tree(), + !launcher.isPlayer(), + launcher.isPlayer(), + [launcher] ) + if is_instance_valid(targetEntity): + PresetAIs.trace( + self, + targetEntity.getTrackingAnchor(), + launcher.fields.get(FieldStore.Entity.BULLET_TRACE) / 10 + ) ai() else: tryDestroy() @@ -113,7 +114,8 @@ func tryRefract(): var value = launcher.fields.get(FieldStore.Entity.BULLET_REFRACTION) var entity = EntityTool.findClosetEntity(position, get_tree(), !launcher.isPlayer(), launcher.isPlayer()) for i in range(MathTool.shrimpRate(value)): - refract(entity, i, value, value - floor(value)) + if is_instance_valid(entity): + refract(entity, i, value, value - floor(value)) # 抽象方法 func ai(): diff --git a/scripts/Statemachine/EntityBase.gd b/scripts/Statemachine/EntityBase.gd index f0c5217..b1d0813 100644 --- a/scripts/Statemachine/EntityBase.gd +++ b/scripts/Statemachine/EntityBase.gd @@ -277,6 +277,9 @@ func playSound(type: String): await cloned.finished cloned.queue_free() +func getTrackingAnchor() -> Vector2: + return hurtbox.global_position + # 关于分组 func isPlayer(): return is_in_group("players")