diff --git a/DungeonShooting_Godot/src/common/NodeExtend.cs b/DungeonShooting_Godot/src/common/NodeExtend.cs new file mode 100644 index 0000000..a341103 --- /dev/null +++ b/DungeonShooting_Godot/src/common/NodeExtend.cs @@ -0,0 +1,41 @@ +using Godot; +using System; + +public static class NodeExtend +{ + + public static ThrowNode StartThrow(this Node2D node, Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate) + { + return StartThrow(node, size, start, startHeight, direction, xSpeed, ySpeed, rotate); + } + + public static T StartThrow(this Node2D node, Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate) where T : ThrowNode + { + StartThrow(node, size, start, startHeight, direction, xSpeed, ySpeed, rotate, null); + T inst = Activator.CreateInstance(); + inst.StartThrow(size, start, startHeight, direction, xSpeed, ySpeed, rotate, node); + return inst; + } + + public static ThrowNode StartThrow(this Node2D node, Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Sprite shadowTarget) + { + return StartThrow(node, size, start, startHeight, direction, xSpeed, ySpeed, rotate, shadowTarget); + } + + public static T StartThrow(this Node2D node, Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Sprite shadowTarget) where T : ThrowNode + { + T inst = Activator.CreateInstance(); + inst.StartThrow(size, start, startHeight, direction, xSpeed, ySpeed, rotate, node, shadowTarget); + return inst; + } + + public static bool StopThrow(this Node2D node) + { + ThrowNode parent = node.GetParentOrNull(); + if (parent != null) { + parent.StopThrow(); + return true; + } + return false; + } +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/effect/ThrowNode.cs b/DungeonShooting_Godot/src/effect/ThrowNode.cs index 3dcec01..65aa23b 100644 --- a/DungeonShooting_Godot/src/effect/ThrowNode.cs +++ b/DungeonShooting_Godot/src/effect/ThrowNode.cs @@ -89,7 +89,7 @@ /// 旋转速度 /// 需要挂载的节点 /// 抛射的节点显示的纹理, 用于渲染阴影用 - public void InitThrow(Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Node2D mount) + public void StartThrow(Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Node2D mount) { if (CollisionShape != null) { @@ -130,9 +130,9 @@ /// 旋转速度 /// 需要挂载的节点 /// 抛射的节点显示的纹理, 用于渲染阴影用 - public void InitThrow(Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Node2D mount, Sprite shadowTarget) + public void StartThrow(Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Node2D mount, Sprite shadowTarget) { - InitThrow(size, start, startHeight, direction, xSpeed, ySpeed, rotate, mount); + StartThrow(size, start, startHeight, direction, xSpeed, ySpeed, rotate, mount); ShadowTarget = shadowTarget; if (shadowTarget != null) { @@ -162,6 +162,9 @@ } } + /// + /// 停止投抛运动 + /// public Node2D StopThrow() { var mount = Mount; diff --git a/DungeonShooting_Godot/src/role/Role.cs b/DungeonShooting_Godot/src/role/Role.cs index bfd21c2..b6eabb7 100644 --- a/DungeonShooting_Godot/src/role/Role.cs +++ b/DungeonShooting_Godot/src/role/Role.cs @@ -156,14 +156,13 @@ gun.RotationDegrees = 180; } gun.Position = Vector2.Zero; - var temp = new ThrowGun(); var startPos = GlobalPosition + new Vector2(0, 0); var startHeight = 6; var direction = GlobalRotationDegrees + MathUtils.RandRangeInt(-20, 20); var xf = 30; var yf = MathUtils.RandRangeInt(60, 120); var rotate = MathUtils.RandRangeInt(-180, 180); - temp.InitThrow(new Vector2(20, 20), startPos, startHeight, direction, xf, yf, rotate, gun, gun.GunSprite); + gun.StartThrow(new Vector2(20, 20), startPos, startHeight, direction, xf, yf, rotate, gun.GunSprite); } } diff --git a/DungeonShooting_Godot/src/weapon/gun/Gun.cs b/DungeonShooting_Godot/src/weapon/gun/Gun.cs index 4267799..b8583a2 100644 --- a/DungeonShooting_Godot/src/weapon/gun/Gun.cs +++ b/DungeonShooting_Godot/src/weapon/gun/Gun.cs @@ -468,10 +468,8 @@ public void Tnteractive(Role master) { - var parent = GetParentOrNull(); - if (parent != null) + if (this.StopThrow()) { - parent.StopThrow(); master.Holster.PickupGun(this); } } diff --git a/DungeonShooting_Godot/src/weapon/gun/OrdinaryGun.cs b/DungeonShooting_Godot/src/weapon/gun/OrdinaryGun.cs index f3dc8ea..18bc183 100644 --- a/DungeonShooting_Godot/src/weapon/gun/OrdinaryGun.cs +++ b/DungeonShooting_Godot/src/weapon/gun/OrdinaryGun.cs @@ -15,7 +15,6 @@ protected override void OnFire() { //创建一个弹壳 - var temp = new ThrowShell(); var startPos = GlobalPosition + new Vector2(0, 5); var startHeight = 6; var direction = GlobalRotationDegrees + MathUtils.RandRangeInt(-30, 30) + 180; @@ -23,7 +22,7 @@ var yf = MathUtils.RandRangeInt(60, 120); var rotate = MathUtils.RandRangeInt(-720, 720); var sprite = Attribute.ShellPack.Instance(); - temp.InitThrow(new Vector2(5, 10), startPos, startHeight, direction, xf, yf, rotate, sprite, sprite); + sprite.StartThrow(new Vector2(5, 10), startPos, startHeight, direction, xf, yf, rotate, sprite); //创建抖动 MainCamera.Main.ProssesDirectionalShake(Vector2.Right.Rotated(GlobalRotation) * 1.5f); } diff --git a/DungeonShooting_Godot/src/weapon/gun/ThrowGun.cs b/DungeonShooting_Godot/src/weapon/gun/ThrowGun.cs index e33895d..56e7651 100644 --- a/DungeonShooting_Godot/src/weapon/gun/ThrowGun.cs +++ b/DungeonShooting_Godot/src/weapon/gun/ThrowGun.cs @@ -23,7 +23,7 @@ //如果落地高度不够低, 再抛一次 if (StartYSpeed > 1) { - InitThrow(Size, GlobalPosition, 0, Direction, XSpeed * 0.8f, StartYSpeed * 0.5f, RotateSpeed * 0.5f, null); + StartThrow(Size, GlobalPosition, 0, Direction, XSpeed * 0.8f, StartYSpeed * 0.5f, RotateSpeed * 0.5f, null); } else //结束 { diff --git a/DungeonShooting_Godot/src/weapon/shell/ThrowShell.cs b/DungeonShooting_Godot/src/weapon/shell/ThrowShell.cs index 4cbb3ce..914ee5d 100644 --- a/DungeonShooting_Godot/src/weapon/shell/ThrowShell.cs +++ b/DungeonShooting_Godot/src/weapon/shell/ThrowShell.cs @@ -17,7 +17,7 @@ //如果落地高度不够低, 再抛一次 if (StartYSpeed > 1) { - InitThrow(Size, GlobalPosition, 0, Direction, XSpeed * 0.8f, StartYSpeed * 0.5f, RotateSpeed * 0.5f, null); + StartThrow(Size, GlobalPosition, 0, Direction, XSpeed * 0.8f, StartYSpeed * 0.5f, RotateSpeed * 0.5f, null); } else {