diff --git a/DungeonShooting_Godot/project.godot b/DungeonShooting_Godot/project.godot index 3e53d71..b47fce3 100644 --- a/DungeonShooting_Godot/project.godot +++ b/DungeonShooting_Godot/project.godot @@ -109,7 +109,7 @@ } fire={ "deadzone": 0.5, -"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"pressed":false,"double_click":false,"script":null) +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"pressed":false,"double_click":false,"script":null) ] } move_left={ @@ -144,12 +144,12 @@ } mouse_roll_up={ "deadzone": 0.5, -"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":4,"pressed":false,"double_click":false,"script":null) +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":4,"pressed":false,"double_click":false,"script":null) ] } mouse_roll_down={ "deadzone": 0.5, -"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":5,"pressed":false,"double_click":false,"script":null) +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":5,"pressed":false,"double_click":false,"script":null) ] } interactive={ @@ -162,6 +162,16 @@ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":82,"physical_keycode":0,"key_label":0,"unicode":114,"echo":false,"script":null) ] } +meleeAttack={ +"deadzone": 0.5, +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(34.8, 12.8),"global_position":Vector2(38, 46),"factor":1.0,"button_index":2,"pressed":true,"double_click":false,"script":null) +] +} +roll={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} [layer_names] diff --git a/DungeonShooting_Godot/src/game/camera/GameCamera.cs b/DungeonShooting_Godot/src/game/camera/GameCamera.cs index 1e2f26f..3786268 100644 --- a/DungeonShooting_Godot/src/game/camera/GameCamera.cs +++ b/DungeonShooting_Godot/src/game/camera/GameCamera.cs @@ -74,7 +74,7 @@ var world = GameApplication.Instance.World; if (world != null && !world.Pause && _followTarget != null) { - var mousePosition = InputManager.GetViewportMousePosition(); + var mousePosition = InputManager.CursorPosition; var targetPosition = _followTarget.GlobalPosition; Vector2 targetPos; if (targetPosition.DistanceSquaredTo(mousePosition) >= (60 / 0.3f) * (60 / 0.3f)) diff --git a/DungeonShooting_Godot/src/game/manager/InputManager.cs b/DungeonShooting_Godot/src/game/manager/InputManager.cs index fae7fc0..4119692 100644 --- a/DungeonShooting_Godot/src/game/manager/InputManager.cs +++ b/DungeonShooting_Godot/src/game/manager/InputManager.cs @@ -7,20 +7,65 @@ public static class InputManager { /// - /// 获取鼠标在SubViewport节点下的坐标 + /// 移动方向 /// - public static Vector2 GetViewportMousePosition() - { - var application = GameApplication.Instance; - return application.GlobalToViewPosition(application.GetGlobalMousePosition()); - } + public static Vector2 MoveAxis { get; private set; } + + /// + /// 鼠标在SubViewport节点下的坐标 + /// + public static Vector2 CursorPosition { get; private set; } + + /// + /// 是否按下切换武器 + /// + public static bool Exchange { get; private set; } /// + /// 是否按钮投抛武器按钮 + /// + public static bool Throw { get; private set; } + + /// + /// 是否按钮互动按钮 + /// + public static bool Interactive { get; private set; } + + /// + /// 是否按钮换弹按钮 + /// + public static bool Reload { get; private set; } + + /// + /// 是否按钮开火按钮 + /// + public static bool Fire { get; private set; } + + /// + /// 是否按钮近战攻击按钮 (使用远程武器发起的近战攻击) + /// + public static bool MeleeAttack { get; private set; } + + /// + /// 是否按下翻滚按钮 + /// + public static bool Roll { get; private set; } + + /// /// 更新输入管理器 /// public static void Update(float delta) { - + var application = GameApplication.Instance; + MoveAxis = Input.GetVector("move_left", "move_right", "move_up", "move_down"); + CursorPosition = application.GlobalToViewPosition(application.GetGlobalMousePosition()); + Exchange = Input.IsActionJustPressed("exchange"); + Throw = Input.IsActionJustPressed("throw"); + Interactive = Input.IsActionJustPressed("interactive"); + Reload = Input.IsActionJustPressed("reload"); + Fire = Input.IsActionPressed("fire"); + MeleeAttack = Input.IsActionPressed("meleeAttack"); + Roll = Input.IsActionPressed("roll"); } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/role/Player.cs b/DungeonShooting_Godot/src/game/role/Player.cs index 7b30aff..0f7eda4 100644 --- a/DungeonShooting_Godot/src/game/role/Player.cs +++ b/DungeonShooting_Godot/src/game/role/Player.cs @@ -74,7 +74,7 @@ if (LookTarget == null) { var gPos = GlobalPosition; - Vector2 mousePos = InputManager.GetViewportMousePosition(); + Vector2 mousePos = InputManager.CursorPosition; if (mousePos.X > gPos.X && Face == FaceDirection.Left) { Face = FaceDirection.Right; @@ -87,11 +87,11 @@ MountPoint.SetLookAt(mousePos); } - if (Input.IsActionJustPressed("exchange")) //切换武器 + if (InputManager.Exchange) //切换武器 { ExchangeNext(); } - else if (Input.IsActionJustPressed("throw")) //扔掉武器 + else if (InputManager.Throw) //扔掉武器 { ThrowWeapon(); @@ -111,7 +111,7 @@ } } } - else if (Input.IsActionJustPressed("interactive")) //互动物体 + else if (InputManager.Interactive) //互动物体 { var item = TriggerInteractive(); if (item != null) @@ -119,11 +119,11 @@ RefreshWeaponTexture(); } } - else if (Input.IsActionJustPressed("reload")) //换弹 + else if (InputManager.Reload) //换弹 { Reload(); } - if (Input.IsActionPressed("fire")) //开火 + if (InputManager.Fire) //开火 { Attack(); } @@ -230,8 +230,7 @@ private void HandleMoveInput(float delta) { //角色移动 - // 得到输入的 vector2 getvector方法返回值已经归一化过了noemalized - Vector2 dir = Input.GetVector("move_left", "move_right", "move_up", "move_down"); + Vector2 dir = InputManager.MoveAxis; // 移动. 如果移动的数值接近0(是用 摇杆可能出现 方向 可能会出现浮点),就friction的值 插值 到 0 // 如果 有输入 就以当前速度,用acceleration 插值到 对应方向 * 最大速度 if (Mathf.IsZeroApprox(dir.X))