mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
2D Character and weapons
This commit is contained in:
parent
072f6d0ce6
commit
cc9c4e5aa1
37 changed files with 1115 additions and 91 deletions
|
|
@ -6,28 +6,19 @@ namespace Cirno.Scripts.Components.Actors;
|
|||
|
||||
public partial class KeyboardInputProvider : InputProvider
|
||||
{
|
||||
[ExportCategory("Movement")]
|
||||
[Export]
|
||||
public StringName LeftAxisName { get; private set; } = "left";
|
||||
[Export]
|
||||
public StringName RightAxisName { get; private set; } = "right";
|
||||
[Export]
|
||||
public StringName UpAxisName { get; private set; } = "up";
|
||||
[Export]
|
||||
public StringName DownAxisName { get; private set; } = "down";
|
||||
[ExportCategory("Movement")] [Export] public StringName LeftAxisName { get; private set; } = "left";
|
||||
[Export] public StringName RightAxisName { get; private set; } = "right";
|
||||
[Export] public StringName UpAxisName { get; private set; } = "up";
|
||||
[Export] public StringName DownAxisName { get; private set; } = "down";
|
||||
|
||||
[ExportCategory("Aiming")]
|
||||
[Export]
|
||||
public StringName LeftAimName { get; private set; } = "aim_left";
|
||||
[Export]
|
||||
public StringName RightAimName { get; private set; } = "aim_right";
|
||||
[Export]
|
||||
public StringName UpAimName { get; private set; } = "aim_up";
|
||||
[Export]
|
||||
public StringName DownAimName { get; private set; } = "aim_down";
|
||||
[ExportCategory("Aiming")] [Export] public StringName LeftAimName { get; private set; } = "aim_left";
|
||||
[Export] public StringName RightAimName { get; private set; } = "aim_right";
|
||||
[Export] public StringName UpAimName { get; private set; } = "aim_up";
|
||||
[Export] public StringName DownAimName { get; private set; } = "aim_down";
|
||||
|
||||
[ExportCategory("Action Names")] [Export]
|
||||
private StringName _shootActionName = "shoot";
|
||||
|
||||
[ExportCategory("Action Names")]
|
||||
[Export] private StringName _shootActionName = "shoot";
|
||||
[Export] private StringName _useActionName = "Use";
|
||||
[Export] private StringName _scanActionName = "scan";
|
||||
[Export] private StringName _strafeActionName = "strafe";
|
||||
|
|
@ -38,7 +29,14 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
[Export] private StringName _freezeActionName = "Freeze";
|
||||
[Export] private StringName _reloadActionName = "Reload";
|
||||
|
||||
private enum AimInputMethod { RightStick, Mouse }
|
||||
private IMouseAimProvider _mouseAImProvider;
|
||||
|
||||
private enum AimInputMethod
|
||||
{
|
||||
RightStick,
|
||||
Mouse
|
||||
}
|
||||
|
||||
private AimInputMethod _lastUsedInput = AimInputMethod.RightStick;
|
||||
|
||||
public override void _Ready()
|
||||
|
|
@ -49,11 +47,19 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
|
||||
private void DelayedRegisterGameManager()
|
||||
{
|
||||
_mouseAImProvider = GetNodeOrNull<IMouseAimProvider>("MouseAimProvider");
|
||||
|
||||
if (_mouseAImProvider is null)
|
||||
{
|
||||
GD.Print("Mouse aim provider is null");
|
||||
}
|
||||
|
||||
if (GameManager.Instance is null)
|
||||
{
|
||||
GD.Print("No GameManager found for keyboard inputprovider");
|
||||
return;
|
||||
}
|
||||
|
||||
GameManager.Instance.GameStateChange += InstanceOnGameStateChange;
|
||||
_enabled = true;
|
||||
}
|
||||
|
|
@ -63,7 +69,7 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
private void InstanceOnGameStateChange(GameState state)
|
||||
{
|
||||
if (state is not GameState.Playing) return;
|
||||
|
||||
|
||||
_enabled = false;
|
||||
|
||||
_ = DelayResume();
|
||||
|
|
@ -75,7 +81,7 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
await Task.Delay(200);
|
||||
_enabled = true;
|
||||
}
|
||||
|
||||
|
||||
public override Vector2 GetMovementInput()
|
||||
{
|
||||
return Input.GetVector(LeftAxisName, RightAxisName, UpAxisName, DownAxisName);
|
||||
|
|
@ -98,26 +104,27 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
|
||||
return _lastUsedInput == AimInputMethod.RightStick ? rightStickInput : mouseInput;
|
||||
}
|
||||
|
||||
|
||||
private Vector2 GetRightStickInput()
|
||||
{
|
||||
return new Vector2(
|
||||
Input.GetAxis(LeftAimName,RightAimName),
|
||||
Input.GetAxis(LeftAimName, RightAimName),
|
||||
Input.GetAxis(UpAimName, DownAimName)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private Vector2 GetMouseAimInput()
|
||||
{
|
||||
//Camera2D camera = GetViewport().GetCamera2D();
|
||||
//if (camera == null) return Vector2.Zero; // Ensure there's a valid camera
|
||||
|
||||
//Vector2 mouseScreenPos = GetViewport().get_local_mouse_position();
|
||||
if (GameManager.Instance is null) return Vector2.Zero;
|
||||
|
||||
Vector2 mouseWorldPos = DisplayServer.MouseGetPosition();// GameManager.Instance.GetGlobalMousePosition();
|
||||
|
||||
return mouseWorldPos - GameManager.Instance.PlayerPosition.Value; // Get direction vector
|
||||
return _mouseAImProvider?.GetMouseAimInput() ?? Vector2.Zero;
|
||||
// //Camera2D camera = GetViewport().GetCamera2D();
|
||||
// //if (camera == null) return Vector2.Zero; // Ensure there's a valid camera
|
||||
//
|
||||
// //Vector2 mouseScreenPos = GetViewport().get_local_mouse_position();
|
||||
// if (GameManager.Instance is null) return Vector2.Zero;
|
||||
//
|
||||
// Vector2 mouseWorldPos = DisplayServer.MouseGetPosition();// GameManager.Instance.GetGlobalMousePosition();
|
||||
//
|
||||
// return mouseWorldPos - GameManager.Instance.PlayerPosition.Value; // Get direction vector
|
||||
}
|
||||
|
||||
public override bool GetActionJustPressed(string action)
|
||||
|
|
@ -134,12 +141,12 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
{
|
||||
return GetActionJustPressed(_inventoryActionName);
|
||||
}
|
||||
|
||||
|
||||
public override bool GetShootPressed()
|
||||
{
|
||||
return _enabled && GetActionPressed(_shootActionName);
|
||||
}
|
||||
|
||||
|
||||
public override bool GetShootJustPressed()
|
||||
{
|
||||
return GetActionJustPressed(_shootActionName);
|
||||
|
|
@ -149,6 +156,7 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
{
|
||||
return GetActionJustPressed(_useActionName);
|
||||
}
|
||||
|
||||
public override bool GetScanJustPressed()
|
||||
{
|
||||
return GetActionJustPressed(_scanActionName);
|
||||
|
|
@ -173,25 +181,24 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
{
|
||||
return GetActionJustPressed(_pauseActionName);
|
||||
}
|
||||
|
||||
|
||||
public override bool GetFreezeJustPressed()
|
||||
{
|
||||
return GetActionJustPressed(_freezeActionName);
|
||||
}
|
||||
|
||||
|
||||
public override bool GetFreezePressed()
|
||||
{
|
||||
return GetActionPressed(_freezeActionName);
|
||||
}
|
||||
|
||||
|
||||
public override bool GetReloadJustPressed()
|
||||
{
|
||||
return GetActionJustPressed(_reloadActionName);
|
||||
}
|
||||
|
||||
|
||||
public override bool GetReloadPressed()
|
||||
{
|
||||
return GetActionPressed(_reloadActionName);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue