From 187100f500a0994a878c6be6841f50ad1138ebde 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: Fri, 29 Aug 2025 10:56:33 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E5=AD=90=E5=BC=B9=E7=B3=BB=E7=BB=9F):?= =?UTF-8?q?=20=E5=B0=86=E5=AD=90=E5=BC=B9=E5=89=8D=E8=BF=9B=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E6=8F=90=E5=8F=96=E5=88=B0PresetsAI=E7=B1=BB=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将多个子弹类型的forward调用统一到PresetsAI类中,提高代码复用性 删除LockLauncher.gd文件及部分场景文件中冗余的fields配置 --- components/Bullets/BigLaser.tscn | 4 ---- components/Bullets/Common/LaserSummoner.tscn | 5 ----- components/Bullets/FireScan.tscn | 5 ----- components/Bullets/Laser.tscn | 5 ----- components/Bullets/Star.tscn | 5 ----- scripts/Contents/Bullets/Common/LockLauncher.gd | 16 ---------------- scripts/Contents/Bullets/Diamond.gd | 2 +- scripts/Contents/Bullets/FireScan.gd | 2 +- scripts/Contents/Bullets/Presets/Presets.gd | 4 ++++ scripts/Contents/Bullets/PurpleCrystal.gd | 2 +- scripts/Contents/Bullets/Star.gd | 2 +- 11 files changed, 8 insertions(+), 44 deletions(-) delete mode 100644 scripts/Contents/Bullets/Common/LockLauncher.gd create mode 100644 scripts/Contents/Bullets/Presets/Presets.gd diff --git a/components/Bullets/BigLaser.tscn b/components/Bullets/BigLaser.tscn index 8e84d1c..72ac295 100644 --- a/components/Bullets/BigLaser.tscn +++ b/components/Bullets/BigLaser.tscn @@ -6,7 +6,3 @@ needEnergy = 100.0 knockback = 10.0 recoil = 4.0 - -[node name="rect" parent="texture" index="0"] -offset_top = 0.0 -offset_bottom = 2000.0 diff --git a/components/Bullets/Common/LaserSummoner.tscn b/components/Bullets/Common/LaserSummoner.tscn index 0ce20e8..1fd5ef7 100644 --- a/components/Bullets/Common/LaserSummoner.tscn +++ b/components/Bullets/Common/LaserSummoner.tscn @@ -207,11 +207,6 @@ height = 2000.0 [node name="LaserSummoner" instance=ExtResource("1_pnxoq")] script = ExtResource("2_nk2p8") -fields = { -0: 0, -1: 25, -2: 1 -} autoSpawnAnimation = true freeAfterSpawn = true diff --git a/components/Bullets/FireScan.tscn b/components/Bullets/FireScan.tscn index 45fd73c..4f0e5b6 100644 --- a/components/Bullets/FireScan.tscn +++ b/components/Bullets/FireScan.tscn @@ -8,11 +8,6 @@ a = Vector2(0, -10) [node name="FireScan" instance=ExtResource("1_cqre5")] script = ExtResource("2_qprdp") -fields = { -0: 20, -1: 40, -2: 0 -} lifeDistance = 200.0 [node name="hitbox" parent="." index="1"] diff --git a/components/Bullets/Laser.tscn b/components/Bullets/Laser.tscn index 9498625..9859bc7 100644 --- a/components/Bullets/Laser.tscn +++ b/components/Bullets/Laser.tscn @@ -17,11 +17,6 @@ height = 300.0 [node name="Laser" instance=ExtResource("1_3u4op")] script = ExtResource("2_yy5sr") -fields = { -0: 10, -1: 15, -2: 1 -} lifeTime = 2000.0 [node name="texture" parent="." index="0"] diff --git a/components/Bullets/Star.tscn b/components/Bullets/Star.tscn index d1fe70f..a90f6ea 100644 --- a/components/Bullets/Star.tscn +++ b/components/Bullets/Star.tscn @@ -62,11 +62,6 @@ radius = 19.2354 [node name="Star" instance=ExtResource("1_x6yf7")] script = ExtResource("2_y4b0l") -fields = { -0: 10, -1: 1, -2: 0 -} lifeTime = 1000.0 autoLoopAnimation = true diff --git a/scripts/Contents/Bullets/Common/LockLauncher.gd b/scripts/Contents/Bullets/Common/LockLauncher.gd deleted file mode 100644 index 2fbf780..0000000 --- a/scripts/Contents/Bullets/Common/LockLauncher.gd +++ /dev/null @@ -1,16 +0,0 @@ -extends BulletBase -class_name LockLauncher - -enum PositionType { - SELF, - TEXTURE, -} - -@export var target: PositionType = PositionType.SELF - -func ai(): - if target == PositionType.SELF: - position = launcher.position - else: - position = launcher.texture.global_position - rotation = launcher.rotation diff --git a/scripts/Contents/Bullets/Diamond.gd b/scripts/Contents/Bullets/Diamond.gd index f3886ad..80fa041 100644 --- a/scripts/Contents/Bullets/Diamond.gd +++ b/scripts/Contents/Bullets/Diamond.gd @@ -8,4 +8,4 @@ func register(): func ai(): rotation = lerp_angle(rotation, position.angle_to_point(launcher.currentFocusedBoss.position), 0.1 * clamp((traceTime - timeLived()) / traceTime, 0, INF)) canDamageSelf = !(timeLived() >= traceTime) - forward(Vector2.from_angle(rotation)) + PresetsAI.forward(self, rotation) diff --git a/scripts/Contents/Bullets/FireScan.gd b/scripts/Contents/Bullets/FireScan.gd index 6a1df4a..71f3151 100644 --- a/scripts/Contents/Bullets/FireScan.gd +++ b/scripts/Contents/Bullets/FireScan.gd @@ -6,4 +6,4 @@ func register(): damage = 20 func ai(): - forward(Vector2.from_angle(rotation)) + PresetsAI.forward(self, rotation) diff --git a/scripts/Contents/Bullets/Presets/Presets.gd b/scripts/Contents/Bullets/Presets/Presets.gd new file mode 100644 index 0000000..fca082f --- /dev/null +++ b/scripts/Contents/Bullets/Presets/Presets.gd @@ -0,0 +1,4 @@ +class_name PresetsAI + +static func forward(bullet: BulletBase, rotation: float): + bullet.forward(Vector2.from_angle(rotation)) diff --git a/scripts/Contents/Bullets/PurpleCrystal.gd b/scripts/Contents/Bullets/PurpleCrystal.gd index a38f4ea..a2894a3 100644 --- a/scripts/Contents/Bullets/PurpleCrystal.gd +++ b/scripts/Contents/Bullets/PurpleCrystal.gd @@ -2,4 +2,4 @@ extends BulletBase class_name PurpleCrystal func ai(): - forward(Vector2.from_angle(rotation)) + PresetsAI.forward(self, rotation) diff --git a/scripts/Contents/Bullets/Star.gd b/scripts/Contents/Bullets/Star.gd index 9bf8478..97c87a5 100644 --- a/scripts/Contents/Bullets/Star.gd +++ b/scripts/Contents/Bullets/Star.gd @@ -4,4 +4,4 @@ class_name Star func register(): damage = 1 func ai(): - forward(Vector2.from_angle(rotation)) + PresetsAI.forward(self, rotation)