From 7b89d10aca22a012798d7e6d6add64d0d1980ac5 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: Sun, 14 Sep 2025 08:23:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(ShaderStage):=20=E5=B0=86=E5=9F=BA?= =?UTF-8?q?=E7=B1=BB=E4=BB=8ECanvasItem=E6=94=B9=E4=B8=BANode2D=E5=B9=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=B1=BB=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat(LightGun): 添加长度属性和粒子发射控制 refactor(TickTool): 修改millseconds参数类型并添加动画关键帧修改功能 feat(Bear): 添加新攻击类型6并优化攻击5的子弹生成逻辑 --- components/Bullets/BossAttack/Bear/LightGun.tscn | 2 ++ .../Contents/Bullets/BossAttack/Bear/LightGun.gd | 12 ++++++++++-- scripts/Contents/Characters/Bear.gd | 14 +++++++++++--- scripts/Statemachine/ShaderStage.gd | 3 ++- scripts/Tools/TickTool.gd | 14 +++++++++++++- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/components/Bullets/BossAttack/Bear/LightGun.tscn b/components/Bullets/BossAttack/Bear/LightGun.tscn index addde7b..0263ea1 100644 --- a/components/Bullets/BossAttack/Bear/LightGun.tscn +++ b/components/Bullets/BossAttack/Bear/LightGun.tscn @@ -154,6 +154,7 @@ height = 118.0 [node name="LightGun" instance=ExtResource("1_kwotu")] script = ExtResource("2_jid6s") allColor = SubResource("GradientTexture1D_aqmnp") +length = 1000.0 displayName = "空灵长枪" autoSpawnAnimation = true freeAfterSpawn = true @@ -178,6 +179,7 @@ texture = ExtResource("5_bepne") unique_name_in_owner = true z_index = -1 position = Vector2(-55, 0) +emitting = false amount = 50 process_material = SubResource("ParticleProcessMaterial_ppc2o") diff --git a/scripts/Contents/Bullets/BossAttack/Bear/LightGun.gd b/scripts/Contents/Bullets/BossAttack/Bear/LightGun.gd index cc547c9..d694ef6 100644 --- a/scripts/Contents/Bullets/BossAttack/Bear/LightGun.gd +++ b/scripts/Contents/Bullets/BossAttack/Bear/LightGun.gd @@ -1,8 +1,9 @@ extends BulletBase @export var allColor: GradientTexture1D = null +@export var length: float = 1000 -@onready var track: Node2D = $"%track" +@onready var track: ShaderStage = $"%track" @onready var sword: Sprite2D = $"%sword" @onready var points: GPUParticles2D = $"%points" @@ -16,7 +17,14 @@ func spawn(): track.material = track.material.duplicate() points.process_material = points.process_material.duplicate() setColor(myColor) + track.size.x = length + TickTool.modifyAnimationKey(animator, "spawn", "sword:position:x", Animation.TrackType.TYPE_BEZIER, 2.5, length / -2) + TickTool.modifyAnimationKey(animator, "spawn", "sword:position:x", Animation.TrackType.TYPE_BEZIER, 3, length / 2) + TickTool.modifyAnimationKey(animator, "spawn", "%hitbox:position:x", Animation.TrackType.TYPE_BEZIER, 2.5, length / -2) + TickTool.modifyAnimationKey(animator, "spawn", "%hitbox:position:x", Animation.TrackType.TYPE_BEZIER, 3, length / 2) + await TickTool.millseconds(2500) + points.emitting = true func setColor(color: Color): track.material.set_shader_parameter("color", color) sword.modulate = color - points.process_material.color = color + points.process_material.color = color \ No newline at end of file diff --git a/scripts/Contents/Characters/Bear.gd b/scripts/Contents/Characters/Bear.gd index 9ee8a33..f80b084 100644 --- a/scripts/Contents/Characters/Bear.gd +++ b/scripts/Contents/Characters/Bear.gd @@ -12,6 +12,7 @@ func register(): attackCooldownMap[3] = 13000 attackCooldownMap[4] = 4500 attackCooldownMap[5] = 5500 + attackCooldownMap[6] = 10000 sprintMultiplier = 60 func spawn(): texture.play("walk") @@ -19,7 +20,6 @@ func ai(): PresetEntityAI.follow(self, currentFocusedBoss, 200) for i in len(attackCooldownMap.keys()): tryAttack(i) - # tryAttack(5) func attack(type): var weaponPos = findWeaponAnchor("normal") if type == 0: @@ -60,14 +60,22 @@ func attack(type): await TickTool.millseconds(830.0 / count) return false elif type == 5: + playSound("attack5") var target = currentFocusedBoss.position var count = randi_range(10, 15) for i in range(count): for bullet in BulletBase.generate(preload("res://components/Bullets/BossAttack/Bear/LightGun.tscn"), self, target, 0): - bullet.position += Vector2.from_angle(deg_to_rad(360.0 / count * i)) * 1000 - bullet.rotation = bullet.position.angle_to_point(target) + bullet.rotation = deg_to_rad(360.0 / count * i) await TickTool.millseconds(1670.0 / count) return false + elif type == 6: + playSound("attack6") + for i in 16: + for bullet in BulletBase.generate(preload("res://components/Bullets/BossAttack/Bear/LightGun.tscn"), self, currentFocusedBoss.position, 0): + bullet.position += MathTool.randv2_range(300) + bullet.look_at(currentFocusedBoss.position) + await TickTool.millseconds(100) + return false return true func sprint(): move(Vector2(sign((currentFocusedBoss.position - position).x * sprintMultiplier), 0), true) diff --git a/scripts/Statemachine/ShaderStage.gd b/scripts/Statemachine/ShaderStage.gd index 917b4ea..0459acf 100644 --- a/scripts/Statemachine/ShaderStage.gd +++ b/scripts/Statemachine/ShaderStage.gd @@ -1,5 +1,6 @@ @tool -extends CanvasItem +extends Node2D +class_name ShaderStage @export var size: Vector2 = Vector2.ONE * 100 @export var color: Color = Color.WHITE diff --git a/scripts/Tools/TickTool.gd b/scripts/Tools/TickTool.gd index 5da04ef..f19647b 100644 --- a/scripts/Tools/TickTool.gd +++ b/scripts/Tools/TickTool.gd @@ -1,6 +1,6 @@ class_name TickTool -static func millseconds(ms: int): +static func millseconds(ms: float): return await WorldManager.tree.create_timer(ms / 1000.0).timeout static func frame(count: int = 1): for i in range(count): @@ -8,3 +8,15 @@ static func frame(count: int = 1): static func until(predicate: Callable): while not predicate.call(): await frame() +static func modifyAnimationKey(animator: AnimationPlayer, name: String, track: NodePath, trackType: Animation.TrackType, time: float, value: Variant): + var animation = animator.get_animation(name) + var trackIdx = animation.find_track(track, trackType) + var keyIdx = animation.track_find_key(trackIdx, time) + var inHandle + var outHandle + if trackType == Animation.TrackType.TYPE_BEZIER: + inHandle = animation.bezier_track_get_key_in_handle(trackIdx, keyIdx) + outHandle = animation.bezier_track_get_key_out_handle(trackIdx, keyIdx) + animation.track_set_key_value(trackIdx, keyIdx, [value, inHandle.x, inHandle.y, outHandle.x, outHandle.y]) + else: + animation.track_set_key_value(trackIdx, keyIdx, [value])