Add initial resource and presenter classes for game entities and effects
This commit is contained in:
47
Code/Services/GodotInputService.cs
Normal file
47
Code/Services/GodotInputService.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using GameCore.Input.Interfaces;
|
||||
using Godot;
|
||||
using GameCoreMath = GameCore.Math.Vector3;
|
||||
|
||||
namespace CryptonymThunder.Code.Services;
|
||||
|
||||
public class GodotInputService : IInputService
|
||||
{
|
||||
private Vector2 _mouseDeltaAccumulator = Vector2.Zero;
|
||||
private const float MouseSensitivity = 0.002f;
|
||||
|
||||
public bool IsFiring { get; private set; }
|
||||
public bool IsInteracting { get; private set; }
|
||||
public bool IsJumping { get; private set; }
|
||||
public GameCoreMath MoveDirection { get; private set; }
|
||||
public GameCoreMath LookDirection { get; private set; }
|
||||
|
||||
public void HandleInputEvent(InputEvent e)
|
||||
{
|
||||
if (e is InputEventMouseMotion mouseMotion)
|
||||
{
|
||||
_mouseDeltaAccumulator += mouseMotion.Relative;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
var godotInputVector = Input.GetVector("left", "right", "forward", "backward");
|
||||
MoveDirection = new GameCoreMath(godotInputVector.X, 0f, godotInputVector.Y);
|
||||
|
||||
LookDirection = new GameCoreMath(
|
||||
-_mouseDeltaAccumulator.Y * MouseSensitivity,
|
||||
-_mouseDeltaAccumulator.X * MouseSensitivity,
|
||||
0f);
|
||||
|
||||
_mouseDeltaAccumulator = Vector2.Zero;
|
||||
|
||||
IsJumping = Input.IsActionJustPressed("jump");
|
||||
IsFiring = Input.IsActionPressed("fire");
|
||||
IsInteracting = Input.IsActionPressed("interact");
|
||||
}
|
||||
|
||||
public void LateUpdate()
|
||||
{
|
||||
LookDirection = GameCoreMath.Zero;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user