Add initial resource and presenter classes for game entities and effects

This commit is contained in:
2025-10-13 12:11:50 +02:00
commit ad3e631d8c
75 changed files with 1423 additions and 0 deletions

View 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;
}
}

View File

@@ -0,0 +1 @@
uid://dp63r0vs7vydp

View File

@@ -0,0 +1,59 @@
using System;
using CryptonymThunder.Code.Autoloads;
using CryptonymThunder.Code.Extensions;
using CryptonymThunder.Code.Presenters;
using GameCore.ECS;
using GameCore.ECS.Interfaces;
using Godot;
using GodotWorld = Godot.World3D;
using Vector3 = GameCore.Math.Vector3;
namespace CryptonymThunder.Code.Services;
public class GodotWorldQuery(GamePresenter ownerNode) : IWorldQuery
{
private readonly PresenterRegistry _presenterRegistry = ownerNode.GetNode<PresenterRegistry>("/root/PresenterRegistry");
private readonly GodotWorld _godotWorld = ((SceneTree)Engine.GetMainLoop()).Root.World3D;
public HitResult Raycast(Vector3 from, Vector3 to, Entity? ownerToExclude = null)
{
var spaceState = _godotWorld.DirectSpaceState;
var query = PhysicsRayQueryParameters3D.Create(from.ToGodot(), to.ToGodot());
query.CollisionMask = 1;
query.CollideWithBodies = true;
query.CollideWithAreas = false;
if (ownerToExclude.HasValue)
{
var ownerPresenter = ownerNode.GetPresenterNode(ownerToExclude.Value);
if (ownerPresenter != null)
{
query.Exclude = [((PhysicsBody3D)ownerPresenter).GetRid()];
}
}
var result = spaceState.IntersectRay(query);
if (result.Count > 0 && result["collider"].Obj is Node3D collider)
{
if (_presenterRegistry.TryGetEntity(collider.GetInstanceId(), out var hitEntity))
{
return new HitResult
{
DidHit = true,
HitEntity = hitEntity
};
}
}
return new HitResult { DidHit = false };
}
public Vector3 RotateVectorByYaw(Vector3 vector, float yawRadians)
{
var rotatedX = vector.X * (float)Math.Cos(yawRadians) + vector.Z * (float)Math.Sin(yawRadians);
var rotatedZ = -vector.X * (float)Math.Sin(yawRadians) + vector.Z * (float)Math.Cos(yawRadians);
return new Vector3(rotatedX, vector.Y, rotatedZ);
}
}

View File

@@ -0,0 +1 @@
uid://l1tfuwnumj0m