new player art

This commit is contained in:
Lilith Schier 2026-06-19 00:35:46 +02:00
parent 562a33bd8e
commit f774f8e8a4
65 changed files with 2953 additions and 276 deletions

View file

@ -1,10 +1,9 @@
using System.Collections.Generic;
using System.Text;
namespace Dancer;
[Meta(typeof(IAutoNode))]
public sealed partial class Player : CharacterBody2D, IAttackable
public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner, IProvide<IHitboxOwner>
{
public override void _Notification(int what) => this.Notify(what);
@ -21,13 +20,13 @@ public sealed partial class Player : CharacterBody2D, IAttackable
public float GroundedSpeedStopDecay { get; set; } = 0.005f;
[Export(PropertyHint.None, "suffix:px/s")]
public float WalkMaxSpeed { get; set; } = 110.0f;
public float WalkMaxSpeed { get; set; } = 130.0f;
[Export(PropertyHint.None, "suffix:px/s²")]
public float WalkAccel { get; set; } = 600.0f;
public float WalkAccel { get; set; } = 900.0f;
[Export(PropertyHint.None, "suffix:px/s²")]
public float AirAccel { get; set; } = 180.0f;
public float AirAccel { get; set; } = 210.0f;
[Export(PropertyHint.None, "suffix:s")]
public float JumpAscentMaxTime { get; set; } = 0.2f;
@ -50,23 +49,24 @@ public sealed partial class Player : CharacterBody2D, IAttackable
public float DownInputAngle { get; set; } = Mathf.Pi / 4;
[Export] public float MaxHealth { get; set; } = 5f;
public float Health { get; set; }
[Export] public float Health { get; set; }
[Export] public bool CanTurn { get; set; } = true;
private ulong MaxInputBufferTimeMicroseconds => (ulong)(MaxInputBufferTime * 1_000_000);
private float _jumpAscentRemainingTime;
private bool _isJumping;
private float _jumpAllowedTime;
private Vector2 _currentDirection = Vector2.Zero;
private bool _isFacingRight = true;
private AnimationNodeStateMachinePlayback _playback = null!;
private List<BufferedInput> _inputBuffer = [];
[Node] private AnimationTree AnimationTree { get; set; } = null!;
public override void _Ready()
public void OnReady()
{
this.Provide();
SetPhysicsProcess(true);
Health = MaxHealth;
_playback = AnimationTree.Get("parameters/playback").As<AnimationNodeStateMachinePlayback>();
}
@ -101,16 +101,13 @@ public sealed partial class Player : CharacterBody2D, IAttackable
}
}
public override void _PhysicsProcess(double delta)
public void OnPhysicsProcess(double delta)
{
var deltaF = (float)delta;
// Temporary copy of the velocity for easier editing.
var velocity = Velocity;
if (_currentDirection.X < 0)
_isFacingRight = false;
else if (_currentDirection.X > 0)
_isFacingRight = true;
if (CanTurn) AdjustFacing();
// Walking on the floor
if (IsOnFloor())
@ -171,6 +168,14 @@ public sealed partial class Player : CharacterBody2D, IAttackable
}
}
private void AdjustFacing()
{
if (_currentDirection.X < 0)
_isFacingRight = false;
else if (_currentDirection.X > 0)
_isFacingRight = true;
}
private bool IsHoldingWall()
{
return
@ -199,15 +204,6 @@ public sealed partial class Player : CharacterBody2D, IAttackable
_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++)
{
@ -236,7 +232,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable
else if (input.Event.IsActionPressed("attack"))
{
inputFound = true;
Slash();
Attack();
}
if (inputFound)
@ -249,6 +245,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable
private void GroundJump()
{
AdjustFacing();
_jumpAllowedTime = 0.0f;
_jumpAscentRemainingTime = JumpAscentMaxTime;
_isJumping = true;
@ -256,6 +253,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable
private void WallJump()
{
AdjustFacing();
_jumpAllowedTime = 0.0f;
Velocity += GetWallNormal() * 200.0f;
Velocity = Velocity with { Y = Mathf.Min(0, Velocity.Y) };
@ -270,16 +268,11 @@ public sealed partial class Player : CharacterBody2D, IAttackable
Velocity = Velocity with { Y = Velocity.Y * 0.1f };
}
private void Slash()
private void Attack()
{
AdjustFacing();
Velocity += (_isFacingRight ? Vector2.Right : Vector2.Left) * SlashSpeedBoost;
_playback.Travel("attack");
var instance = GD.Load<PackedScene>("res://src/player/slash_projectile.tscn")
.Instantiate<SlashProjectile>();
AddChild(instance);
instance.GlobalTransform = GetNode<Node2D>("%HandAttachment").GlobalTransform;
instance.HitboxEntered += OnEnemyHit;
_playback.Travel("front_kick");
}
private bool IsInputVecDown(Vector2 vec)
@ -287,14 +280,14 @@ public sealed partial class Player : CharacterBody2D, IAttackable
return Mathf.Abs(vec.AngleTo(Vector2.Down)) < DownInputAngle && vec.Length() > 0.1f;
}
private void OnEnemyHit(Node2D enemy)
private void OnEnemyHit(Hitbox hitbox, Node2D enemy)
{
if (enemy is not IAttackable attackable) return;
attackable.GetAttacked(new()
{
Attacker = this,
Damage = 1.0f,
Impulse = Vector2.Down * 1000.0f + (enemy.Position - Position).Normalized() * 1000.0f,
Impulse = Vector2.Up * 1000.0f + (enemy.Position - Position).Normalized() * 1000.0f,
});
}
@ -309,4 +302,8 @@ public sealed partial class Player : CharacterBody2D, IAttackable
public required InputEvent Event { get; init; }
public ulong Time { get; init; }
}
public void OnHitboxAdded(Hitbox hitbox) => hitbox.BodyHit += OnEnemyHit;
public void OnHitboxRemoved(Hitbox hitbox) => hitbox.BodyHit -= OnEnemyHit;
IHitboxOwner IProvide<IHitboxOwner>.Value() => this;
}