birb stab
This commit is contained in:
parent
00b76b6b25
commit
96bec5a6b7
11 changed files with 309 additions and 120 deletions
|
|
@ -7,6 +7,7 @@
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Ccombat/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Ccombat/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Ccreatures/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Ccreatures/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Ccreatures_005Cbirb/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Ccreatures_005Cbirb/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Cphysics/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Cplayer/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Cplayer/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Crescaler/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Crescaler/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Cspring/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Cspring/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||||
49
export_presets.cfg
Normal file
49
export_presets.cfg
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
[preset.0]
|
||||||
|
|
||||||
|
name="Linux"
|
||||||
|
platform="Linux"
|
||||||
|
runnable=true
|
||||||
|
dedicated_server=false
|
||||||
|
custom_features=""
|
||||||
|
export_filter="all_resources"
|
||||||
|
include_filter=""
|
||||||
|
exclude_filter=""
|
||||||
|
export_path="../../Desktop/export/Dancer.x86_64"
|
||||||
|
patches=PackedStringArray()
|
||||||
|
patch_delta_encoding=false
|
||||||
|
patch_delta_compression_level_zstd=19
|
||||||
|
patch_delta_min_reduction=0.1
|
||||||
|
patch_delta_include_filters="*"
|
||||||
|
patch_delta_exclude_filters=""
|
||||||
|
encryption_include_filters=""
|
||||||
|
encryption_exclude_filters=""
|
||||||
|
seed=0
|
||||||
|
encrypt_pck=false
|
||||||
|
encrypt_directory=false
|
||||||
|
script_export_mode=2
|
||||||
|
|
||||||
|
[preset.0.options]
|
||||||
|
|
||||||
|
custom_template/debug=""
|
||||||
|
custom_template/release=""
|
||||||
|
debug/export_console_wrapper=1
|
||||||
|
binary_format/embed_pck=true
|
||||||
|
texture_format/s3tc_bptc=true
|
||||||
|
texture_format/etc2_astc=false
|
||||||
|
shader_baker/enabled=false
|
||||||
|
binary_format/architecture="x86_64"
|
||||||
|
ssh_remote_deploy/enabled=false
|
||||||
|
ssh_remote_deploy/host="user@host_ip"
|
||||||
|
ssh_remote_deploy/port="22"
|
||||||
|
ssh_remote_deploy/extra_args_ssh=""
|
||||||
|
ssh_remote_deploy/extra_args_scp=""
|
||||||
|
ssh_remote_deploy/run_script="#!/usr/bin/env bash
|
||||||
|
export DISPLAY=:0
|
||||||
|
unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\"
|
||||||
|
\"{temp_dir}/{exe_name}\" {cmd_args}"
|
||||||
|
ssh_remote_deploy/cleanup_script="#!/usr/bin/env bash
|
||||||
|
pkill -x -f \"{temp_dir}/{exe_name} {cmd_args}\"
|
||||||
|
rm -rf \"{temp_dir}\""
|
||||||
|
dotnet/include_scripts_content=false
|
||||||
|
dotnet/include_debug_symbols=true
|
||||||
|
dotnet/embed_build_outputs=false
|
||||||
|
|
@ -88,8 +88,10 @@ attack={
|
||||||
|
|
||||||
2d/run_on_separate_thread=true
|
2d/run_on_separate_thread=true
|
||||||
common/physics_ticks_per_second=120
|
common/physics_ticks_per_second=120
|
||||||
|
common/physics_jitter_fix=0.0
|
||||||
3d/physics_engine="Dummy"
|
3d/physics_engine="Dummy"
|
||||||
2d/default_gravity=480.0
|
2d/default_gravity=480.0
|
||||||
|
common/physics_interpolation=true
|
||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,51 +9,62 @@ public sealed partial class Birb : CharacterBody2D, IAttackable
|
||||||
{
|
{
|
||||||
public override void _Notification(int what) => this.Notify(what);
|
public override void _Notification(int what) => this.Notify(what);
|
||||||
|
|
||||||
[Export] public float Speed { get; set; } = 60f;
|
[Export] public float Speed { get; set; } = 90f;
|
||||||
[Export] public float AttackDistance { get; set; } = 32f;
|
[Export] public float AttackDistance { get; set; } = 30f;
|
||||||
[Export] public float ThinkTime { get; set; } = 0.2f;
|
|
||||||
[Export] public float Weight { get; set; } = 20f;
|
[Export] public float Weight { get; set; } = 20f;
|
||||||
[Export] public float MaxHp { get; set; } = 4f;
|
[Export] public float MaxHp { get; set; } = 4f;
|
||||||
|
[Export] public float Acceleration { get; set; } = 700f;
|
||||||
|
|
||||||
[Node] private ProgressBar HealthBar { get; set; } = null!;
|
[Node] private ProgressBar HealthBar { get; set; } = null!;
|
||||||
[Node] private AnimatedSprite2D BodySprite { get; set; } = null!;
|
[Node] private AnimatedSprite2D Body { get; set; } = null!;
|
||||||
|
[Node] private AnimationPlayer AnimationPlayer { get; set; } = null!;
|
||||||
|
|
||||||
private float _hp;
|
private float _hp;
|
||||||
private float _timeThought;
|
|
||||||
private Node2D? _target;
|
|
||||||
private float _targetVelocity;
|
|
||||||
|
|
||||||
public override void _Ready()
|
private Logic Ai { get; set; } = null!;
|
||||||
|
|
||||||
|
public void Initialize()
|
||||||
{
|
{
|
||||||
_hp = MaxHp;
|
_hp = MaxHp;
|
||||||
HealthBar.MinValue = 0f;
|
HealthBar.MinValue = 0f;
|
||||||
HealthBar.MaxValue = MaxHp;
|
HealthBar.MaxValue = MaxHp;
|
||||||
|
Ai = new();
|
||||||
|
Ai.Set(this);
|
||||||
|
Ai.Start<Logic.Root.Idle>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public void OnReady()
|
||||||
{
|
{
|
||||||
_timeThought += (float)delta;
|
SetPhysicsProcess(true);
|
||||||
if (_timeThought >= ThinkTime)
|
SetProcess(true);
|
||||||
{
|
|
||||||
_timeThought -= ThinkTime;
|
|
||||||
if (_target is not null)
|
|
||||||
{
|
|
||||||
var xDifference = _target.Position.X - Position.X;
|
|
||||||
var distance = Mathf.Abs(xDifference);
|
|
||||||
if (Mathf.Abs(distance - AttackDistance) > Speed * ThinkTime)
|
|
||||||
_targetVelocity = Mathf.Sign(xDifference) * Mathf.Sign(distance - AttackDistance) * Speed;
|
|
||||||
else
|
|
||||||
_targetVelocity = 0f;
|
|
||||||
BodySprite.FlipH = xDifference < 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
_targetVelocity = 0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Velocity = Velocity with
|
public void OnPhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
X = Mathf.MoveToward(Velocity.X, _targetVelocity, (float)delta * 500f)
|
// _timeThought += (float)delta;
|
||||||
};
|
// if (_timeThought >= ThinkTime)
|
||||||
|
// {
|
||||||
|
// _timeThought -= ThinkTime;
|
||||||
|
// if (_target is not null)
|
||||||
|
// {
|
||||||
|
// var xDifference = _target.Position.X - Position.X;
|
||||||
|
// var distance = Mathf.Abs(xDifference);
|
||||||
|
// if (Mathf.Abs(distance - AttackDistance) > Speed * ThinkTime)
|
||||||
|
// _targetVelocity = Mathf.Sign(xDifference) * Mathf.Sign(distance - AttackDistance) * Speed;
|
||||||
|
// else
|
||||||
|
// _targetVelocity = 0f;
|
||||||
|
// BodySprite.FlipH = xDifference < 0;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// _targetVelocity = 0f;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Velocity = Velocity with
|
||||||
|
// {
|
||||||
|
// X = Mathf.MoveToward(Velocity.X, _targetVelocity, (float)delta * 500f)
|
||||||
|
// };
|
||||||
|
|
||||||
|
Ai.Input(new Logic.Input.OnPhysicsProcess(delta));
|
||||||
|
|
||||||
if (!IsOnFloor()) Velocity += GetGravity() * (float)delta;
|
if (!IsOnFloor()) Velocity += GetGravity() * (float)delta;
|
||||||
|
|
||||||
|
|
@ -66,13 +77,44 @@ public sealed partial class Birb : CharacterBody2D, IAttackable
|
||||||
HealthBar.Visible = _hp < MaxHp;
|
HealthBar.Visible = _hp < MaxHp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnDetectionBodyEntered(Node2D body) => _target = body;
|
/// <summary>
|
||||||
|
///
|
||||||
public void OnChaseBodyExited(Node2D body)
|
/// </summary>
|
||||||
|
/// <param name="delta"></param>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns>If the goal will be reached this tick or not.</returns>
|
||||||
|
public bool WalkToward(double delta, Vector2 pos)
|
||||||
{
|
{
|
||||||
if (body == _target) _target = null;
|
var xDifference = pos.X - GlobalPosition.X;
|
||||||
|
var distance = Mathf.Abs(xDifference);
|
||||||
|
var breakableSpeed = Mathf.Sqrt(2 * Acceleration * distance);
|
||||||
|
var speedRequiredToReachGoalNow = distance / (float)delta;
|
||||||
|
var speed = Mathf.Min(Speed, Mathf.Min(speedRequiredToReachGoalNow, breakableSpeed));
|
||||||
|
var targetVelocity = Mathf.Sign(xDifference) * speed;
|
||||||
|
Velocity = Velocity with
|
||||||
|
{
|
||||||
|
X = Mathf.MoveToward(Velocity.X, targetVelocity, (float)delta * Acceleration)
|
||||||
|
};
|
||||||
|
return speedRequiredToReachGoalNow < Speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Stop(double delta)
|
||||||
|
{
|
||||||
|
Velocity = Velocity with
|
||||||
|
{
|
||||||
|
X = Mathf.MoveToward(Velocity.X, 0, (float)delta * Acceleration)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void FaceToward(Vector2 pos)
|
||||||
|
{
|
||||||
|
Body.Scale = new(pos.X > GlobalPosition.X ? 1 : -1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnDetectionBodyEntered(Node2D body) => Ai.Input(new Logic.Input.TargetFound(body));
|
||||||
|
public void OnChaseBodyExited(Node2D body) => Ai.Input(new Logic.Input.TargetLost(body));
|
||||||
|
public void OnAttackFinished() => Ai.Input(new Logic.Input.AttackFinished());
|
||||||
|
|
||||||
public void GetAttacked(in Attack attack)
|
public void GetAttacked(in Attack attack)
|
||||||
{
|
{
|
||||||
_hp -= attack.Damage;
|
_hp -= attack.Damage;
|
||||||
|
|
@ -85,84 +127,143 @@ public sealed partial class Birb : CharacterBody2D, IAttackable
|
||||||
{
|
{
|
||||||
public sealed record Data
|
public sealed record Data
|
||||||
{
|
{
|
||||||
public required Birb Birb { get; set; }
|
|
||||||
public float DurationLeft { get; set; }
|
public float DurationLeft { get; set; }
|
||||||
public Node2D? Target { get; set; }
|
public Node2D? Target { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Logic(Birb birb)
|
public Logic()
|
||||||
{
|
{
|
||||||
Set(new Data { Birb = birb });
|
Set(new Data());
|
||||||
Preallocate<Root>();
|
Preallocate<Root>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Input
|
public static class Input
|
||||||
{
|
{
|
||||||
public readonly record struct TimerFinished;
|
public readonly record struct AttackFinished;
|
||||||
|
|
||||||
|
public readonly record struct TargetFound(Node2D Target);
|
||||||
|
|
||||||
|
public readonly record struct TargetLost(Node2D Target);
|
||||||
|
|
||||||
|
public readonly record struct OnPhysicsProcess(double Delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Meta, StateDiagram]
|
[Meta, StateDiagram]
|
||||||
public abstract partial record Root : LogicBlockState
|
public abstract partial record Root : LogicBlockState
|
||||||
{
|
{
|
||||||
public virtual void OnPhysicsProcess(double delta)
|
[Meta]
|
||||||
|
public sealed partial record Idle : Root, IGet<Input.TargetFound>, IGet<Input.OnPhysicsProcess>
|
||||||
{
|
{
|
||||||
|
public Idle()
|
||||||
|
{
|
||||||
|
this.OnEnter(() => { Get<Birb>().AnimationPlayer.Play("idle"); });
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type On(in Input.TargetFound input)
|
||||||
|
{
|
||||||
|
Get<Data>().Target = input.Target;
|
||||||
|
return To<Fight.Think>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type On(in Input.OnPhysicsProcess input)
|
||||||
|
{
|
||||||
|
Get<Birb>().Stop(input.Delta);
|
||||||
|
return ToSelf();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Meta]
|
[Meta]
|
||||||
public sealed partial record Idle : Root;
|
public abstract partial record Fight : Root, IGet<Input.TargetLost>
|
||||||
|
{
|
||||||
|
public Type On(in Input.TargetLost input)
|
||||||
|
{
|
||||||
|
var data = Get<Data>();
|
||||||
|
if (input.Target != data.Target) return ToSelf();
|
||||||
|
data.Target = null;
|
||||||
|
return To<Idle>();
|
||||||
|
}
|
||||||
|
|
||||||
[Meta]
|
[Meta]
|
||||||
public abstract partial record Fight : Root
|
public sealed partial record Think : Fight, IGet<Input.OnPhysicsProcess>
|
||||||
{
|
|
||||||
[Meta]
|
|
||||||
public sealed partial record Think : Fight, IGet<Input.TimerFinished>
|
|
||||||
{
|
{
|
||||||
public Think()
|
public Think()
|
||||||
{
|
{
|
||||||
this.OnEnter(() => Get<Data>().DurationLeft = (float)GD.RandRange(0.3, 0.6));
|
this.OnEnter(() =>
|
||||||
|
{
|
||||||
|
Get<Data>().DurationLeft = (float)GD.RandRange(0f, 0.4f);
|
||||||
|
Get<Birb>().AnimationPlayer.Play("idle");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnPhysicsProcess(double delta)
|
public Type On(in Input.OnPhysicsProcess input)
|
||||||
{
|
{
|
||||||
var data = Get<Data>();
|
var data = Get<Data>();
|
||||||
data.DurationLeft -= (float)delta;
|
var birb = Get<Birb>();
|
||||||
if (data.DurationLeft <= 0f) Input(new Input.TimerFinished());
|
data.DurationLeft -= (float)input.Delta;
|
||||||
}
|
if (data.DurationLeft > 0f) return ToSelf();
|
||||||
|
|
||||||
public Type On(in Input.TimerFinished input)
|
birb.FaceToward(data.Target!.GlobalPosition);
|
||||||
{
|
birb.Stop(input.Delta);
|
||||||
var data = Get<Data>();
|
return data.Target!.GlobalPosition.DistanceTo(birb.GlobalPosition) < birb.AttackDistance
|
||||||
if (data.Target is not { } target) return To<Idle>();
|
|
||||||
return target.GlobalPosition.DistanceTo(data.Birb.GlobalPosition) <
|
|
||||||
data.Birb.AttackDistance
|
|
||||||
? To<PrepareStrike>()
|
? To<PrepareStrike>()
|
||||||
: To<StepToPosition>();
|
: To<StepToPosition>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Meta]
|
[Meta]
|
||||||
public sealed partial record StepToPosition : Fight;
|
public sealed partial record StepToPosition : Fight, IGet<Input.OnPhysicsProcess>
|
||||||
|
{
|
||||||
|
public Type On(in Input.OnPhysicsProcess input)
|
||||||
|
{
|
||||||
|
var birb = Get<Birb>();
|
||||||
|
var data = Get<Data>();
|
||||||
|
birb.FaceToward(data.Target!.GlobalPosition);
|
||||||
|
|
||||||
|
var left = data.Target!.GlobalPosition + Vector2.Left * birb.AttackDistance;
|
||||||
|
var right = data.Target!.GlobalPosition + Vector2.Right * birb.AttackDistance;
|
||||||
|
var targetPosition =
|
||||||
|
birb.GlobalPosition.DistanceSquaredTo(left)
|
||||||
|
< birb.GlobalPosition.DistanceSquaredTo(right)
|
||||||
|
? left
|
||||||
|
: right;
|
||||||
|
return birb.WalkToward(input.Delta, targetPosition)
|
||||||
|
? To<Think>()
|
||||||
|
: ToSelf();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Meta]
|
[Meta]
|
||||||
public sealed partial record PrepareStrike : Fight, IGet<Input.TimerFinished>
|
public sealed partial record PrepareStrike : Fight, IGet<Input.OnPhysicsProcess>
|
||||||
{
|
{
|
||||||
public PrepareStrike()
|
public PrepareStrike()
|
||||||
{
|
{
|
||||||
this.OnEnter(() => Get<Data>().DurationLeft = (float)GD.RandRange(0.7, 0.9));
|
this.OnEnter(() =>
|
||||||
|
{
|
||||||
|
|
||||||
|
Get<Data>().DurationLeft = (float)GD.RandRange(0.1f, 0.7f);
|
||||||
|
Get<Birb>().AnimationPlayer.Play("prepare_attack");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnPhysicsProcess(double delta)
|
public Type On(in Input.OnPhysicsProcess input)
|
||||||
{
|
{
|
||||||
var data = Get<Data>();
|
var data = Get<Data>();
|
||||||
data.DurationLeft -= (float)delta;
|
var birb = Get<Birb>();
|
||||||
if (data.DurationLeft <= 0f) Input(new Input.TimerFinished());
|
if (data.Target!.GlobalPosition.DistanceTo(birb.GlobalPosition) >
|
||||||
|
birb.AttackDistance * 1.2) return To<Think>();
|
||||||
|
birb.FaceToward(data.Target!.GlobalPosition);
|
||||||
|
birb.Stop(input.Delta);
|
||||||
|
data.DurationLeft -= (float)input.Delta;
|
||||||
|
return data.DurationLeft > 0f ? ToSelf() : To<Stab>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type On(in Input.TimerFinished input) => To<Stab>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Meta]
|
[Meta]
|
||||||
public sealed partial record Stab : Fight;
|
public sealed partial record Stab : Fight, IGet<Input.AttackFinished>
|
||||||
|
{
|
||||||
|
public Stab() => this.OnEnter(() => Get<Birb>().AnimationPlayer.Play("stab"));
|
||||||
|
public Type On(in Input.AttackFinished input) => To<Think>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -11,7 +11,7 @@ height = 14.0
|
||||||
radius = 52.0
|
radius = 52.0
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_ba6cv"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_ba6cv"]
|
||||||
radius = 110.0
|
radius = 160.0
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_lyo8d"]
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_lyo8d"]
|
||||||
bg_color = Color(0.15, 0.15, 0.15, 0.34509805)
|
bg_color = Color(0.15, 0.15, 0.15, 0.34509805)
|
||||||
|
|
@ -25,7 +25,7 @@ step = 0.1
|
||||||
tracks/0/type = "value"
|
tracks/0/type = "value"
|
||||||
tracks/0/imported = false
|
tracks/0/imported = false
|
||||||
tracks/0/enabled = true
|
tracks/0/enabled = true
|
||||||
tracks/0/path = NodePath("BodySprite:animation")
|
tracks/0/path = NodePath("Body:animation")
|
||||||
tracks/0/interp = 1
|
tracks/0/interp = 1
|
||||||
tracks/0/loop_wrap = true
|
tracks/0/loop_wrap = true
|
||||||
tracks/0/keys = {
|
tracks/0/keys = {
|
||||||
|
|
@ -37,7 +37,7 @@ tracks/0/keys = {
|
||||||
tracks/1/type = "value"
|
tracks/1/type = "value"
|
||||||
tracks/1/imported = false
|
tracks/1/imported = false
|
||||||
tracks/1/enabled = true
|
tracks/1/enabled = true
|
||||||
tracks/1/path = NodePath("BodySprite:frame")
|
tracks/1/path = NodePath("Body:frame")
|
||||||
tracks/1/interp = 1
|
tracks/1/interp = 1
|
||||||
tracks/1/loop_wrap = true
|
tracks/1/loop_wrap = true
|
||||||
tracks/1/keys = {
|
tracks/1/keys = {
|
||||||
|
|
@ -54,7 +54,7 @@ step = 0.1
|
||||||
tracks/0/type = "value"
|
tracks/0/type = "value"
|
||||||
tracks/0/imported = false
|
tracks/0/imported = false
|
||||||
tracks/0/enabled = true
|
tracks/0/enabled = true
|
||||||
tracks/0/path = NodePath("BodySprite:animation")
|
tracks/0/path = NodePath("Body:animation")
|
||||||
tracks/0/interp = 1
|
tracks/0/interp = 1
|
||||||
tracks/0/loop_wrap = true
|
tracks/0/loop_wrap = true
|
||||||
tracks/0/keys = {
|
tracks/0/keys = {
|
||||||
|
|
@ -66,7 +66,7 @@ tracks/0/keys = {
|
||||||
tracks/1/type = "value"
|
tracks/1/type = "value"
|
||||||
tracks/1/imported = false
|
tracks/1/imported = false
|
||||||
tracks/1/enabled = true
|
tracks/1/enabled = true
|
||||||
tracks/1/path = NodePath("BodySprite:frame")
|
tracks/1/path = NodePath("Body:frame")
|
||||||
tracks/1/interp = 1
|
tracks/1/interp = 1
|
||||||
tracks/1/loop_wrap = true
|
tracks/1/loop_wrap = true
|
||||||
tracks/1/keys = {
|
tracks/1/keys = {
|
||||||
|
|
@ -82,7 +82,7 @@ step = 0.1
|
||||||
tracks/0/type = "value"
|
tracks/0/type = "value"
|
||||||
tracks/0/imported = false
|
tracks/0/imported = false
|
||||||
tracks/0/enabled = true
|
tracks/0/enabled = true
|
||||||
tracks/0/path = NodePath("BodySprite:animation")
|
tracks/0/path = NodePath("Body:animation")
|
||||||
tracks/0/interp = 1
|
tracks/0/interp = 1
|
||||||
tracks/0/loop_wrap = true
|
tracks/0/loop_wrap = true
|
||||||
tracks/0/keys = {
|
tracks/0/keys = {
|
||||||
|
|
@ -94,7 +94,7 @@ tracks/0/keys = {
|
||||||
tracks/1/type = "value"
|
tracks/1/type = "value"
|
||||||
tracks/1/imported = false
|
tracks/1/imported = false
|
||||||
tracks/1/enabled = true
|
tracks/1/enabled = true
|
||||||
tracks/1/path = NodePath("BodySprite:frame")
|
tracks/1/path = NodePath("Body:frame")
|
||||||
tracks/1/interp = 1
|
tracks/1/interp = 1
|
||||||
tracks/1/loop_wrap = true
|
tracks/1/loop_wrap = true
|
||||||
tracks/1/keys = {
|
tracks/1/keys = {
|
||||||
|
|
@ -106,11 +106,12 @@ tracks/1/keys = {
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_3ly8m"]
|
[sub_resource type="Animation" id="Animation_3ly8m"]
|
||||||
resource_name = "stab"
|
resource_name = "stab"
|
||||||
|
length = 0.9
|
||||||
step = 0.1
|
step = 0.1
|
||||||
tracks/0/type = "value"
|
tracks/0/type = "value"
|
||||||
tracks/0/imported = false
|
tracks/0/imported = false
|
||||||
tracks/0/enabled = true
|
tracks/0/enabled = true
|
||||||
tracks/0/path = NodePath("BodySprite:animation")
|
tracks/0/path = NodePath("Body:animation")
|
||||||
tracks/0/interp = 1
|
tracks/0/interp = 1
|
||||||
tracks/0/loop_wrap = true
|
tracks/0/loop_wrap = true
|
||||||
tracks/0/keys = {
|
tracks/0/keys = {
|
||||||
|
|
@ -122,14 +123,28 @@ tracks/0/keys = {
|
||||||
tracks/1/type = "value"
|
tracks/1/type = "value"
|
||||||
tracks/1/imported = false
|
tracks/1/imported = false
|
||||||
tracks/1/enabled = true
|
tracks/1/enabled = true
|
||||||
tracks/1/path = NodePath("BodySprite:frame")
|
tracks/1/path = NodePath("Body:frame")
|
||||||
tracks/1/interp = 1
|
tracks/1/interp = 1
|
||||||
tracks/1/loop_wrap = true
|
tracks/1/loop_wrap = true
|
||||||
tracks/1/keys = {
|
tracks/1/keys = {
|
||||||
"times": PackedFloat32Array(0),
|
"times": PackedFloat32Array(0, 0.1, 0.5),
|
||||||
"transitions": PackedFloat32Array(1),
|
"transitions": PackedFloat32Array(1, 1, 1),
|
||||||
"update": 1,
|
"update": 1,
|
||||||
"values": [0]
|
"values": [0, 1, 2]
|
||||||
|
}
|
||||||
|
tracks/2/type = "method"
|
||||||
|
tracks/2/imported = false
|
||||||
|
tracks/2/enabled = true
|
||||||
|
tracks/2/path = NodePath(".")
|
||||||
|
tracks/2/interp = 1
|
||||||
|
tracks/2/loop_wrap = true
|
||||||
|
tracks/2/keys = {
|
||||||
|
"times": PackedFloat32Array(0.9),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"values": [{
|
||||||
|
"args": [],
|
||||||
|
"method": &"OnAttackFinished"
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_1i6dk"]
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_1i6dk"]
|
||||||
|
|
@ -145,11 +160,11 @@ collision_layer = 4
|
||||||
script = ExtResource("1_lyo8d")
|
script = ExtResource("1_lyo8d")
|
||||||
metadata/_edit_group_ = true
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
[node name="BodySprite" type="AnimatedSprite2D" parent="." unique_id=581143480]
|
[node name="Body" type="AnimatedSprite2D" parent="." unique_id=581143480]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
position = Vector2(2, -4)
|
|
||||||
sprite_frames = ExtResource("2_ba6cv")
|
sprite_frames = ExtResource("2_ba6cv")
|
||||||
animation = &"idle"
|
animation = &"idle"
|
||||||
|
offset = Vector2(9, -4)
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1744954023]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1744954023]
|
||||||
position = Vector2(0, 1)
|
position = Vector2(0, 1)
|
||||||
|
|
@ -189,6 +204,7 @@ value = 50.0
|
||||||
show_percentage = false
|
show_percentage = false
|
||||||
|
|
||||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=695394949]
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=695394949]
|
||||||
|
unique_name_in_owner = true
|
||||||
libraries/ = SubResource("AnimationLibrary_1i6dk")
|
libraries/ = SubResource("AnimationLibrary_1i6dk")
|
||||||
|
|
||||||
[connection signal="body_entered" from="Detection" to="." method="OnDetectionBodyEntered"]
|
[connection signal="body_entered" from="Detection" to="." method="OnDetectionBodyEntered"]
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
25
src/physics/Physics.cs
Normal file
25
src/physics/Physics.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
namespace Dancer;
|
||||||
|
|
||||||
|
public static class Physics
|
||||||
|
{
|
||||||
|
public const float PixelsPerMeter = 8f;
|
||||||
|
public const float PixelsPerMeterSquared = PixelsPerMeter * PixelsPerMeter;
|
||||||
|
|
||||||
|
public static Vector2 DragForce(Vector2 flowVelocity, float dragAmount = 0.01f)
|
||||||
|
{
|
||||||
|
return flowVelocity * flowVelocity.Abs() * dragAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float DragAmount(float area = 1f, float dragCoefficient = 1.17f,
|
||||||
|
float fluidMassDensity = 1.2f / PixelsPerMeterSquared)
|
||||||
|
{
|
||||||
|
return 0.5f * fluidMassDensity * area * dragCoefficient;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Extensions
|
||||||
|
{
|
||||||
|
extension(CharacterBody2D body)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
1
src/physics/Physics.cs.uid
Normal file
1
src/physics/Physics.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://cxqgafpm35er5
|
||||||
|
|
@ -2,10 +2,6 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Dancer;
|
namespace Dancer;
|
||||||
|
|
||||||
using Godot;
|
|
||||||
using Chickensoft.AutoInject;
|
|
||||||
using Chickensoft.Introspection;
|
|
||||||
|
|
||||||
[Meta(typeof(IAutoNode))]
|
[Meta(typeof(IAutoNode))]
|
||||||
public sealed partial class Player : CharacterBody2D
|
public sealed partial class Player : CharacterBody2D
|
||||||
{
|
{
|
||||||
|
|
@ -14,20 +10,23 @@ public sealed partial class Player : CharacterBody2D
|
||||||
[Export(PropertyHint.None, "suffix:s")]
|
[Export(PropertyHint.None, "suffix:s")]
|
||||||
public float MaxInputBufferTime { get; set; } = 0.15f;
|
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⁻¹")]
|
[Export(PropertyHint.None, "suffix:s⁻¹")]
|
||||||
public float GroundedSpeedDecay { get; set; } = 0.1f;
|
public float GroundedSpeedDecay { get; set; } = 0.3f;
|
||||||
|
|
||||||
[Export(PropertyHint.None, "suffix:s⁻¹")]
|
[Export(PropertyHint.None, "suffix:s⁻¹")]
|
||||||
public float GroundedSpeedStopDecay { get; set; } = 0.005f;
|
public float GroundedSpeedStopDecay { get; set; } = 0.005f;
|
||||||
|
|
||||||
[Export(PropertyHint.None, "suffix:px/s")]
|
[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²")]
|
[Export(PropertyHint.None, "suffix:px/s²")]
|
||||||
public float WalkAccel { get; set; } = 600.0f;
|
public float WalkAccel { get; set; } = 600.0f;
|
||||||
|
|
||||||
[Export(PropertyHint.None, "suffix:px/s²")]
|
[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")]
|
[Export(PropertyHint.None, "suffix:s")]
|
||||||
public float JumpAscentMaxTime { get; set; } = 0.2f;
|
public float JumpAscentMaxTime { get; set; } = 0.2f;
|
||||||
|
|
@ -100,6 +99,8 @@ public sealed partial class Player : CharacterBody2D
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
var deltaF = (float)delta;
|
var deltaF = (float)delta;
|
||||||
|
// Temporary copy of the velocity for easier editing.
|
||||||
|
var velocity = Velocity;
|
||||||
|
|
||||||
if (_currentDirection.X < 0)
|
if (_currentDirection.X < 0)
|
||||||
_isFacingRight = false;
|
_isFacingRight = false;
|
||||||
|
|
@ -109,48 +110,49 @@ public sealed partial class Player : CharacterBody2D
|
||||||
// Walking on the floor
|
// Walking on the floor
|
||||||
if (IsOnFloor())
|
if (IsOnFloor())
|
||||||
{
|
{
|
||||||
if (Mathf.Sign(Velocity.X) != Mathf.Sign(_currentDirection.X))
|
if (Mathf.Sign(velocity.X) != Mathf.Sign(_currentDirection.X))
|
||||||
Velocity = Velocity with { X = Velocity.X * Mathf.Pow(GroundedSpeedStopDecay, deltaF) };
|
velocity.X *= Mathf.Pow(GroundedSpeedStopDecay, deltaF);
|
||||||
else
|
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 targetVelX = Mathf.Sign(_currentDirection.X) * WalkMaxSpeed;
|
||||||
var isWalking = targetVelX != 0;
|
var isWalking = targetVelX != 0;
|
||||||
|
|
||||||
if (!isWalking || Mathf.Abs(Velocity.X) < WalkMaxSpeed)
|
if (!isWalking || Mathf.Abs(velocity.X) < WalkMaxSpeed)
|
||||||
{
|
{
|
||||||
Velocity = Velocity with
|
velocity.X = Mathf.MoveToward(velocity.X, targetVelX, WalkAccel * deltaF);
|
||||||
{
|
|
||||||
X = Mathf.MoveToward(Velocity.X, targetVelX, WalkAccel * deltaF)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Air control
|
// Air control
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Velocity = Velocity with { X = Velocity.X + _currentDirection.X * AirAccel * deltaF };
|
velocity.X += _currentDirection.X * AirAccel * deltaF;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move up while holding jump
|
// Move up while holding jump
|
||||||
if (_jumpAscentRemainingTime > 0)
|
if (_jumpAscentRemainingTime > 0)
|
||||||
{
|
{
|
||||||
Velocity = Velocity with { Y = -JumpAscentSpeed };
|
velocity.Y = -JumpAscentSpeed;
|
||||||
_jumpAscentRemainingTime -= deltaF;
|
_jumpAscentRemainingTime -= deltaF;
|
||||||
if (_jumpAscentRemainingTime < 0)
|
if (_jumpAscentRemainingTime < 0)
|
||||||
Velocity += GetGravity() * -_jumpAscentRemainingTime;
|
velocity += GetGravity() * -_jumpAscentRemainingTime;
|
||||||
}
|
}
|
||||||
else if (!IsOnFloor())
|
else if (!IsOnFloor())
|
||||||
{
|
{
|
||||||
Velocity += GetGravity() * deltaF;
|
velocity += GetGravity() * deltaF;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drag while in air
|
// Drag while in air
|
||||||
if (!IsOnFloor() && _jumpAscentRemainingTime <= 0)
|
if (!IsOnFloor() && _jumpAscentRemainingTime <= 0)
|
||||||
|
velocity += Physics.DragForce(-velocity) * deltaF;
|
||||||
|
|
||||||
|
if (IsHoldingWall())
|
||||||
{
|
{
|
||||||
var dragForce = -0.01f * Velocity * Velocity.Abs();
|
velocity.Y = Mathf.Min(velocity.Y, 5.0f);
|
||||||
Velocity += dragForce * deltaF;
|
_isFacingRight = Mathf.Sign(GetWallNormal().X) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Velocity = velocity;
|
||||||
MoveAndSlide();
|
MoveAndSlide();
|
||||||
|
|
||||||
_jumpAllowedTime = Mathf.Max(0, _jumpAllowedTime - deltaF);
|
_jumpAllowedTime = Mathf.Max(0, _jumpAllowedTime - deltaF);
|
||||||
|
|
@ -162,12 +164,6 @@ public sealed partial class Player : CharacterBody2D
|
||||||
_isJumping = false;
|
_isJumping = false;
|
||||||
_jumpAscentRemainingTime = 0.0f;
|
_jumpAscentRemainingTime = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsHoldingWall())
|
|
||||||
{
|
|
||||||
Velocity = Velocity with { Y = Mathf.Min(5.0f, Velocity.Y) };
|
|
||||||
_isFacingRight = Mathf.Sign(GetWallNormal().X) > 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsHoldingWall()
|
private bool IsHoldingWall()
|
||||||
|
|
@ -262,10 +258,7 @@ public sealed partial class Player : CharacterBody2D
|
||||||
|
|
||||||
private void Slash()
|
private void Slash()
|
||||||
{
|
{
|
||||||
Velocity = Velocity with
|
Velocity += (_isFacingRight ? Vector2.Right : Vector2.Left) * SlashSpeedBoost;
|
||||||
{
|
|
||||||
X = Velocity.X + (_isFacingRight ? 1 : -1) * SlashSpeedBoost
|
|
||||||
};
|
|
||||||
_playback.Travel("attack");
|
_playback.Travel("attack");
|
||||||
|
|
||||||
var instance = GD.Load<PackedScene>("res://src/player/slash_projectile.tscn")
|
var instance = GD.Load<PackedScene>("res://src/player/slash_projectile.tscn")
|
||||||
|
|
@ -287,7 +280,7 @@ public sealed partial class Player : CharacterBody2D
|
||||||
{
|
{
|
||||||
Attacker = this,
|
Attacker = this,
|
||||||
Damage = 1.0f,
|
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
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,7 @@ graph_offset = Vector2(-59.670364, -27)
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody2D" unique_id=500011307]
|
[node name="Player" type="CharacterBody2D" unique_id=500011307]
|
||||||
physics_interpolation_mode = 1
|
physics_interpolation_mode = 1
|
||||||
|
auto_translate_mode = 1
|
||||||
collision_layer = 2
|
collision_layer = 2
|
||||||
floor_constant_speed = true
|
floor_constant_speed = true
|
||||||
floor_max_angle = 0.24783675
|
floor_max_angle = 0.24783675
|
||||||
|
|
@ -190,7 +191,7 @@ metadata/_aseprite_wizard_interface_config_ = {
|
||||||
"i_mode": 0,
|
"i_mode": 0,
|
||||||
"keep_anim_length": false,
|
"keep_anim_length": false,
|
||||||
"player": "",
|
"player": "",
|
||||||
"source": "res://player/player.aseprite"
|
"source": "res://src/player/player.aseprite"
|
||||||
},
|
},
|
||||||
"slice_section": false
|
"slice_section": false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue