diff --git a/DungeonShooting_Godot/src/common/NodeExtend.cs b/DungeonShooting_Godot/src/common/NodeExtend.cs index 72c8570..2a2479a 100644 --- a/DungeonShooting_Godot/src/common/NodeExtend.cs +++ b/DungeonShooting_Godot/src/common/NodeExtend.cs @@ -37,10 +37,28 @@ public static bool Pickup(this Node2D node) { ThrowNode parent = node.GetParentOrNull(); - if (parent != null) { + if (parent != null) + { parent.StopThrow(); return true; } return false; } + + public static ThrowGun StartThrowGun(this Gun gun, Role master) + { + if (master.Face == FaceDirection.Left) + { + gun.Scale *= new Vector2(1, -1); + gun.RotationDegrees = 180; + } + var startPos = master.GlobalPosition;// + new Vector2(0, 0); + var startHeight = 6; + var direction = master.GlobalRotationDegrees + MathUtils.RandRangeInt(-20, 20); + var xf = 30; + var yf = MathUtils.RandRangeInt(60, 120); + var rotate = MathUtils.RandRangeInt(-180, 180); + gun.Position = Vector2.Zero; + return gun.StartThrow(new Vector2(20, 20), startPos, startHeight, direction, xf, yf, rotate, gun.GunSprite); + } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/effect/ThrowNode.cs b/DungeonShooting_Godot/src/effect/ThrowNode.cs index e49d8ea..4615833 100644 --- a/DungeonShooting_Godot/src/effect/ThrowNode.cs +++ b/DungeonShooting_Godot/src/effect/ThrowNode.cs @@ -176,6 +176,7 @@ { var gp = mount.GlobalPosition; var gr = mount.GlobalRotation; + IsOver = true; Mount = null; RemoveChild(mount); parent.AddChild(mount); @@ -207,6 +208,11 @@ { if (!IsOver) { + if (Mount == null) + { + QueueFree(); + return; + } MoveAndSlide(new Vector2(XSpeed, 0).Rotated(Direction * Mathf.Pi / 180)); Mount.Position = new Vector2(0, Mount.Position.y - YSpeed * delta); var rotate = Mount.GlobalRotationDegrees + RotateSpeed * delta; diff --git a/DungeonShooting_Godot/src/package/Holster.cs b/DungeonShooting_Godot/src/package/Holster.cs index 7428da0..932aa1a 100644 --- a/DungeonShooting_Godot/src/package/Holster.cs +++ b/DungeonShooting_Godot/src/package/Holster.cs @@ -102,13 +102,13 @@ var item = SlotList[i]; if (item.Enable && gun.Attribute.WeightType == item.Type && item.Gun == null) { + gun.Pickup(); item.Gun = gun; ExchangeByIndex(i); gun._PickUpGun(Master); return i; } } - GD.PrintErr("存入武器失败!"); return -1; } diff --git a/DungeonShooting_Godot/src/role/Role.cs b/DungeonShooting_Godot/src/role/Role.cs index b6eabb7..559c1eb 100644 --- a/DungeonShooting_Godot/src/role/Role.cs +++ b/DungeonShooting_Godot/src/role/Role.cs @@ -150,19 +150,7 @@ //播放抛出效果 if (gun != null) { - if (Face == FaceDirection.Left) - { - gun.Scale *= new Vector2(1, -1); - gun.RotationDegrees = 180; - } - gun.Position = Vector2.Zero; - 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); - gun.StartThrow(new Vector2(20, 20), startPos, startHeight, direction, xf, yf, rotate, gun.GunSprite); + gun.StartThrowGun(this); } } diff --git a/DungeonShooting_Godot/src/room/RoomManager.cs b/DungeonShooting_Godot/src/room/RoomManager.cs index 57bcf55..50f37cd 100644 --- a/DungeonShooting_Godot/src/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/room/RoomManager.cs @@ -54,6 +54,9 @@ var gun4 = GunManager.GetGun4(); gun4.Position = new Vector2(120, 120); gun4.PutDown(gun4.GunSprite); + var gun5 = GunManager.GetGun5(); + gun5.Position = new Vector2(160, 160); + gun5.PutDown(gun5.GunSprite); } public override void _Process(float delta) diff --git a/DungeonShooting_Godot/src/weapon/gun/Gun.cs b/DungeonShooting_Godot/src/weapon/gun/Gun.cs index 8f65d74..f61a605 100644 --- a/DungeonShooting_Godot/src/weapon/gun/Gun.cs +++ b/DungeonShooting_Godot/src/weapon/gun/Gun.cs @@ -281,9 +281,9 @@ OriginPoint.Position = new Vector2(0, -attribute.FirePosition.y); //弹药量 - CurrAmmo = attribute.CartridgeCapacity; + CurrAmmo = attribute.AmmoCapacity; //剩余弹药量 - ResidueAmmo = attribute.MaxCartridgeCapacity - attribute.CartridgeCapacity; + ResidueAmmo = attribute.MaxAmmoCapacity - attribute.AmmoCapacity; Init(); } @@ -435,7 +435,7 @@ public int PickUpAmmo(int count) { var num = ResidueAmmo; - ResidueAmmo = Mathf.Min(ResidueAmmo + count, Attribute.MaxCartridgeCapacity - CurrAmmo); + ResidueAmmo = Mathf.Min(ResidueAmmo + count, Attribute.MaxAmmoCapacity - CurrAmmo); return count - ResidueAmmo + num; } @@ -444,7 +444,7 @@ /// public void _Reload() { - if (CurrAmmo < Attribute.CartridgeCapacity && ResidueAmmo > 0 && !Reloading) + if (CurrAmmo < Attribute.AmmoCapacity && ResidueAmmo > 0 && !Reloading) { Reloading = true; ReloadTimer = Attribute.ReloadTime; @@ -464,10 +464,10 @@ else //换弹结束 { Reloading = false; - if (ResidueAmmo >= Attribute.CartridgeCapacity) + if (ResidueAmmo >= Attribute.AmmoCapacity) { - ResidueAmmo -= Attribute.CartridgeCapacity - CurrAmmo; - CurrAmmo = Attribute.CartridgeCapacity; + ResidueAmmo -= Attribute.AmmoCapacity - CurrAmmo; + CurrAmmo = Attribute.AmmoCapacity; } else { @@ -487,7 +487,7 @@ return; } var gun = master.Holster.GetGun(index); - var maxCount = Attribute.MaxCartridgeCapacity; + var maxCount = Attribute.MaxAmmoCapacity; if (ResidueAmmo > 0 && gun.CurrAmmo + gun.ResidueAmmo < maxCount) { @@ -502,9 +502,15 @@ } else//没有武器 { - if (this.Pickup()) + if (master.Holster.PickupGun(this) == -1) { - master.Holster.PickupGun(this); + var slot = master.Holster.SlotList[master.Holster.ActiveIndex]; + if (slot.Type == Attribute.WeightType) + { + var gun = master.Holster.RmoveGun(master.Holster.ActiveIndex); + gun.StartThrowGun(master); + master.Holster.PickupGun(this); + } } } } diff --git a/DungeonShooting_Godot/src/weapon/gun/GunAttribute.cs b/DungeonShooting_Godot/src/weapon/gun/GunAttribute.cs index db173dc..8e48069 100644 --- a/DungeonShooting_Godot/src/weapon/gun/GunAttribute.cs +++ b/DungeonShooting_Godot/src/weapon/gun/GunAttribute.cs @@ -14,7 +14,7 @@ /// public string Name = "Gun1"; /// - /// 主武器 + /// 武器类型 /// public GunWeightType WeightType = GunWeightType.MainWeapon; /// @@ -36,11 +36,11 @@ /// /// 弹夹容量 /// - public int CartridgeCapacity = 30; + public int AmmoCapacity = 30; /// /// 弹药容量上限 /// - public int MaxCartridgeCapacity = 90; + public int MaxAmmoCapacity = 90; /// /// 装弹时间 /// diff --git a/DungeonShooting_Godot/src/weapon/gun/GunManager.cs b/DungeonShooting_Godot/src/weapon/gun/GunManager.cs index c690018..50bc089 100644 --- a/DungeonShooting_Godot/src/weapon/gun/GunManager.cs +++ b/DungeonShooting_Godot/src/weapon/gun/GunManager.cs @@ -169,4 +169,49 @@ gun.Init(attr); return gun; } + + public static Gun GetGun5() + { + //加载枪的 prefab + var gun = ResourceManager.LoadGunAndInstance("res://prefab/weapon/Gun.tscn"); + //设置基础属性 + var attr = new GunAttribute(); + attr.Id = "5"; + attr.Name = "Gun5"; + attr.Weight = 10; + attr.CenterPosition = new Vector2(0.4f, -2.6f); + attr.WeightType = GunWeightType.DeputyWeapon; + attr.StartFiringSpeed = 480; + attr.StartScatteringRange = 5; + attr.FinalScatteringRange = 30; + attr.ScatteringRangeAddValue = 8f; + attr.ScatteringRangeBackSpeed = 40; + //连发 + attr.ContinuousShoot = true; + //扳机检测间隔 + attr.TriggerInterval = 0.4f; + //连发数量 + attr.MinContinuousCount = 1; + attr.MaxContinuousCount = 1; + //开火前延时 + attr.DelayedTime = 0f; + //攻击距离 + attr.MinDistance = 500; + attr.MaxDistance = 600; + //发射子弹数量 + attr.MinFireBulletCount = 1; + attr.MaxFireBulletCount = 1; + //弹夹容量 + attr.AmmoCapacity = 120; + attr.MaxAmmoCapacity = 360; + //抬起角度 + attr.UpliftAngle = 30; + //枪身长度 + attr.FirePosition = new Vector2(10, 1.5f); + attr.Sprite = ResourceManager.Load("res://resource/sprite/gun/gun5.png"); + attr.BulletPack = ResourceManager.Load("res://prefab/weapon/bullet/HighSpeedBullet.tscn"); + attr.ShellPack = ResourceManager.Load("res://prefab/weapon/shell/ShellCase.tscn"); + gun.Init(attr); + return gun; + } }