diff --git a/project.godot b/project.godot index b259443..cf7aefc 100644 --- a/project.godot +++ b/project.godot @@ -127,6 +127,11 @@ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"physical_scancode":0,"unicode":0,"echo":false,"script":null) ] } +exchange={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":81,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} [layer_names] diff --git a/src/common/CommonNodeManager.cs b/src/common/CommonNodeManager.cs deleted file mode 100644 index 83c1c90..0000000 --- a/src/common/CommonNodeManager.cs +++ /dev/null @@ -1,6 +0,0 @@ -using Godot; - -public static class CommonNodeManager -{ - -} \ No newline at end of file diff --git a/src/package/Holster.cs b/src/package/Holster.cs new file mode 100644 index 0000000..acd5ef6 --- /dev/null +++ b/src/package/Holster.cs @@ -0,0 +1,95 @@ +using Godot; + +/// +/// 角色身上的枪套, 存储角色携带的武器 +/// +public class Holster +{ + /// + /// 插槽类 + /// + public class GunSlot + { + /// + /// 是否启用 + /// + public bool Enable = false; + /// + /// 当前插槽存放的武器类型 + /// + public GunWeightType Type = GunWeightType.MainWeapon; + /// + /// 插槽存放的武器 + /// + public Gun Gun; + } + + /// + /// 归属者 + /// + public Role Master { get; } + + public Gun ActiveGun { get; private set; } + public int ActiveIndex { get; private set; } + + public GunSlot[] SlotList { get; } = new GunSlot[4]; + + public Holster(Role master) + { + Master = master; + + //创建枪的插槽, 默认前两个都是启用的 + GunSlot slot1 = new GunSlot(); + slot1.Enable = true; + SlotList[0] = slot1; + + GunSlot slot2 = new GunSlot(); + slot2.Enable = true; + slot2.Type = GunWeightType.DeputyWeapon; + SlotList[1] = slot2; + + GunSlot slot3 = new GunSlot(); + SlotList[2] = slot3; + + GunSlot slot4 = new GunSlot(); + slot4.Type = GunWeightType.DeputyWeapon; + SlotList[3] = slot4; + } + + /// + /// 拾起武器, 存入枪套中, 如果容不下这把武器, 则会返回 false + /// + /// 武器对象 + public bool PickupGun(Gun gun) + { + for (int i = 0; i < SlotList.Length; i++) + { + var item = SlotList[i]; + if (item.Enable && gun.Attribute.WeightType == item.Type && item.Gun == null) + { + item.Gun = gun; + ActiveGun = gun; + ActiveIndex = i; + return true; + } + } + GD.PrintErr("存入武器失败!"); + return false; + } + + /// + /// 切换到上一个武器 + /// + public void ExchangePrev() + { + + } + + /// + /// 切换到下一个武器 + /// + public void ExchangeNext() + { + + } +} diff --git a/src/role/Player.cs b/src/role/Player.cs index fe5f268..cc76373 100644 --- a/src/role/Player.cs +++ b/src/role/Player.cs @@ -16,11 +16,6 @@ /// public Vector2 Velocity = Vector2.Zero; - /// - /// 当前的枪 - /// - public Gun CurrGun { get; private set; } - [Export] public PackedScene GunPrefab; public override void _Ready() @@ -30,7 +25,6 @@ //加载枪 var gun = GunPrefab.Instance(); MountPoint.AddChild(gun); - CurrGun = gun; var attr = new GunAttribute(); attr.StartFiringSpeed = 480; @@ -60,6 +54,7 @@ attr.Sprite = "res://resource/sprite/gun/gun4.png"; gun.Init(attr); gun.FireEvent += FireEvent_Func; + Holster.PickupGun(gun); RoomManager.Current.Cursor.TargetGun = gun; } @@ -95,19 +90,6 @@ private void Move(float delta) { //角色移动 - // var dir = new Vector2( - // Input.GetActionRawStrength("move_right") - Input.GetActionRawStrength("move_left"), - // Input.GetActionRawStrength("move_down") - Input.GetActionRawStrength("move_up") - // ).Normalized(); - // if (dir.x * Velocity.x < 0) - // { - // Velocity.x = 0; - // } - // if (dir.y * Velocity.y < 0) - // { - // Velocity.y = 0; - // } - // Velocity = Velocity.MoveToward(dir * MoveSpeed, Acceleration * delta); // 得到输入的 vector2 getvector方法返回值已经归一化过了noemalized Vector2 dir = Input.GetVector("move_left", "move_right", "move_up", "move_down"); // 移动. 如果移动的数值接近0(是用 摇杆可能出现 方向 可能会出现浮点),就fricition的值 插值 到 0 @@ -125,7 +107,10 @@ { if (Input.IsActionPressed("fire")) { - CurrGun.Trigger(); + if (Holster.ActiveGun != null) + { + Holster.ActiveGun.Trigger(); + } } } diff --git a/src/role/Role.cs b/src/role/Role.cs index 78ac69f..335b3df 100644 --- a/src/role/Role.cs +++ b/src/role/Role.cs @@ -35,6 +35,11 @@ /// public List PropsPack { get; } = new List(); + /// + /// 角色携带的枪套 + /// + public Holster Holster { get; private set; } + /// /// 动画播放器 /// @@ -61,7 +66,8 @@ ChangeFrameTexture(AnimatorNames.Idle, AnimatedSprite, Texture); ChangeFrameTexture(AnimatorNames.Run, AnimatedSprite, Texture); ChangeFrameTexture(AnimatorNames.ReverseRun, AnimatedSprite, Texture); - + + Holster = new Holster(this); Face = FaceDirection.Right; } diff --git a/src/weapon/gun/GunAttribute.cs b/src/weapon/gun/GunAttribute.cs index aaeab64..38a338d 100644 --- a/src/weapon/gun/GunAttribute.cs +++ b/src/weapon/gun/GunAttribute.cs @@ -6,6 +6,10 @@ public class GunAttribute { /// + /// 主武器 + /// + public GunWeightType WeightType = GunWeightType.MainWeapon; + /// /// 枪的图片 /// public string Sprite = "res://resource/sprite/gun/gun1.png"; diff --git a/src/weapon/gun/GunWeightType.cs b/src/weapon/gun/GunWeightType.cs new file mode 100644 index 0000000..4181693 --- /dev/null +++ b/src/weapon/gun/GunWeightType.cs @@ -0,0 +1,19 @@ + +/// +/// 根据重量划分的武器类型 +/// +public enum GunWeightType +{ + /// + /// 副武器 + /// + DeputyWeapon = 1, + /// + /// 主武器 + /// + MainWeapon = 2, + /// + /// 重型武器 + /// + HeavyWeapon = 3 +} \ No newline at end of file