Actor stub

This commit is contained in:
MaddoScientisto 2025-02-17 21:53:05 +01:00
commit a1bbe63b66
4 changed files with 73 additions and 1 deletions

View file

@ -0,0 +1,38 @@
using System.Collections.Generic;
using Cirno.Scripts;
using Godot;
public partial class Actor : CharacterBody2D
{
[Export]
public float MovementSpeed { get; private set; }
public Vector2 FacingDirection { get; set; }
private GameManager _gameManager;
private List<MovementHandler> _movementHandlers = new();
public override void _Ready()
{
_gameManager = this.GetGameManager();
var children = GetChildren();
foreach (var child in children) {
if (child is MovementHandler movementHandler)
{
_movementHandlers.Add(movementHandler);
}
}
}
public override void _PhysicsProcess(double delta)
{
foreach (var handler in _movementHandlers)
{
handler.Move(delta);
}
}
}

View file

@ -0,0 +1,23 @@
using Godot;
public partial class ActorFreeMovement : MovementHandler
{
private Actor _parent;
public override void Init(Actor parent)
{
_parent = parent;
MovementDirection = Vector2.Zero;
_parent.FacingDirection = Vector2.Down;
}
public override void Move(double delta)
{
_parent.Velocity = MovementDirection * _parent.MovementSpeed;
_parent.MoveAndSlide();
}
}

View file

@ -0,0 +1,11 @@
using Godot;
public abstract partial class MovementHandler : Node2D
{
public Vector2 MovementDirection { get; set; }
public abstract void Init(Actor parent);
public abstract void Move(double delta);
}