43 lines
1004 B
C#
43 lines
1004 B
C#
using DaggerFramework;
|
|
using DaggerFramework.Extensions;
|
|
using DaggerFramework.SceneGraph;
|
|
using DaggerFramework.Utils;
|
|
|
|
public class TestPlayer : RectangleShape2d
|
|
{
|
|
protected override void OnStart()
|
|
{
|
|
base.OnStart();
|
|
Color = Color.Cyan;
|
|
|
|
_camera = new Camera2d()
|
|
{
|
|
Current = true,
|
|
};
|
|
|
|
if (Layer is not null)
|
|
{
|
|
Layer.AddEntity(_camera);
|
|
}
|
|
}
|
|
|
|
protected override void OnUpdate(double dt)
|
|
{
|
|
base.OnUpdate(dt);
|
|
|
|
var sprinting = Input.IsActionDown("sprint");
|
|
_speed = sprinting ? 400f : 200f;
|
|
|
|
var velocity = Input.GetInputDirection("left", "right", "up", "down") * _speed;
|
|
Position += velocity * (float)dt;
|
|
|
|
if (_camera is not null)
|
|
{
|
|
_camera.Position = _camera.Position.Lerp(Position, dt * 5f);
|
|
}
|
|
}
|
|
|
|
private Logger _logger = new(nameof(TestPlayer));
|
|
private float _speed = 200f;
|
|
private Camera2d? _camera;
|
|
} |