mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-17 08:33:47 +00:00
Actor stub
This commit is contained in:
parent
237a59055b
commit
a1bbe63b66
4 changed files with 73 additions and 1 deletions
38
Scripts/Components/Actors/Actor.cs
Normal file
38
Scripts/Components/Actors/Actor.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
23
Scripts/Components/Actors/ActorFreeMovement.cs
Normal file
23
Scripts/Components/Actors/ActorFreeMovement.cs
Normal 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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
11
Scripts/Components/Actors/MovementHandler.cs
Normal file
11
Scripts/Components/Actors/MovementHandler.cs
Normal 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);
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue