diff --git a/DungeonShooting_Godot/src/common/NodeExtend.cs b/DungeonShooting_Godot/src/common/NodeExtend.cs index 2a2479a..7ad30d8 100644 --- a/DungeonShooting_Godot/src/common/NodeExtend.cs +++ b/DungeonShooting_Godot/src/common/NodeExtend.cs @@ -11,10 +11,7 @@ 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; + return StartThrow(node, size, start, startHeight, direction, xSpeed, ySpeed, rotate, null); } public static ThrowNode StartThrow(this Node2D node, Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Sprite shadowTarget) @@ -24,7 +21,21 @@ 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(); + ThrowNode throwNode = node.GetParentOrNull(); + T inst; + if (throwNode == null) + { + inst = Activator.CreateInstance(); + } + else if (throwNode is T) + { + inst = throwNode as T; + } + else + { + throwNode.StopThrow(); + inst = Activator.CreateInstance(); + } inst.StartThrow(size, start, startHeight, direction, xSpeed, ySpeed, rotate, node, shadowTarget); return inst; } diff --git a/DungeonShooting_Godot/src/effect/ThrowNode.cs b/DungeonShooting_Godot/src/effect/ThrowNode.cs index 4615833..3260128 100644 --- a/DungeonShooting_Godot/src/effect/ThrowNode.cs +++ b/DungeonShooting_Godot/src/effect/ThrowNode.cs @@ -92,7 +92,7 @@ /// 旋转速度 /// 需要挂载的节点 /// 抛射的节点显示的纹理, 用于渲染阴影用 - public void StartThrow(Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Node2D mount) + public virtual void StartThrow(Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Node2D mount) { if (CollisionShape != null) { @@ -112,10 +112,19 @@ if (mount != null) { Mount = mount; - AddChild(mount); + var parent = mount.GetParent(); + if (parent == null) + { + AddChild(mount); + } + else if (parent != this) + { + parent.RemoveChild(mount); + AddChild(mount); + } mount.Position = new Vector2(0, -startHeight); } - if (GetParentOrNull() == null) + if (GetParent() == null) { RoomManager.Current.SortRoot.AddChild(this); } @@ -133,7 +142,7 @@ /// 旋转速度 /// 需要挂载的节点 /// 抛射的节点显示的纹理, 用于渲染阴影用 - public void StartThrow(Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Node2D mount, Sprite shadowTarget) + public virtual void StartThrow(Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Node2D mount, Sprite shadowTarget) { StartThrow(size, start, startHeight, direction, xSpeed, ySpeed, rotate, mount); ShadowTarget = shadowTarget; @@ -171,7 +180,7 @@ public Node2D StopThrow() { var mount = Mount; - var parent = GetParentOrNull(); + var parent = GetParent(); if (parent != null && mount != null) { var gp = mount.GlobalPosition; diff --git a/DungeonShooting_Godot/src/weapon/gun/Gun.cs b/DungeonShooting_Godot/src/weapon/gun/Gun.cs index f61a605..7fe353d 100644 --- a/DungeonShooting_Godot/src/weapon/gun/Gun.cs +++ b/DungeonShooting_Godot/src/weapon/gun/Gun.cs @@ -487,18 +487,35 @@ return; } var gun = master.Holster.GetGun(index); + //子弹上限 var maxCount = Attribute.MaxAmmoCapacity; - + //是否捡到子弹 + var flag = false; if (ResidueAmmo > 0 && gun.CurrAmmo + gun.ResidueAmmo < maxCount) { - ResidueAmmo = gun.PickUpAmmo(ResidueAmmo); + var count = gun.PickUpAmmo(ResidueAmmo); + if (count != ResidueAmmo) + { + ResidueAmmo = count; + flag = true; + } } if (CurrAmmo > 0 && gun.CurrAmmo + gun.ResidueAmmo < maxCount) { - CurrAmmo = gun.PickUpAmmo(CurrAmmo); + var count = gun.PickUpAmmo(CurrAmmo); + if (count != CurrAmmo) + { + CurrAmmo = count; + flag = true; + } } - //CurrAmmo - //ResidueAmmo + //播放互动效果 + if (flag) + { + this.StartThrow(new Vector2(20, 20), GlobalPosition, 0, 0, + MathUtils.RandRangeInt(-20, 20), MathUtils.RandRangeInt(20, 50), + MathUtils.RandRangeInt(-180, 180), GunSprite); + } } else//没有武器 { diff --git a/DungeonShooting_Godot/src/weapon/gun/ThrowGun.cs b/DungeonShooting_Godot/src/weapon/gun/ThrowGun.cs index 56e7651..9ea6b86 100644 --- a/DungeonShooting_Godot/src/weapon/gun/ThrowGun.cs +++ b/DungeonShooting_Godot/src/weapon/gun/ThrowGun.cs @@ -10,6 +10,13 @@ base._Ready(); ZIndex = 2; } + + public override void StartThrow(Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Node2D mount) + { + base.StartThrow(size, start, startHeight, direction, xSpeed, ySpeed, rotate, mount); + fristOver = true; + } + protected override void OnOver() { if (fristOver)