2022-12-02 21:09:40 +01:00
|
|
|
using Godot;
|
|
|
|
using System;
|
|
|
|
|
2022-12-28 21:57:34 +01:00
|
|
|
public class Player : Entity
|
2022-12-02 21:09:40 +01:00
|
|
|
{
|
2022-12-28 21:57:34 +01:00
|
|
|
// public members
|
|
|
|
public Vector3 TargetPosition = Vector3.Zero;
|
2023-01-04 21:29:42 +01:00
|
|
|
|
2023-02-12 16:30:56 +01:00
|
|
|
public TaskQueueComponent TaskQueueComponent;
|
|
|
|
|
2023-01-04 21:29:42 +01:00
|
|
|
public NavigationComponent Navigation
|
|
|
|
{
|
|
|
|
get { return _navigationComponent; }
|
|
|
|
}
|
|
|
|
|
2022-12-28 21:57:34 +01:00
|
|
|
// private members
|
2022-12-04 20:51:02 +01:00
|
|
|
private MovableComponent _movable;
|
2022-12-06 21:06:25 +01:00
|
|
|
private Spatial _geometry;
|
2022-12-28 16:22:53 +01:00
|
|
|
private WorldInfoComponent _worldInfo;
|
2022-12-28 21:57:34 +01:00
|
|
|
private GroundMotionComponent _groundMotion;
|
2023-01-03 17:46:55 +01:00
|
|
|
private NavigationComponent _navigationComponent;
|
2022-12-02 21:09:40 +01:00
|
|
|
|
|
|
|
// Called when the node enters the scene tree for the first time.
|
|
|
|
public override void _Ready()
|
|
|
|
{
|
2022-12-28 21:57:34 +01:00
|
|
|
_groundMotion = new GroundMotionComponent();
|
2023-01-04 21:29:42 +01:00
|
|
|
_worldInfo = (WorldInfoComponent)FindNode("WorldInfo", false);
|
|
|
|
_navigationComponent = (NavigationComponent)FindNode("Navigation", false);
|
|
|
|
_navigationComponent.TileWorld = _worldInfo.TileWorld;
|
2023-02-12 16:30:56 +01:00
|
|
|
TaskQueueComponent = new TaskQueueComponent();
|
2022-12-06 21:06:25 +01:00
|
|
|
_geometry = (Spatial)FindNode("Geometry", false);
|
2022-12-02 21:09:40 +01:00
|
|
|
}
|
|
|
|
|
2022-12-28 21:57:34 +01:00
|
|
|
|
2022-12-31 18:36:52 +01:00
|
|
|
public override void _PhysicsProcess(float delta)
|
2022-12-28 21:57:34 +01:00
|
|
|
{
|
2022-12-31 18:36:52 +01:00
|
|
|
base._PhysicsProcess(delta);
|
2023-01-03 17:46:55 +01:00
|
|
|
|
2023-01-04 21:29:42 +01:00
|
|
|
if (_navigationComponent == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-01-03 17:46:55 +01:00
|
|
|
|
2023-02-12 16:30:56 +01:00
|
|
|
if (TaskQueueComponent != null && TaskQueueComponent.Queue.Count > 0)
|
|
|
|
{
|
2023-02-12 21:10:28 +01:00
|
|
|
TaskQueueComponent.Process(this, delta);
|
|
|
|
|
|
|
|
if (TaskQueueComponent.Queue.Count > 0)
|
2023-02-12 16:30:56 +01:00
|
|
|
{
|
2023-02-12 21:10:28 +01:00
|
|
|
var currentTask = TaskQueueComponent.Queue.Peek();
|
|
|
|
if (currentTask is TaskQueueComponent.NavigationTask)
|
|
|
|
{
|
|
|
|
TaskQueueComponent.NavigationTask navigationTask = (TaskQueueComponent.NavigationTask)currentTask;
|
|
|
|
_navigationComponent.Plan(GlobalTransform, navigationTask.NavigationPoint);
|
|
|
|
}
|
2023-02-12 16:30:56 +01:00
|
|
|
}
|
|
|
|
}
|
2023-01-03 17:46:55 +01:00
|
|
|
|
2023-02-12 16:30:56 +01:00
|
|
|
_navigationComponent.UpdateCurrentGoal(GlobalTransform);
|
|
|
|
_groundMotion.PhysicsProcess(delta, this, _navigationComponent.CurrentGoalPositionWorld, _navigationComponent.CurrentGoalOrientationWorld, _worldInfo.TileWorld);
|
2023-01-03 17:46:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void _Process(float delta)
|
|
|
|
{
|
2023-01-04 21:29:42 +01:00
|
|
|
if (_navigationComponent != null)
|
2023-01-03 17:46:55 +01:00
|
|
|
{
|
2023-02-12 16:30:56 +01:00
|
|
|
_navigationComponent.UpdateCurrentGoal(GlobalTransform);
|
2023-01-03 17:46:55 +01:00
|
|
|
}
|
2022-12-06 21:06:25 +01:00
|
|
|
}
|
2022-12-28 16:22:53 +01:00
|
|
|
}
|