birb stab

This commit is contained in:
Lilith Schier 2026-06-08 21:53:05 +02:00
parent 00b76b6b25
commit 96bec5a6b7
11 changed files with 309 additions and 120 deletions

View file

@ -2,10 +2,6 @@ using System.Collections.Generic;
namespace Dancer;
using Godot;
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
[Meta(typeof(IAutoNode))]
public sealed partial class Player : CharacterBody2D
{
@ -14,20 +10,23 @@ public sealed partial class Player : CharacterBody2D
[Export(PropertyHint.None, "suffix:s")]
public float MaxInputBufferTime { get; set; } = 0.15f;
/// <summary>
/// The speed decay used when the player continues movement in the direction they're going.
/// </summary>
[Export(PropertyHint.None, "suffix:s⁻¹")]
public float GroundedSpeedDecay { get; set; } = 0.1f;
public float GroundedSpeedDecay { get; set; } = 0.3f;
[Export(PropertyHint.None, "suffix:s⁻¹")]
public float GroundedSpeedStopDecay { get; set; } = 0.005f;
[Export(PropertyHint.None, "suffix:px/s")]
public float WalkMaxSpeed { get; set; } = 130.0f;
public float WalkMaxSpeed { get; set; } = 110.0f;
[Export(PropertyHint.None, "suffix:px/s²")]
public float WalkAccel { get; set; } = 600.0f;
[Export(PropertyHint.None, "suffix:px/s²")]
public float AirAccel { get; set; } = 200.0f;
public float AirAccel { get; set; } = 180.0f;
[Export(PropertyHint.None, "suffix:s")]
public float JumpAscentMaxTime { get; set; } = 0.2f;
@ -100,6 +99,8 @@ public sealed partial class Player : CharacterBody2D
public override void _PhysicsProcess(double delta)
{
var deltaF = (float)delta;
// Temporary copy of the velocity for easier editing.
var velocity = Velocity;
if (_currentDirection.X < 0)
_isFacingRight = false;
@ -109,48 +110,49 @@ public sealed partial class Player : CharacterBody2D
// Walking on the floor
if (IsOnFloor())
{
if (Mathf.Sign(Velocity.X) != Mathf.Sign(_currentDirection.X))
Velocity = Velocity with { X = Velocity.X * Mathf.Pow(GroundedSpeedStopDecay, deltaF) };
if (Mathf.Sign(velocity.X) != Mathf.Sign(_currentDirection.X))
velocity.X *= Mathf.Pow(GroundedSpeedStopDecay, deltaF);
else
Velocity = Velocity with { X = Velocity.X * Mathf.Pow(GroundedSpeedDecay, deltaF) };
velocity.X *= Mathf.Pow(GroundedSpeedDecay, deltaF);
var targetVelX = Mathf.Sign(_currentDirection.X) * WalkMaxSpeed;
var isWalking = targetVelX != 0;
if (!isWalking || Mathf.Abs(Velocity.X) < WalkMaxSpeed)
if (!isWalking || Mathf.Abs(velocity.X) < WalkMaxSpeed)
{
Velocity = Velocity with
{
X = Mathf.MoveToward(Velocity.X, targetVelX, WalkAccel * deltaF)
};
velocity.X = Mathf.MoveToward(velocity.X, targetVelX, WalkAccel * deltaF);
}
}
// Air control
else
{
Velocity = Velocity with { X = Velocity.X + _currentDirection.X * AirAccel * deltaF };
velocity.X += _currentDirection.X * AirAccel * deltaF;
}
// Move up while holding jump
if (_jumpAscentRemainingTime > 0)
{
Velocity = Velocity with { Y = -JumpAscentSpeed };
velocity.Y = -JumpAscentSpeed;
_jumpAscentRemainingTime -= deltaF;
if (_jumpAscentRemainingTime < 0)
Velocity += GetGravity() * -_jumpAscentRemainingTime;
velocity += GetGravity() * -_jumpAscentRemainingTime;
}
else if (!IsOnFloor())
{
Velocity += GetGravity() * deltaF;
velocity += GetGravity() * deltaF;
}
// Drag while in air
if (!IsOnFloor() && _jumpAscentRemainingTime <= 0)
velocity += Physics.DragForce(-velocity) * deltaF;
if (IsHoldingWall())
{
var dragForce = -0.01f * Velocity * Velocity.Abs();
Velocity += dragForce * deltaF;
velocity.Y = Mathf.Min(velocity.Y, 5.0f);
_isFacingRight = Mathf.Sign(GetWallNormal().X) > 0;
}
Velocity = velocity;
MoveAndSlide();
_jumpAllowedTime = Mathf.Max(0, _jumpAllowedTime - deltaF);
@ -162,12 +164,6 @@ public sealed partial class Player : CharacterBody2D
_isJumping = false;
_jumpAscentRemainingTime = 0.0f;
}
if (IsHoldingWall())
{
Velocity = Velocity with { Y = Mathf.Min(5.0f, Velocity.Y) };
_isFacingRight = Mathf.Sign(GetWallNormal().X) > 0;
}
}
private bool IsHoldingWall()
@ -262,10 +258,7 @@ public sealed partial class Player : CharacterBody2D
private void Slash()
{
Velocity = Velocity with
{
X = Velocity.X + (_isFacingRight ? 1 : -1) * SlashSpeedBoost
};
Velocity += (_isFacingRight ? Vector2.Right : Vector2.Left) * SlashSpeedBoost;
_playback.Travel("attack");
var instance = GD.Load<PackedScene>("res://src/player/slash_projectile.tscn")
@ -287,7 +280,7 @@ public sealed partial class Player : CharacterBody2D
{
Attacker = this,
Damage = 1.0f,
Impulse = Vector2.Down * 5000.0f + (enemy.Position - Position).Normalized() * 5000.0f
Impulse = Vector2.Down * 1000.0f + (enemy.Position - Position).Normalized() * 1000.0f
});
}