diff --git a/DungeonShooting_Godot/excel/BulletBase.xlsx b/DungeonShooting_Godot/excel/BulletBase.xlsx index c98d2c4..3848b0d 100644 --- a/DungeonShooting_Godot/excel/BulletBase.xlsx +++ b/DungeonShooting_Godot/excel/BulletBase.xlsx Binary files differ diff --git a/DungeonShooting_Godot/prefab/effect/common/Trail0001.tscn b/DungeonShooting_Godot/prefab/effect/common/Trail0001.tscn index 2136abe..ca24925 100644 --- a/DungeonShooting_Godot/prefab/effect/common/Trail0001.tscn +++ b/DungeonShooting_Godot/prefab/effect/common/Trail0001.tscn @@ -3,11 +3,12 @@ [ext_resource type="Script" path="res://src/game/effects/Trail.cs" id="1_i68ib"] [sub_resource type="Curve" id="Curve_fnvhf"] -_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0] +_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0.5), 0.0, 0.0, 0, 0] point_count = 2 [sub_resource type="Gradient" id="Gradient_lp1h8"] -colors = PackedColorArray(0.964706, 0.494118, 0.478431, 1, 0, 0, 0, 1) +offsets = PackedFloat32Array(0.825949, 1) +colors = PackedColorArray(0.96, 0.496, 0.48, 0.705882, 0.960784, 0.494118, 0.478431, 0) [node name="Trail" type="Line2D"] width = 3.0 diff --git a/DungeonShooting_Godot/project.godot b/DungeonShooting_Godot/project.godot index 5331d14..2588b93 100644 --- a/DungeonShooting_Godot/project.godot +++ b/DungeonShooting_Godot/project.godot @@ -11,7 +11,7 @@ [application] config/name="DungeonShooting" -run/main_scene="res://scene/test/TestTrail.tscn" +run/main_scene="res://scene/Main.tscn" config/features=PackedStringArray("4.2", "C#") config/icon="res://icon.png" diff --git a/DungeonShooting_Godot/resource/config/BulletBase.json b/DungeonShooting_Godot/resource/config/BulletBase.json index 3ca89bd..6cebba7 100644 --- a/DungeonShooting_Godot/resource/config/BulletBase.json +++ b/DungeonShooting_Godot/resource/config/BulletBase.json @@ -216,10 +216,10 @@ "Type": 1, "Prefab": "bullet0006", "HarmRange": [ - 4 + 10 ], "RepelRange": [ - 20 + 45 ], "DeviationAngleRange": [ 0 diff --git a/DungeonShooting_Godot/scene/test/TestTrail.tscn b/DungeonShooting_Godot/scene/test/TestTrail.tscn index 79b7b09..221f2b9 100644 --- a/DungeonShooting_Godot/scene/test/TestTrail.tscn +++ b/DungeonShooting_Godot/scene/test/TestTrail.tscn @@ -7,7 +7,7 @@ [node name="TestTrail" type="Node2D"] script = ExtResource("1_mefd0") +[node name="Trail" parent="." instance=ExtResource("2_t308a")] + [node name="Sprite2D" type="Sprite2D" parent="."] texture = ExtResource("2_w7ffd") - -[node name="Trail" parent="Sprite2D" instance=ExtResource("2_t308a")] diff --git a/DungeonShooting_Godot/src/game/activity/bullet/normal/TrailBullet.cs b/DungeonShooting_Godot/src/game/activity/bullet/normal/TrailBullet.cs index a228062..108e05c 100644 --- a/DungeonShooting_Godot/src/game/activity/bullet/normal/TrailBullet.cs +++ b/DungeonShooting_Godot/src/game/activity/bullet/normal/TrailBullet.cs @@ -1,12 +1,27 @@  -using System.Collections.Generic; using Godot; [Tool] public partial class TrailBullet : Bullet { - protected override void Process(float delta) + private Trail trail; + + public override void InitData(BulletData data, uint attackLayer) { - base.Process(delta); + base.InitData(data, attackLayer); + + trail = ObjectManager.GetPoolItem(ResourcePath.prefab_effect_common_Trail0001_tscn); + trail.SetTarget(AnimatedSprite); + trail.AddToActivityRoot(RoomLayerEnum.YSortLayer); + trail.AddPoint(trail.Target.GlobalPosition, 0); + trail.ZIndex = 1; + } + + + public override void OnReclaim() + { + base.OnReclaim(); + trail.SetTarget(null); + trail = null; } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/effects/Trail.cs b/DungeonShooting_Godot/src/game/effects/Trail.cs index cc8ed3f..6137bcd 100644 --- a/DungeonShooting_Godot/src/game/effects/Trail.cs +++ b/DungeonShooting_Godot/src/game/effects/Trail.cs @@ -1,30 +1,102 @@ using Godot; -public partial class Trail : Line2D +public partial class Trail : Line2D, IPoolItem { - [Export] - public int length = 300; + public const int TrailUpdateFrame = 20; + + public int length { get; set; } = 30; + public Node2D Target { get; private set; } - private Node2D parent; - private Vector2 offset = Vector2.Zero; + public bool IsDestroyed { get; private set; } + + public bool IsRecycled { get; set; } + public string Logotype { get; set; } - public override void _Ready() + private double _time = 0; + private IPoolItem _targetPoolItem; + + public void SetTarget(Node2D target) { - offset = Position; - parent = GetParent(); - TopLevel = true; + Target = target; + if (target is IPoolItem poolItem) + { + _targetPoolItem = poolItem; + } + else + { + _targetPoolItem = null; + } + + if (target != null) + { + ClearPoints(); + } + + _time = TrailUpdateFrame; } public override void _Process(double delta) { - GlobalPosition = Vector2.Zero; - - var point = parent.GlobalPosition + offset; - AddPoint(point, 0); - - if (GetPointCount() > length) + if (_targetPoolItem != null && _targetPoolItem.IsRecycled) //目标物体被回收 { - RemovePoint(GetPointCount() - 1); + SetTarget(null); } + + _time += delta; + var v = 1f / TrailUpdateFrame; + if (_time >= v) //执行更新点 + { + _time %= v; + + var pointCount = GetPointCount(); + if (Target != null) //没有被回收 + { + AddPoint(Target.GlobalPosition, 0); + if (pointCount > length) + { + RemovePoint(pointCount - 1); + } + } + else //被回收了, + { + if (pointCount > 0) + { + RemovePoint(pointCount - 1); + } + + if (pointCount <= 1) //没有点了, 执行回收 + { + ObjectPool.Reclaim(this); + } + } + } + else if (Target != null) //没有被回收, 更新第一个点 + { + SetPointPosition(0, Target.GlobalPosition); + } + } + + public void Destroy() + { + if (IsDestroyed) + { + return; + } + + IsDestroyed = true; + QueueFree(); + } + public void OnReclaim() + { + GetParent().CallDeferred(Node.MethodName.RemoveChild, this); + Target = null; + _targetPoolItem = null; + } + + public void OnLeavePool() + { + ClearPoints(); + _time = 0; + ZIndex = 0; } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs index 6aecf16..a6b5cbd 100644 --- a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs +++ b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs @@ -33,6 +33,7 @@ public const string prefab_effect_bullet_BulletSmoke0001_tscn = "res://prefab/effect/bullet/BulletSmoke0001.tscn"; public const string prefab_effect_bullet_BulletSmoke0002_tscn = "res://prefab/effect/bullet/BulletSmoke0002.tscn"; public const string prefab_effect_common_Effect1_tscn = "res://prefab/effect/common/Effect1.tscn"; + public const string prefab_effect_common_Trail0001_tscn = "res://prefab/effect/common/Trail0001.tscn"; public const string prefab_effect_enemy_EnemyBlood0001_tscn = "res://prefab/effect/enemy/EnemyBlood0001.tscn"; public const string prefab_effect_enemy_EnemyDead0001_tscn = "res://prefab/effect/enemy/EnemyDead0001.tscn"; public const string prefab_effect_enemy_EnemyDead0002_tscn = "res://prefab/effect/enemy/EnemyDead0002.tscn"; @@ -483,4 +484,5 @@ public const string scene_test_TestRoomFog_tscn = "res://scene/test/TestRoomFog.tscn"; public const string scene_test_TestTerrain2x2_tscn = "res://scene/test/TestTerrain2x2.tscn"; public const string scene_test_TestTileLayer_tscn = "res://scene/test/TestTileLayer.tscn"; + public const string scene_test_TestTrail_tscn = "res://scene/test/TestTrail.tscn"; } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/test/TestTrail.cs b/DungeonShooting_Godot/src/test/TestTrail.cs index 4de8864..f722c97 100644 --- a/DungeonShooting_Godot/src/test/TestTrail.cs +++ b/DungeonShooting_Godot/src/test/TestTrail.cs @@ -4,10 +4,13 @@ public partial class TestTrail : Node2D { private Sprite2D sprite; + private Trail trail; public override void _Ready() { sprite = GetNode("Sprite2D"); + trail = GetNode("Trail"); + trail.SetTarget(sprite); } public override void _Process(double delta)