Files
doom-dm/DoomDeathmatch/src/Component/ControllerComponent.cs
2024-12-16 04:28:45 +03:00

33 lines
1023 B
C#

using Engine.Input;
using OpenTK.Mathematics;
namespace DoomDeathmatch.Component;
public class ControllerComponent : Engine.Scene.Component.Component
{
public float Speed { get; set; } = 10.0f;
private readonly IInputHandler _inputHandler = Engine.Engine.Instance.InputHandler!;
public override void Update(double parDeltaTime)
{
var movement = Vector3.Zero;
if (_inputHandler.IsKeyPressed(KeyboardButtonCode.W))
movement.Z += 1;
if (_inputHandler.IsKeyPressed(KeyboardButtonCode.S))
movement.Z -= 1;
if (_inputHandler.IsKeyPressed(KeyboardButtonCode.A))
movement.X -= 1;
if (_inputHandler.IsKeyPressed(KeyboardButtonCode.D))
movement.X += 1;
if (_inputHandler.IsKeyPressed(KeyboardButtonCode.Space))
movement.Y += 1;
if (_inputHandler.IsKeyPressed(KeyboardButtonCode.Shift))
movement.Y -= 1;
if (movement.LengthSquared > 0)
movement.Normalize();
GameObject.Transform.Translation += movement * Speed * (float)parDeltaTime;
}
}