SupaLidlGame/Characters/Character.cs

50 lines
1.3 KiB
C#
Raw Normal View History

2022-11-10 20:29:53 -08:00
using Godot;
namespace SupaLidlGame.Characters
{
public partial class Character : CharacterBody2D
{
2022-11-12 16:45:04 -08:00
[Export]
2022-11-10 20:29:53 -08:00
public float Speed { get; protected set; } = 128.0f;
2022-11-12 16:45:04 -08:00
2022-11-10 20:29:53 -08:00
public float JumpVelocity { get; protected set; } = -400.0f;
public float AccelerationMagnitude { get; protected set; } = 256.0f;
public Vector2 Acceleration => Direction * AccelerationMagnitude;
// Get the gravity from the project settings to be synced with RigidBody nodes.
public float Gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle();
2022-11-13 15:42:04 -08:00
public Vector2 Direction { get; set; } = Vector2.Zero;
public Vector2 Target { get; set; } = Vector2.Zero;
[Export]
public State.Machine StateMachine { get; set; }
2022-11-10 20:29:53 -08:00
public override void _Process(double delta)
{
2022-11-13 15:42:04 -08:00
if (StateMachine != null)
{
StateMachine.Process(delta);
}
}
public override void _Input(InputEvent @event)
{
if (StateMachine != null)
{
StateMachine.Input(@event);
}
2022-11-10 20:29:53 -08:00
}
public override void _PhysicsProcess(double delta)
{
2022-11-13 15:42:04 -08:00
if (StateMachine != null)
{
StateMachine.PhysicsProcess(delta);
}
2022-11-10 20:29:53 -08:00
}
}
}