diff --git a/DungeonShooting_Godot/src/role/Player.cs b/DungeonShooting_Godot/src/role/Player.cs index 71fa511..efe2d5c 100644 --- a/DungeonShooting_Godot/src/role/Player.cs +++ b/DungeonShooting_Godot/src/role/Player.cs @@ -60,10 +60,6 @@ base._Ready(); Holster.SlotList[2].Enable = true; Holster.SlotList[3].Enable = true; - // PickUpWeapon(WeaponManager.GetGun1()); //0 - // PickUpWeapon(WeaponManager.GetGun2()); //1 - // PickUpWeapon(WeaponManager.GetGun3()); //2 - // PickUpWeapon(WeaponManager.GetGun4()); //3 RefreshGunTexture(); MaxHp = 50; diff --git a/DungeonShooting_Godot/src/room/RoomManager.cs b/DungeonShooting_Godot/src/room/RoomManager.cs index c3a1711..b66bccf 100644 --- a/DungeonShooting_Godot/src/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/room/RoomManager.cs @@ -46,12 +46,12 @@ var gun1 = WeaponManager.GetGun("1001"); gun1.Position = new Vector2(80, 80); gun1.PutDown(gun1.WeaponSprite); - // var gun2 = WeaponManager.GetGun2(); - // gun2.Position = new Vector2(80, 120); - // gun2.PutDown(gun2.WeaponSprite); - // var gun3 = WeaponManager.GetGun3(); - // gun3.Position = new Vector2(120, 80); - // gun3.PutDown(gun3.WeaponSprite); + var gun2 = WeaponManager.GetGun("1002"); + gun2.Position = new Vector2(80, 120); + gun2.PutDown(gun2.WeaponSprite); + var gun3 = WeaponManager.GetGun("1003"); + gun3.Position = new Vector2(120, 80); + gun3.PutDown(gun3.WeaponSprite); // var gun4 = WeaponManager.GetGun4(); // gun4.Position = new Vector2(120, 120); // gun4.PutDown(gun4.WeaponSprite); diff --git a/DungeonShooting_Godot/src/weapon/Weapon.cs b/DungeonShooting_Godot/src/weapon/Weapon.cs index 01bda48..2cde361 100644 --- a/DungeonShooting_Godot/src/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/weapon/Weapon.cs @@ -121,6 +121,11 @@ //连发状态记录 private bool continuousShootFlag = false; + /// + /// 根据属性创建一把武器 + /// + /// 武器唯一id + /// 属性 public Weapon(string id, WeaponAttribute attribute) { Id = id; @@ -138,25 +143,40 @@ } /// - /// 初始化时调用 + /// 初始化基础数据完成时调用 /// protected abstract void Init(); /// + /// 当按下扳机时调用 + /// + protected abstract void OnDownTrigger(); + + /// + /// 当松开扳机时调用 + /// + protected abstract void OnUpTrigger(); + + /// /// 单次开火时调用的函数 /// protected abstract void OnFire(); /// - /// 换弹时调用 + /// 发射子弹时调用的函数, 每发射一枚子弹调用一次, + /// 如果做霰弹武器效果, 一次开火发射5枚子弹, 则该函数调用5次 + /// + protected abstract void OnShoot(); + + /// + /// 当开始换弹时调用 /// protected abstract void OnReload(); /// - /// 发射子弹时调用的函数, 每发射一枚子弹调用一次, - /// 如果做霰弹武器效果, 一次开火发射5枚子弹, 则该函数调用5次 + /// 当换弹完成时调用 /// - protected abstract void OnShootBullet(); + protected abstract void OnReloadFinish(); /// /// 当武器被拾起时调用 @@ -165,7 +185,7 @@ protected abstract void OnPickUp(Role master); /// - /// 当武器被扔掉时调用 + /// 当武器从武器袋中扔掉时调用 /// protected abstract void OnThrowOut(); @@ -348,10 +368,10 @@ if (flag) { - var fireFlag = true; + var fireFlag = true; //是否能开火 if (Reloading) //换弹中 { - if (Attribute.AloneReload && Attribute.AloneReloadCanShoot) //立即停止换弹 + if (CurrAmmo > 0 && Attribute.AloneReload && Attribute.AloneReloadCanShoot) //立即停止换弹 { Reloading = false; ReloadTimer = 0; @@ -398,7 +418,7 @@ /// private void DownTrigger() { - + OnDownTrigger(); } /// @@ -411,6 +431,7 @@ { continuousCount = 0; } + OnUpTrigger(); } /// @@ -441,7 +462,7 @@ //先算武器口方向 Rotation = (float)GD.RandRange(-angle, angle); //发射子弹 - OnShootBullet(); + OnShoot(); } //当前的散射半径 @@ -537,6 +558,7 @@ { Reloading = false; ReloadTimer = 0; + OnReloadFinish(); } else { @@ -546,8 +568,6 @@ } else //换弹结束 { - Reloading = false; - ReloadTimer = 0; if (ResidueAmmo >= Attribute.AmmoCapacity) { ResidueAmmo -= Attribute.AmmoCapacity - CurrAmmo; @@ -558,6 +578,9 @@ CurrAmmo = ResidueAmmo; ResidueAmmo = 0; } + Reloading = false; + ReloadTimer = 0; + OnReloadFinish(); } } diff --git a/DungeonShooting_Godot/src/weapon/WeaponAttribute.cs b/DungeonShooting_Godot/src/weapon/WeaponAttribute.cs index 27c46e5..c6cad38 100644 --- a/DungeonShooting_Godot/src/weapon/WeaponAttribute.cs +++ b/DungeonShooting_Godot/src/weapon/WeaponAttribute.cs @@ -20,7 +20,7 @@ /// /// 武器的图片 /// - public string Sprite = "res://resource/sprite/gun/gun4.png"; + public string Sprite = "res://resource/sprite/gun/gun1.png"; /// /// 是否连续发射, 如果为false, 则每次发射都需要扣动扳机 /// @@ -149,9 +149,4 @@ /// 开火后武器口角度恢复速度倍数 /// public float UpliftAngleRestore = 1; - - public WeaponAttribute() - { - - } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/weapon/WeaponManager.cs b/DungeonShooting_Godot/src/weapon/WeaponManager.cs index 5343aa2..9137249 100644 --- a/DungeonShooting_Godot/src/weapon/WeaponManager.cs +++ b/DungeonShooting_Godot/src/weapon/WeaponManager.cs @@ -8,7 +8,6 @@ /// public static class WeaponManager { - private static Dictionary> registerData = new Dictionary>(); /// @@ -116,224 +115,4 @@ { return (T)GetGun(id); } - - //----------------------------- 以下均为临时处理 ------------------------------- - /* - public static Weapon GetGun1() - { - //加载枪的 prefab - var gun = ResourceManager.LoadWeaponAndInstance("res://prefab/weapon/Weapon.tscn"); - //设置基础属性 - var attr = new WeaponAttribute(); - attr.Id = "1"; - attr.Name = "Gun1"; - attr.Weight = 40; - attr.CenterPosition = new Vector2(0.4f, -2.6f); - attr.StartFiringSpeed = 480; - attr.StartScatteringRange = 30; - attr.FinalScatteringRange = 90; - attr.ScatteringRangeAddValue = 2f; - attr.ScatteringRangeBackSpeed = 40; - //连发 - attr.ContinuousShoot = true; - //扳机检测间隔 - attr.TriggerInterval = 0f; - //连发数量 - attr.MinContinuousCount = 3; - attr.MaxContinuousCount = 3; - //开火前延时 - attr.DelayedTime = 0f; - //攻击距离 - attr.MinDistance = 500; - attr.MaxDistance = 600; - //发射子弹数量 - attr.MinFireBulletCount = 1; - attr.MaxFireBulletCount = 1; - //抬起角度 - attr.UpliftAngle = 10; - //枪身长度 - attr.FirePosition = new Vector2(16, 1.5f); - attr.Sprite = ResourceManager.Load("res://resource/sprite/gun/gun4.png"); - attr.BulletPack = ResourceManager.Load("res://prefab/weapon/bullet/OrdinaryBullets.tscn"); - attr.ShellPack = ResourceManager.Load("res://prefab/weapon/shell/ShellCase.tscn"); - gun.Init(attr); - return gun; - } - - public static Weapon GetGun2() - { - //加载枪的 prefab - var gun = ResourceManager.LoadWeaponAndInstance("res://prefab/weapon/Weapon.tscn"); - //设置基础属性 - var attr = new WeaponAttribute(); - attr.Id = "2"; - attr.Name = "Gun2"; - attr.Weight = 20; - attr.CenterPosition = new Vector2(0.4f, -2.6f); - attr.WeightType = WeaponWeightType.DeputyWeapon; - attr.StartFiringSpeed = 600; - attr.StartScatteringRange = 5; - attr.FinalScatteringRange = 60; - attr.ScatteringRangeAddValue = 8f; - attr.ScatteringRangeBackSpeed = 40; - //连发 - attr.ContinuousShoot = false; - //扳机检测间隔 - attr.TriggerInterval = 0.4f; - //连发数量 - attr.MinContinuousCount = 3; - attr.MaxContinuousCount = 3; - //开火前延时 - attr.DelayedTime = 0f; - //攻击距离 - attr.MinDistance = 500; - attr.MaxDistance = 600; - //发射子弹数量 - attr.MinFireBulletCount = 1; - attr.MaxFireBulletCount = 1; - //抬起角度 - attr.UpliftAngle = 30; - //枪身长度 - attr.FirePosition = new Vector2(10, 1.5f); - attr.Sprite = ResourceManager.Load("res://resource/sprite/gun/gun3.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; - } - - public static Weapon GetGun3() - { - //加载枪的 prefab - var gun = ResourceManager.LoadWeaponAndInstance("res://prefab/weapon/gun/Shotgun.tscn"); - //设置基础属性 - var attr = new WeaponAttribute(); - attr.Id = "3"; - attr.Name = "Gun3"; - attr.Weight = 30; - attr.CenterPosition = new Vector2(0.4f, -2.6f); - attr.StartFiringSpeed = 180; - attr.StartScatteringRange = 30; - attr.FinalScatteringRange = 90; - attr.ScatteringRangeAddValue = 2f; - attr.ScatteringRangeBackSpeed = 40; - //连发 - attr.ContinuousShoot = false; - //装弹时间 - attr.ReloadTime = 0.4f; - //单独装弹 - attr.AloneReload = true; - attr.AloneReloadCount = 1; - attr.AloneReloadCanShoot = true; - //扳机检测间隔 - attr.TriggerInterval = 0f; - //连发数量 - attr.MinContinuousCount = 1; - attr.MaxContinuousCount = 1; - //开火前延时 - attr.DelayedTime = 0f; - //攻击距离 - attr.MinDistance = 150; - attr.MaxDistance = 200; - //发射子弹数量 - attr.MinFireBulletCount = 1; - attr.MaxFireBulletCount = 1; - //抬起角度 - attr.UpliftAngle = 10; - //枪身长度 - attr.FirePosition = new Vector2(16, 1.5f); - attr.Sprite = ResourceManager.Load("res://resource/sprite/gun/gun2.png"); - attr.BulletPack = ResourceManager.Load("res://prefab/weapon/bullet/OrdinaryBullets.tscn"); - attr.ShellPack = ResourceManager.Load("res://prefab/weapon/shell/ShellCase.tscn"); - gun.Init(attr); - return gun; - } - - public static Weapon GetGun4() - { - //加载枪的 prefab - var gun = ResourceManager.LoadWeaponAndInstance("res://prefab/weapon/Weapon.tscn"); - //设置基础属性 - var attr = new WeaponAttribute(); - attr.Id = "4"; - attr.Name = "Gun4"; - attr.Weight = 10; - attr.CenterPosition = new Vector2(0.4f, -2.6f); - attr.WeightType = WeaponWeightType.DeputyWeapon; - attr.StartFiringSpeed = 600; - attr.StartScatteringRange = 5; - attr.FinalScatteringRange = 60; - attr.ScatteringRangeAddValue = 8f; - attr.ScatteringRangeBackSpeed = 40; - //连发 - attr.ContinuousShoot = false; - //扳机检测间隔 - attr.TriggerInterval = 0.4f; - //连发数量 - attr.MinContinuousCount = 3; - attr.MaxContinuousCount = 3; - //开火前延时 - attr.DelayedTime = 0f; - //攻击距离 - attr.MinDistance = 500; - attr.MaxDistance = 600; - //发射子弹数量 - attr.MinFireBulletCount = 1; - attr.MaxFireBulletCount = 1; - //抬起角度 - attr.UpliftAngle = 30; - //枪身长度 - attr.FirePosition = new Vector2(10, 1.5f); - attr.Sprite = ResourceManager.Load("res://resource/sprite/gun/gun7.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; - } - - public static Weapon GetGun5() - { - //加载枪的 prefab - var gun = ResourceManager.LoadWeaponAndInstance("res://prefab/weapon/Weapon.tscn"); - //设置基础属性 - var attr = new WeaponAttribute(); - attr.Id = "5"; - attr.Name = "Gun5"; - attr.Weight = 10; - attr.CenterPosition = new Vector2(0.4f, -2.6f); - attr.WeightType = WeaponWeightType.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; - } - */ } diff --git a/DungeonShooting_Godot/src/weapon/gun/Gun.cs b/DungeonShooting_Godot/src/weapon/gun/Gun.cs index 34f18be..2acfbb7 100644 --- a/DungeonShooting_Godot/src/weapon/gun/Gun.cs +++ b/DungeonShooting_Godot/src/weapon/gun/Gun.cs @@ -1,14 +1,87 @@ -using System; using Godot; -[RegisterWeapon("1001", typeof(WeaponAttribute))] -[RegisterWeapon("1002")] +[RegisterWeapon("1001", typeof(Gun.RifleAttribute))] +[RegisterWeapon("1003", typeof(Gun.PistolAttribute))] /// /// 普通的枪 /// public class Gun : Weapon { - + //步枪属性数据 + private class RifleAttribute : WeaponAttribute + { + public RifleAttribute() + { + Name = "步枪"; + Sprite = "res://resource/sprite/gun/gun4.png"; + Weight = 40; + CenterPosition = new Vector2(0.4f, -2.6f); + StartFiringSpeed = 480; + StartScatteringRange = 30; + FinalScatteringRange = 90; + ScatteringRangeAddValue = 2f; + ScatteringRangeBackSpeed = 40; + //连发 + ContinuousShoot = true; + //扳机检测间隔 + TriggerInterval = 0f; + //连发数量 + MinContinuousCount = 3; + MaxContinuousCount = 3; + //开火前延时 + DelayedTime = 0f; + //攻击距离 + MinDistance = 500; + MaxDistance = 600; + //发射子弹数量 + MinFireBulletCount = 1; + MaxFireBulletCount = 1; + //抬起角度 + UpliftAngle = 10; + //枪身长度 + FirePosition = new Vector2(16, 1.5f); + } + } + + //手枪属性数据 + private class PistolAttribute : WeaponAttribute + { + public PistolAttribute() + { + Name = "手枪"; + Sprite = "res://resource/sprite/gun/gun3.png"; + Weight = 20; + CenterPosition = new Vector2(0.4f, -2.6f); + WeightType = WeaponWeightType.DeputyWeapon; + StartFiringSpeed = 300; + StartScatteringRange = 5; + FinalScatteringRange = 60; + ScatteringRangeAddValue = 8f; + ScatteringRangeBackSpeed = 40; + //连发 + ContinuousShoot = false; + AmmoCapacity = 12; + MaxAmmoCapacity = 72; + //扳机检测间隔 + TriggerInterval = 0.1f; + //连发数量 + MinContinuousCount = 1; + MaxContinuousCount = 1; + //开火前延时 + DelayedTime = 0f; + //攻击距离 + MinDistance = 500; + MaxDistance = 600; + //发射子弹数量 + MinFireBulletCount = 1; + MaxFireBulletCount = 1; + //抬起角度 + UpliftAngle = 30; + //枪身长度 + FirePosition = new Vector2(10, 1.5f); + } + } + /// /// 子弹预制体 /// @@ -18,12 +91,6 @@ /// public PackedScene ShellPack; - [RegisterWeaponFunction("1003")] - private static Gun Test(string id) - { - return new Gun(id, new WeaponAttribute()); - } - public Gun(string id, WeaponAttribute attribute): base(id, attribute) { BulletPack = ResourceManager.Load("res://prefab/weapon/bullet/OrdinaryBullets.tscn"); @@ -50,7 +117,7 @@ MainCamera.Main.ProssesDirectionalShake(Vector2.Right.Rotated(GlobalRotation) * 1.5f); } - protected override void OnShootBullet() + protected override void OnShoot() { //创建子弹 CreateBullet(BulletPack, FirePoint.GlobalPosition, (FirePoint.GlobalPosition - OriginPoint.GlobalPosition).Angle()); @@ -61,6 +128,21 @@ } + protected override void OnReloadFinish() + { + + } + + protected override void OnDownTrigger() + { + + } + + protected override void OnUpTrigger() + { + + } + protected override void OnPickUp(Role master) { diff --git a/DungeonShooting_Godot/src/weapon/gun/Shotgun.cs b/DungeonShooting_Godot/src/weapon/gun/Shotgun.cs index 7825375..f66b5f2 100644 --- a/DungeonShooting_Godot/src/weapon/gun/Shotgun.cs +++ b/DungeonShooting_Godot/src/weapon/gun/Shotgun.cs @@ -1,8 +1,49 @@ using Godot; +[RegisterWeapon("1002", typeof(Shotgun.ShotgunAttribute))] public class Shotgun : Weapon { + private class ShotgunAttribute : WeaponAttribute + { + public ShotgunAttribute() + { + Name = "霰弹枪"; + Sprite = "res://resource/sprite/gun/gun2.png"; + Weight = 40; + CenterPosition = new Vector2(0.4f, -2.6f); + StartFiringSpeed = 120; + StartScatteringRange = 30; + FinalScatteringRange = 90; + ScatteringRangeAddValue = 50f; + ScatteringRangeBackSpeed = 50; + //连发 + ContinuousShoot = false; + AmmoCapacity = 7; + MaxAmmoCapacity = 42; + AloneReload = true; + AloneReloadCanShoot = true; + ReloadTime = 0.3f; + //连发数量 + MinContinuousCount = 1; + MaxContinuousCount = 1; + //开火前延时 + DelayedTime = 0f; + //攻击距离 + MinDistance = 500; + MaxDistance = 600; + //发射子弹数量 + MinFireBulletCount = 1; + MaxFireBulletCount = 1; + //抬起角度 + UpliftAngle = 15; + MaxBacklash = 6; + MinBacklash = 5; + //枪身长度 + FirePosition = new Vector2(16, 1.5f); + } + } + /// /// 子弹预制体 /// @@ -12,7 +53,7 @@ /// public PackedScene ShellPack; - public Shotgun(string id, WeaponAttribute attribute): base(id, attribute) + public Shotgun(string id, WeaponAttribute attribute) : base(id, attribute) { BulletPack = ResourceManager.Load("res://prefab/weapon/bullet/OrdinaryBullets.tscn"); ShellPack = ResourceManager.Load("res://prefab/weapon/shell/ShellCase.tscn"); @@ -38,7 +79,7 @@ MainCamera.Main.ProssesDirectionalShake(Vector2.Right.Rotated(GlobalRotation) * 1.5f); } - protected override void OnShootBullet() + protected override void OnShoot() { for (int i = 0; i < 5; i++) { @@ -49,12 +90,27 @@ protected override void OnReload() { + + } + + protected override void OnReloadFinish() + { + + } + + protected override void OnDownTrigger() + { } + protected override void OnUpTrigger() + { + + } + protected override void OnPickUp(Role master) { - + } protected override void OnThrowOut() @@ -64,11 +120,11 @@ protected override void OnActive() { - + } protected override void OnConceal() { - + } }