added enemy attack
This commit is contained in:
parent
96bec5a6b7
commit
562a33bd8e
54 changed files with 1950 additions and 48 deletions
|
|
@ -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; }
|
||||
|
|
|
|||
19
src/player/PlayerHealthBar.cs
Normal file
19
src/player/PlayerHealthBar.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
namespace Dancer;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public sealed partial class PlayerHealthBar : ProgressBar
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Export] private Player Player { get; set; } = null!;
|
||||
|
||||
public void OnReady() => SetProcess(true);
|
||||
|
||||
public void OnProcess(double delta)
|
||||
{
|
||||
MinValue = 0;
|
||||
MaxValue = Player.MaxHealth;
|
||||
Value = Player.Health;
|
||||
}
|
||||
}
|
||||
|
||||
1
src/player/PlayerHealthBar.cs.uid
Normal file
1
src/player/PlayerHealthBar.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://i5v0sfow12sr
|
||||
|
|
@ -174,6 +174,7 @@ position = Vector2(0, 1)
|
|||
shape = SubResource("CapsuleShape2D_e2o6t")
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="." unique_id=1975474809]
|
||||
process_callback = 0
|
||||
limit_enabled = false
|
||||
|
||||
[node name="Body" type="Sprite2D" parent="." unique_id=567060128]
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
class_name SlashProjectile extends Node2D
|
||||
|
||||
signal hitbox_entered(other: Node2D)
|
||||
|
||||
func _on_attack_finished() -> void:
|
||||
queue_free()
|
||||
|
||||
func _on_hitbox_body_entered(body: Node2D) -> void:
|
||||
hitbox_entered.emit(body)
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://uwfp4ytugp51
|
||||
Loading…
Add table
Add a link
Reference in a new issue