added enemy attack

This commit is contained in:
Lilith Schier 2026-06-13 16:07:00 +02:00
parent 96bec5a6b7
commit 562a33bd8e
54 changed files with 1950 additions and 48 deletions

View file

@ -1,9 +1,10 @@
using System.Collections.Generic;
using System.Text;
namespace Dancer;
[Meta(typeof(IAutoNode))]
public sealed partial class Player : CharacterBody2D
public sealed partial class Player : CharacterBody2D, IAttackable
{
public override void _Notification(int what) => this.Notify(what);
@ -48,6 +49,9 @@ public sealed partial class Player : CharacterBody2D
[Export(PropertyHint.Range, "0,360,0.1,radians_as_degrees")]
public float DownInputAngle { get; set; } = Mathf.Pi / 4;
[Export] public float MaxHealth { get; set; } = 5f;
public float Health { get; set; }
private ulong MaxInputBufferTimeMicroseconds => (ulong)(MaxInputBufferTime * 1_000_000);
private float _jumpAscentRemainingTime;
@ -63,6 +67,7 @@ public sealed partial class Player : CharacterBody2D
public override void _Ready()
{
Health = MaxHealth;
_playback = AnimationTree.Get("parameters/playback").As<AnimationNodeStateMachinePlayback>();
}
@ -90,7 +95,7 @@ public sealed partial class Player : CharacterBody2D
{
Direction = _currentDirection,
Event = @event,
Time = Time.GetTicksUsec()
Time = Time.GetTicksUsec(),
});
HandleBufferedInputs();
}
@ -194,6 +199,15 @@ public sealed partial class Player : CharacterBody2D
_inputBuffer.RemoveAt(0);
}
{
var inputBuffer = new StringBuilder();
foreach (var bufferedInput in _inputBuffer)
{
inputBuffer.Append($"{bufferedInput}, ");
}
GD.Print(inputBuffer);
}
// Check new commands
for (var i = 0; i < _inputBuffer.Count; i++)
{
@ -280,10 +294,15 @@ public sealed partial class Player : CharacterBody2D
{
Attacker = this,
Damage = 1.0f,
Impulse = Vector2.Down * 1000.0f + (enemy.Position - Position).Normalized() * 1000.0f
Impulse = Vector2.Down * 1000.0f + (enemy.Position - Position).Normalized() * 1000.0f,
});
}
public void GetAttacked(in Attack attack)
{
Health -= attack.Damage;
}
public class BufferedInput
{
public Vector2 Direction { get; init; }