cirnogodot/Scripts/Components/Actors/Actor.cs

53 lines
1.3 KiB
C#
Raw Normal View History

2025-02-17 21:53:05 +01:00
using System.Collections.Generic;
using Cirno.Scripts;
2025-02-18 17:40:33 +01:00
using Cirno.Scripts.Components.Actors;
2025-02-17 21:53:05 +01:00
using Godot;
public partial class Actor : CharacterBody2D
{
[Export]
public float MovementSpeed { get; private set; }
2025-02-18 17:40:33 +01:00
public Vector2 MovementDirection { get; set; }
2025-02-17 21:53:05 +01:00
public Vector2 FacingDirection { get; set; }
private GameManager _gameManager;
private List<MovementHandler> _movementHandlers = new();
2025-02-18 17:40:33 +01:00
private List<AnimationHandler> _animationHandlers = new();
2025-02-17 21:53:05 +01:00
public override void _Ready()
{
_gameManager = this.GetGameManager();
var children = GetChildren();
foreach (var child in children) {
if (child is MovementHandler movementHandler)
{
_movementHandlers.Add(movementHandler);
2025-02-18 17:40:33 +01:00
movementHandler.Init(this);
}
else if (child is AnimationHandler animationHandler)
{
_animationHandlers.Add(animationHandler);
animationHandler.Init(this);
2025-02-17 21:53:05 +01:00
}
}
}
public override void _PhysicsProcess(double delta)
{
foreach (var handler in _movementHandlers)
{
handler.Move(delta);
}
2025-02-18 17:40:33 +01:00
foreach (var handler in _animationHandlers)
{
handler.Update(delta);
}
2025-02-17 21:53:05 +01:00
}
}