Add attribute system with core stats and gameplay components
This commit is contained in:
16
GameCore/Input/InputStateComponent.cs
Normal file
16
GameCore/Input/InputStateComponent.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using GameCore.ECS.Interfaces;
|
||||
using GameCore.Input.Interfaces;
|
||||
using GameCore.Math;
|
||||
|
||||
namespace GameCore.Input;
|
||||
|
||||
public class InputStateComponent : IComponent, IInputService
|
||||
{
|
||||
public Vector3 MuzzlePosition { get; set; }
|
||||
public Vector3 MuzzleDirection { get; set; }
|
||||
public bool IsFiring { get; set; }
|
||||
public bool IsInteracting { get; set; }
|
||||
public bool IsJumping { get; set; }
|
||||
public Vector3 MoveDirection { get; set; }
|
||||
public Vector3 LookDirection { get; set; }
|
||||
}
|
||||
12
GameCore/Input/Interfaces/IInputService.cs
Normal file
12
GameCore/Input/Interfaces/IInputService.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using GameCore.Math;
|
||||
|
||||
namespace GameCore.Input.Interfaces;
|
||||
|
||||
public interface IInputService
|
||||
{
|
||||
public bool IsFiring { get; }
|
||||
public bool IsInteracting { get; }
|
||||
public bool IsJumping { get; }
|
||||
public Vector3 MoveDirection { get; }
|
||||
public Vector3 LookDirection { get; }
|
||||
}
|
||||
24
GameCore/Input/PlayerInputSystem.cs
Normal file
24
GameCore/Input/PlayerInputSystem.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using GameCore.ECS;
|
||||
using GameCore.ECS.Interfaces;
|
||||
using GameCore.Player;
|
||||
|
||||
namespace GameCore.Input;
|
||||
|
||||
public class PlayerInputSystem : ISystem
|
||||
{
|
||||
public void Update(World world, float deltaTime)
|
||||
{
|
||||
var playerEntities = world.GetEntitiesWith<PlayerComponent>();
|
||||
if (!playerEntities.Any()) return;
|
||||
|
||||
var playerEntity = playerEntities.First();
|
||||
var inputState = world.GetComponent<InputStateComponent>(playerEntity);
|
||||
if (inputState == null) return;
|
||||
|
||||
inputState.MoveDirection = world.InputService.MoveDirection.Normalize();
|
||||
inputState.LookDirection = world.InputService.LookDirection;
|
||||
inputState.IsJumping = world.InputService.IsJumping;
|
||||
inputState.IsInteracting = world.InputService.IsInteracting;
|
||||
inputState.IsFiring = world.InputService.IsFiring;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user