diff --git a/DungeonShooting_Godot/prefab/bullet/normal/Bullet0006.tscn b/DungeonShooting_Godot/prefab/bullet/normal/Bullet0006.tscn index c29f36a..e4e7314 100644 --- a/DungeonShooting_Godot/prefab/bullet/normal/Bullet0006.tscn +++ b/DungeonShooting_Godot/prefab/bullet/normal/Bullet0006.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=3 uid="uid://c1fx7c1jwil26"] +[gd_scene load_steps=8 format=3 uid="uid://c1fx7c1jwil26"] [ext_resource type="Script" path="res://src/game/activity/bullet/normal/TrailBullet.cs" id="1_b8pov"] [ext_resource type="Shader" path="res://resource/material/Blend.gdshader" id="2_iolc6"] @@ -28,19 +28,15 @@ shader_parameter/outline_use_blend = false shader_parameter/grey = 0.0 -[sub_resource type="Gradient" id="Gradient_lp1h8"] -colors = PackedColorArray(0.964706, 0.494118, 0.478431, 1, 0.960784, 0.494118, 0.478431, 0) - [sub_resource type="CircleShape2D" id="CircleShape2D_4mw2b"] radius = 4.0 [sub_resource type="CircleShape2D" id="CircleShape2D_vqdkp"] radius = 4.0 -[node name="Bullet0006" type="CharacterBody2D" node_paths=PackedStringArray("Trail", "CollisionArea", "CollisionShape2D", "Particles2D", "ShadowSprite", "AnimatedSprite", "Collision")] +[node name="Bullet0006" type="CharacterBody2D" node_paths=PackedStringArray("CollisionArea", "CollisionShape2D", "Particles2D", "ShadowSprite", "AnimatedSprite", "Collision")] collision_layer = 2 script = ExtResource("1_b8pov") -Trail = NodePath("AnimatedSprite/Trail") CollisionArea = NodePath("AnimatedSprite/CollisionArea") CollisionShape2D = NodePath("AnimatedSprite/CollisionArea/CollisionShape2D") Particles2D = [] @@ -57,12 +53,6 @@ material = SubResource("ShaderMaterial_qhkgc") sprite_frames = ExtResource("3_v2y7a") -[node name="Trail" type="Line2D" parent="AnimatedSprite"] -width = 2.0 -gradient = SubResource("Gradient_lp1h8") -joint_mode = 1 -end_cap_mode = 2 - [node name="CollisionArea" type="Area2D" parent="AnimatedSprite"] collision_layer = 0 collision_mask = 0 diff --git a/DungeonShooting_Godot/prefab/effect/common/Trail0001.tscn b/DungeonShooting_Godot/prefab/effect/common/Trail0001.tscn new file mode 100644 index 0000000..2136abe --- /dev/null +++ b/DungeonShooting_Godot/prefab/effect/common/Trail0001.tscn @@ -0,0 +1,16 @@ +[gd_scene load_steps=4 format=3 uid="uid://ddwikcidm0gsi"] + +[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] +point_count = 2 + +[sub_resource type="Gradient" id="Gradient_lp1h8"] +colors = PackedColorArray(0.964706, 0.494118, 0.478431, 1, 0, 0, 0, 1) + +[node name="Trail" type="Line2D"] +width = 3.0 +width_curve = SubResource("Curve_fnvhf") +gradient = SubResource("Gradient_lp1h8") +script = ExtResource("1_i68ib") diff --git a/DungeonShooting_Godot/project.godot b/DungeonShooting_Godot/project.godot index 2588b93..5331d14 100644 --- a/DungeonShooting_Godot/project.godot +++ b/DungeonShooting_Godot/project.godot @@ -11,7 +11,7 @@ [application] config/name="DungeonShooting" -run/main_scene="res://scene/Main.tscn" +run/main_scene="res://scene/test/TestTrail.tscn" config/features=PackedStringArray("4.2", "C#") config/icon="res://icon.png" diff --git a/DungeonShooting_Godot/scene/test/TestTrail.tscn b/DungeonShooting_Godot/scene/test/TestTrail.tscn new file mode 100644 index 0000000..79b7b09 --- /dev/null +++ b/DungeonShooting_Godot/scene/test/TestTrail.tscn @@ -0,0 +1,13 @@ +[gd_scene load_steps=4 format=3 uid="uid://brum5fmbt1br4"] + +[ext_resource type="Script" path="res://src/test/TestTrail.cs" id="1_mefd0"] +[ext_resource type="PackedScene" uid="uid://ddwikcidm0gsi" path="res://prefab/effect/common/Trail0001.tscn" id="2_t308a"] +[ext_resource type="Texture2D" uid="uid://bn8k07n2y6lmr" path="res://resource/sprite/bullet/normal/bullet0006.png" id="2_w7ffd"] + +[node name="TestTrail" type="Node2D"] +script = ExtResource("1_mefd0") + +[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/GameApplication.cs b/DungeonShooting_Godot/src/game/GameApplication.cs index 32add5e..bef0085 100644 --- a/DungeonShooting_Godot/src/game/GameApplication.cs +++ b/DungeonShooting_Godot/src/game/GameApplication.cs @@ -88,7 +88,8 @@ public GameApplication() { Instance = this; - TargetFps = (int)DisplayServer.ScreenGetRefreshRate(); + //TargetFps = 20; + TargetFps = Mathf.RoundToInt(DisplayServer.ScreenGetRefreshRate()); Utils.InitRandom(); diff --git a/DungeonShooting_Godot/src/game/activity/bullet/normal/TrailBullet.cs b/DungeonShooting_Godot/src/game/activity/bullet/normal/TrailBullet.cs index a617deb..a228062 100644 --- a/DungeonShooting_Godot/src/game/activity/bullet/normal/TrailBullet.cs +++ b/DungeonShooting_Godot/src/game/activity/bullet/normal/TrailBullet.cs @@ -5,40 +5,8 @@ [Tool] public partial class TrailBullet : Bullet { - [Export, ExportFillNode] - public Line2D Trail { get; set; } - - private int _pointCount = 30; - private readonly List points = new List(); - protected override void Process(float delta) { base.Process(delta); - - if (points.Count < _pointCount) - { - points.Add(AnimatedSprite.GlobalPosition); - } - else - { - points.RemoveAt(0); - points.Add(AnimatedSprite.GlobalPosition); - } - - var tempPos = new Vector2[points.Count]; - tempPos[points.Count - 1] = Vector2.Zero; - for (var i = points.Count - 2; i >= 0; i--) - { - tempPos[i] = AnimatedSprite.ToLocal(points[i]); - } - //更新line2d点坐标 - Trail.Points = tempPos; - } - - public override void OnLeavePool() - { - base.OnLeavePool(); - points.Clear(); - Trail.Points = new Vector2[0]; } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/effects/Trail.cs b/DungeonShooting_Godot/src/game/effects/Trail.cs new file mode 100644 index 0000000..cc8ed3f --- /dev/null +++ b/DungeonShooting_Godot/src/game/effects/Trail.cs @@ -0,0 +1,30 @@ +using Godot; + +public partial class Trail : Line2D +{ + [Export] + public int length = 300; + + private Node2D parent; + private Vector2 offset = Vector2.Zero; + + public override void _Ready() + { + offset = Position; + parent = GetParent(); + TopLevel = true; + } + + public override void _Process(double delta) + { + GlobalPosition = Vector2.Zero; + + var point = parent.GlobalPosition + offset; + AddPoint(point, 0); + + if (GetPointCount() > length) + { + RemovePoint(GetPointCount() - 1); + } + } +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/test/TestTrail.cs b/DungeonShooting_Godot/src/test/TestTrail.cs new file mode 100644 index 0000000..4de8864 --- /dev/null +++ b/DungeonShooting_Godot/src/test/TestTrail.cs @@ -0,0 +1,17 @@ +using Godot; +using System; + +public partial class TestTrail : Node2D +{ + private Sprite2D sprite; + + public override void _Ready() + { + sprite = GetNode("Sprite2D"); + } + + public override void _Process(double delta) + { + sprite.Position = GetLocalMousePosition(); + } +}