Make Vesna entity save current position
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Babushka.scripts.CSharp.Common.Services;
|
using Babushka.scripts.CSharp.Common.Services;
|
||||||
|
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||||
@@ -8,6 +9,14 @@ public partial class PlayerMovement : CharacterBody2D
|
|||||||
[Export] private float _speed = 1000f;
|
[Export] private float _speed = 1000f;
|
||||||
[Export] private Timer _stepTimer;
|
[Export] private Timer _stepTimer;
|
||||||
|
|
||||||
|
private PositionalEntity _entity;
|
||||||
|
|
||||||
|
public void Initialize(PositionalEntity entity)
|
||||||
|
{
|
||||||
|
_entity = entity;
|
||||||
|
GlobalPosition = entity.position;
|
||||||
|
}
|
||||||
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
bool anyActionPressed = false;
|
bool anyActionPressed = false;
|
||||||
@@ -76,6 +85,7 @@ public partial class PlayerMovement : CharacterBody2D
|
|||||||
|
|
||||||
Velocity = currentVelocity;
|
Velocity = currentVelocity;
|
||||||
MoveAndSlide();
|
MoveAndSlide();
|
||||||
|
_entity.position = GlobalPosition;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public class VesnaEntity : PositionalEntity
|
|||||||
public override void InstantiateEntityNode(Node2D parent)
|
public override void InstantiateEntityNode(Node2D parent)
|
||||||
{
|
{
|
||||||
var node = (VesnaBehaviour2D) EntityManager.Instance.NodeCreator.InstantiateNode(OWN_TYPE_NAME);
|
var node = (VesnaBehaviour2D) EntityManager.Instance.NodeCreator.InstantiateNode(OWN_TYPE_NAME);
|
||||||
node.player2d.GlobalPosition = position;
|
node.player2d.Initialize(this);
|
||||||
parent.AddChild(node);
|
parent.AddChild(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,6 +93,7 @@ public partial class EntityManager : Node
|
|||||||
{
|
{
|
||||||
TrashEntity.OWN_TYPE_NAME => new TrashEntity(),
|
TrashEntity.OWN_TYPE_NAME => new TrashEntity(),
|
||||||
LoadedScenesEntity.OWN_TYPE_NAME => new LoadedScenesEntity(),
|
LoadedScenesEntity.OWN_TYPE_NAME => new LoadedScenesEntity(),
|
||||||
|
VesnaEntity.OWN_TYPE_NAME => new VesnaEntity(),
|
||||||
_ => throw new Exception($"Trying to load unknown entity type: {type}")
|
_ => throw new Exception($"Trying to load unknown entity type: {type}")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user