Partial Completion of Tutorial
This commit is contained in:
parent
0bee2ee47b
commit
cd0f25c73b
6 changed files with 517 additions and 6 deletions
|
|
@ -13,17 +13,20 @@ public partial class CharacterMovement : Node
|
|||
[ExportCategory("Nodes")]
|
||||
[Export] public CharacterBody2D Character;
|
||||
[Export] public CharacterInput CharacterInput;
|
||||
[Export] public CharacterCollisionRayCast CharacterCollisionRayCast;
|
||||
|
||||
[ExportCategory("Movement")]
|
||||
[Export] public Vector2 TargetPosition = Vector2.Zero;
|
||||
[Export] public bool IsWalking = false;
|
||||
[Export] public bool CollisionDetected = false;
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
CharacterInput.Walk += StartWalking;
|
||||
CharacterInput.Turn += Turn;
|
||||
Logger.Info("Loading player movement component ...");
|
||||
CharacterCollisionRayCast.Collision += (value) => CollisionDetected = value;
|
||||
Logger.Info("Loading character movement component ...");
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
|
|
@ -33,9 +36,11 @@ public partial class CharacterMovement : Node
|
|||
|
||||
public bool IsMoving() => IsWalking;
|
||||
|
||||
public bool IsColliding() => CollisionDetected;
|
||||
|
||||
public void StartWalking()
|
||||
{
|
||||
if (!IsMoving())
|
||||
if (!IsMoving() && !IsColliding())
|
||||
{
|
||||
EmitSignal(SignalName.Animation, "walk");
|
||||
TargetPosition = Character.Position + CharacterInput.Direction * Globals.Instance.GRID_SIZE;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue