added C#
This commit is contained in:
parent
ab79ace226
commit
00b76b6b25
63 changed files with 1172 additions and 1548 deletions
300
src/player/Player.cs
Normal file
300
src/player/Player.cs
Normal file
|
|
@ -0,0 +1,300 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Dancer;
|
||||
|
||||
using Godot;
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public sealed partial class Player : CharacterBody2D
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Export(PropertyHint.None, "suffix:s")]
|
||||
public float MaxInputBufferTime { get; set; } = 0.15f;
|
||||
|
||||
[Export(PropertyHint.None, "suffix:s⁻¹")]
|
||||
public float GroundedSpeedDecay { get; set; } = 0.1f;
|
||||
|
||||
[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;
|
||||
|
||||
[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;
|
||||
|
||||
[Export(PropertyHint.None, "suffix:s")]
|
||||
public float JumpAscentMaxTime { get; set; } = 0.2f;
|
||||
|
||||
[Export(PropertyHint.None, "suffix:px/s")]
|
||||
public float JumpAscentSpeed { get; set; } = 200.0f;
|
||||
|
||||
[Export(PropertyHint.None, "suffix:s")]
|
||||
public float LateJumpTimeLimit { get; set; } = 0.15f;
|
||||
|
||||
[Export(PropertyHint.None, "suffix:s")]
|
||||
public float SlashSpeedBoost { get; set; } = 90.0f;
|
||||
|
||||
/// <summary>The angle difference from perfect left/right that still counts.</summary>
|
||||
[Export(PropertyHint.Range, "0,360,0.1,radians_as_degrees")]
|
||||
public float SideInputAngle { get; set; } = Mathf.Pi / 4;
|
||||
|
||||
/// <summary>The angle difference from perfect down that still counts.</summary>
|
||||
[Export(PropertyHint.Range, "0,360,0.1,radians_as_degrees")]
|
||||
public float DownInputAngle { get; set; } = Mathf.Pi / 4;
|
||||
|
||||
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()
|
||||
{
|
||||
_playback = AnimationTree.Get("parameters/playback").As<AnimationNodeStateMachinePlayback>();
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (@event.IsEcho())
|
||||
return;
|
||||
|
||||
if (
|
||||
@event.IsAction("move_left")
|
||||
|| @event.IsAction("move_right")
|
||||
|| @event.IsAction("move_up")
|
||||
|| @event.IsAction("move_down"))
|
||||
{
|
||||
_currentDirection = Input.GetVector(
|
||||
"move_left",
|
||||
"move_right",
|
||||
"move_up",
|
||||
"move_down");
|
||||
}
|
||||
|
||||
if (@event.IsAction("jump") || @event.IsAction("attack"))
|
||||
{
|
||||
_inputBuffer.Add(new()
|
||||
{
|
||||
Direction = _currentDirection,
|
||||
Event = @event,
|
||||
Time = Time.GetTicksUsec()
|
||||
});
|
||||
HandleBufferedInputs();
|
||||
}
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var deltaF = (float)delta;
|
||||
|
||||
if (_currentDirection.X < 0)
|
||||
_isFacingRight = false;
|
||||
else if (_currentDirection.X > 0)
|
||||
_isFacingRight = true;
|
||||
|
||||
// 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) };
|
||||
else
|
||||
Velocity = Velocity with { X = Velocity.X * Mathf.Pow(GroundedSpeedDecay, deltaF) };
|
||||
|
||||
var targetVelX = Mathf.Sign(_currentDirection.X) * WalkMaxSpeed;
|
||||
var isWalking = targetVelX != 0;
|
||||
|
||||
if (!isWalking || Mathf.Abs(Velocity.X) < WalkMaxSpeed)
|
||||
{
|
||||
Velocity = Velocity with
|
||||
{
|
||||
X = Mathf.MoveToward(Velocity.X, targetVelX, WalkAccel * deltaF)
|
||||
};
|
||||
}
|
||||
}
|
||||
// Air control
|
||||
else
|
||||
{
|
||||
Velocity = Velocity with { X = Velocity.X + _currentDirection.X * AirAccel * deltaF };
|
||||
}
|
||||
|
||||
// Move up while holding jump
|
||||
if (_jumpAscentRemainingTime > 0)
|
||||
{
|
||||
Velocity = Velocity with { Y = -JumpAscentSpeed };
|
||||
_jumpAscentRemainingTime -= deltaF;
|
||||
if (_jumpAscentRemainingTime < 0)
|
||||
Velocity += GetGravity() * -_jumpAscentRemainingTime;
|
||||
}
|
||||
else if (!IsOnFloor())
|
||||
{
|
||||
Velocity += GetGravity() * deltaF;
|
||||
}
|
||||
|
||||
// Drag while in air
|
||||
if (!IsOnFloor() && _jumpAscentRemainingTime <= 0)
|
||||
{
|
||||
var dragForce = -0.01f * Velocity * Velocity.Abs();
|
||||
Velocity += dragForce * deltaF;
|
||||
}
|
||||
|
||||
MoveAndSlide();
|
||||
|
||||
_jumpAllowedTime = Mathf.Max(0, _jumpAllowedTime - deltaF);
|
||||
if (IsOnFloor())
|
||||
_jumpAllowedTime = LateJumpTimeLimit;
|
||||
|
||||
if (IsOnCeiling())
|
||||
{
|
||||
_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()
|
||||
{
|
||||
return
|
||||
!IsOnFloor()
|
||||
&& IsOnWall()
|
||||
&& Mathf.Sign(GetWallNormal().X) != Mathf.Sign(_currentDirection.X)
|
||||
&& _currentDirection.X != 0;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
HandleBufferedInputs();
|
||||
GetNode<Node2D>("%Body").Scale = new(_isFacingRight ? 1 : -1, 1);
|
||||
}
|
||||
|
||||
private void HandleBufferedInputs()
|
||||
{
|
||||
var inputFound = false;
|
||||
var currentTime = Time.GetTicksUsec();
|
||||
|
||||
// Clear expired input buffer items
|
||||
while (
|
||||
_inputBuffer.Count > 0
|
||||
&& _inputBuffer[0].Time + MaxInputBufferTimeMicroseconds < currentTime)
|
||||
{
|
||||
_inputBuffer.RemoveAt(0);
|
||||
}
|
||||
|
||||
// Check new commands
|
||||
for (var i = 0; i < _inputBuffer.Count; i++)
|
||||
{
|
||||
var input = _inputBuffer[i];
|
||||
|
||||
if (input.Event.IsAction("jump"))
|
||||
{
|
||||
if (
|
||||
input.Event.IsPressed()
|
||||
&& _jumpAllowedTime > 0
|
||||
&& (!IsOnFloor() || !IsInputVecDown(input.Direction)))
|
||||
{
|
||||
inputFound = true;
|
||||
GroundJump();
|
||||
}
|
||||
else if (input.Event.IsPressed() && IsOnWall())
|
||||
{
|
||||
inputFound = true;
|
||||
WallJump();
|
||||
}
|
||||
else if (input.Event.IsReleased() && _isJumping)
|
||||
{
|
||||
JumpCut();
|
||||
}
|
||||
}
|
||||
else if (input.Event.IsActionPressed("attack"))
|
||||
{
|
||||
inputFound = true;
|
||||
Slash();
|
||||
}
|
||||
|
||||
if (inputFound)
|
||||
{
|
||||
_inputBuffer = _inputBuffer.GetRange(i + 1, _inputBuffer.Count - i - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GroundJump()
|
||||
{
|
||||
_jumpAllowedTime = 0.0f;
|
||||
_jumpAscentRemainingTime = JumpAscentMaxTime;
|
||||
_isJumping = true;
|
||||
}
|
||||
|
||||
private void WallJump()
|
||||
{
|
||||
_jumpAllowedTime = 0.0f;
|
||||
Velocity += GetWallNormal() * 200.0f;
|
||||
Velocity = Velocity with { Y = Mathf.Min(0, Velocity.Y) };
|
||||
}
|
||||
|
||||
private void JumpCut()
|
||||
{
|
||||
_isJumping = false;
|
||||
_jumpAscentRemainingTime = 0.0f;
|
||||
// Jump cut only once, if we're still moving up
|
||||
if (Velocity.Y < 0)
|
||||
Velocity = Velocity with { Y = Velocity.Y * 0.1f };
|
||||
}
|
||||
|
||||
private void Slash()
|
||||
{
|
||||
Velocity = Velocity with
|
||||
{
|
||||
X = Velocity.X + (_isFacingRight ? 1 : -1) * 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;
|
||||
}
|
||||
|
||||
private bool IsInputVecDown(Vector2 vec)
|
||||
{
|
||||
return Mathf.Abs(vec.AngleTo(Vector2.Down)) < DownInputAngle && vec.Length() > 0.1f;
|
||||
}
|
||||
|
||||
private void OnEnemyHit(Node2D enemy)
|
||||
{
|
||||
if (enemy is not IAttackable attackable) return;
|
||||
attackable.GetAttacked(new()
|
||||
{
|
||||
Attacker = this,
|
||||
Damage = 1.0f,
|
||||
Impulse = Vector2.Down * 5000.0f + (enemy.Position - Position).Normalized() * 5000.0f
|
||||
});
|
||||
}
|
||||
|
||||
public class BufferedInput
|
||||
{
|
||||
public Vector2 Direction { get; init; }
|
||||
public required InputEvent Event { get; init; }
|
||||
public ulong Time { get; init; }
|
||||
}
|
||||
}
|
||||
1
src/player/Player.cs.uid
Normal file
1
src/player/Player.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b5iey2typf2tb
|
||||
17
src/player/SlashProjectile.cs
Normal file
17
src/player/SlashProjectile.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
namespace Dancer;
|
||||
|
||||
using Godot;
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public sealed partial class SlashProjectile : Node2D
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Signal]
|
||||
public delegate void HitboxEnteredEventHandler(Node2D other);
|
||||
|
||||
public void OnAttackFinished() => QueueFree();
|
||||
public void OnHitboxBodyEntered(Node2D body) => EmitSignalHitboxEntered(body);
|
||||
}
|
||||
1
src/player/SlashProjectile.cs.uid
Normal file
1
src/player/SlashProjectile.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://0n1gv56pcc74
|
||||
BIN
src/player/attack.aseprite
Normal file
BIN
src/player/attack.aseprite
Normal file
Binary file not shown.
21
src/player/attack.aseprite.import
Normal file
21
src/player/attack.aseprite.import
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
[remap]
|
||||
|
||||
importer="aseprite_wizard.plugin.static-texture"
|
||||
type="PortableCompressedTexture2D"
|
||||
uid="uid://jdmsv25yp25v"
|
||||
path="res://.godot/imported/attack.aseprite-0b3d00875a10a8cf04bab0910589e119.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://src/player/attack.aseprite"
|
||||
dest_files=["res://.godot/imported/attack.aseprite-0b3d00875a10a8cf04bab0910589e119.res"]
|
||||
|
||||
[params]
|
||||
|
||||
layer/exclude_layers_pattern=""
|
||||
layer/only_visible_layers=true
|
||||
layer/split_layers=false
|
||||
first_frame_only=false
|
||||
sheet/sheet_type="horizontal"
|
||||
sheet/sheet_columns=12
|
||||
sheet/scale=1
|
||||
BIN
src/player/hair.aseprite
Normal file
BIN
src/player/hair.aseprite
Normal file
Binary file not shown.
21
src/player/hair.aseprite.import
Normal file
21
src/player/hair.aseprite.import
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
[remap]
|
||||
|
||||
importer="aseprite_wizard.plugin.static-texture"
|
||||
type="PortableCompressedTexture2D"
|
||||
uid="uid://blw6f2ktsrcmg"
|
||||
path="res://.godot/imported/hair.aseprite-733fe205726c184830ebda91637ad9f5.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://src/player/hair.aseprite"
|
||||
dest_files=["res://.godot/imported/hair.aseprite-733fe205726c184830ebda91637ad9f5.res"]
|
||||
|
||||
[params]
|
||||
|
||||
layer/exclude_layers_pattern=""
|
||||
layer/only_visible_layers=false
|
||||
layer/split_layers=false
|
||||
first_frame_only=true
|
||||
sheet/sheet_type="packed"
|
||||
sheet/sheet_columns=12
|
||||
sheet/scale=1
|
||||
BIN
src/player/player.aseprite
Normal file
BIN
src/player/player.aseprite
Normal file
Binary file not shown.
21
src/player/player.aseprite.import
Normal file
21
src/player/player.aseprite.import
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
[remap]
|
||||
|
||||
importer="aseprite_wizard.plugin.static-texture"
|
||||
type="PortableCompressedTexture2D"
|
||||
uid="uid://d0dy3j0qdycqf"
|
||||
path="res://.godot/imported/player.aseprite-61ab8c4a2ca60d43d00c5a0147684013.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://src/player/player.aseprite"
|
||||
dest_files=["res://.godot/imported/player.aseprite-61ab8c4a2ca60d43d00c5a0147684013.res"]
|
||||
|
||||
[params]
|
||||
|
||||
layer/exclude_layers_pattern=""
|
||||
layer/only_visible_layers=true
|
||||
layer/split_layers=false
|
||||
first_frame_only=false
|
||||
sheet/sheet_type="horizontal"
|
||||
sheet/sheet_columns=12
|
||||
sheet/scale=1
|
||||
232
src/player/player.tscn
Normal file
232
src/player/player.tscn
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
[gd_scene format=3 uid="uid://ce2k04khaub8n"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b5iey2typf2tb" path="res://src/player/Player.cs" id="1_244u8"]
|
||||
[ext_resource type="Script" uid="uid://bhijvek6js88u" path="res://src/spring/Spring2D.cs" id="2_mf2ua"]
|
||||
[ext_resource type="Texture2D" uid="uid://d0dy3j0qdycqf" path="res://src/player/player.aseprite" id="2_yw30f"]
|
||||
[ext_resource type="Texture2D" uid="uid://blw6f2ktsrcmg" path="res://src/player/hair.aseprite" id="3_qjkh3"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_e2o6t"]
|
||||
radius = 4.0
|
||||
height = 14.0
|
||||
|
||||
[sub_resource type="Animation" id="Animation_yw30f"]
|
||||
resource_name = "RESET"
|
||||
length = 0.001
|
||||
step = 0.016666668
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Body:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [0]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_qjkh3"]
|
||||
resource_name = "idle"
|
||||
length = 1.0000017
|
||||
loop_mode = 1
|
||||
step = 0.1
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Body:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [0]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_g6k8r"]
|
||||
resource_name = "slash"
|
||||
length = 0.20000167
|
||||
step = 0.05
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Body:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [6]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_boad6"]
|
||||
resource_name = "walk"
|
||||
length = 0.400005
|
||||
loop_mode = 1
|
||||
step = 0.1
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Body:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3),
|
||||
"transitions": PackedFloat32Array(1, 1, 1, 1),
|
||||
"update": 1,
|
||||
"values": [0, 1, 2, 3]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_rgyib"]
|
||||
resource_name = "wall_hold"
|
||||
length = 1.0000017
|
||||
loop_mode = 1
|
||||
step = 0.1
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Body:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [5]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_rgyib"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_yw30f"),
|
||||
&"idle": SubResource("Animation_qjkh3"),
|
||||
&"slash": SubResource("Animation_g6k8r"),
|
||||
&"walk": SubResource("Animation_boad6"),
|
||||
&"wall_hold": SubResource("Animation_rgyib")
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_qjkh3"]
|
||||
animation = &"slash"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_yw30f"]
|
||||
animation = &"idle"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_g6k8r"]
|
||||
animation = &"walk"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_boad6"]
|
||||
animation = &"wall_hold"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_boad6"]
|
||||
switch_mode = 2
|
||||
advance_mode = 2
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_rgyib"]
|
||||
break_loop_at_end = true
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_hg6s5"]
|
||||
advance_mode = 2
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_8t03j"]
|
||||
advance_mode = 2
|
||||
advance_expression = "is_on_floor() and _currentDirection.x != 0.0"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_2ieo8"]
|
||||
break_loop_at_end = true
|
||||
advance_mode = 2
|
||||
advance_expression = "not is_on_floor() or _currentDirection.x == 0.0"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_ebec5"]
|
||||
advance_expression = "_is_on_wall()"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_yllr7"]
|
||||
advance_mode = 2
|
||||
advance_expression = "IsHoldingWall()"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_kb6p2"]
|
||||
advance_mode = 2
|
||||
advance_expression = "not IsHoldingWall()"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_yllr7"]
|
||||
allow_transition_to_self = true
|
||||
states/attack/node = SubResource("AnimationNodeAnimation_qjkh3")
|
||||
states/attack/position = Vector2(604.5, 41.5)
|
||||
states/idle/node = SubResource("AnimationNodeAnimation_yw30f")
|
||||
states/idle/position = Vector2(428.5, 88.5)
|
||||
states/walk/node = SubResource("AnimationNodeAnimation_g6k8r")
|
||||
states/walk/position = Vector2(628.5, 203.5)
|
||||
states/wall_hold/node = SubResource("AnimationNodeAnimation_boad6")
|
||||
states/wall_hold/position = Vector2(362.82965, 231.5)
|
||||
transitions = ["attack", "idle", SubResource("AnimationNodeStateMachineTransition_boad6"), "idle", "attack", SubResource("AnimationNodeStateMachineTransition_rgyib"), "Start", "idle", SubResource("AnimationNodeStateMachineTransition_hg6s5"), "idle", "walk", SubResource("AnimationNodeStateMachineTransition_8t03j"), "walk", "idle", SubResource("AnimationNodeStateMachineTransition_2ieo8"), "walk", "attack", SubResource("AnimationNodeStateMachineTransition_ebec5"), "idle", "wall_hold", SubResource("AnimationNodeStateMachineTransition_yllr7"), "wall_hold", "idle", SubResource("AnimationNodeStateMachineTransition_kb6p2")]
|
||||
graph_offset = Vector2(-59.670364, -27)
|
||||
|
||||
[node name="Player" type="CharacterBody2D" unique_id=500011307]
|
||||
physics_interpolation_mode = 1
|
||||
collision_layer = 2
|
||||
floor_constant_speed = true
|
||||
floor_max_angle = 0.24783675
|
||||
script = ExtResource("1_244u8")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=84142517]
|
||||
position = Vector2(0, 1)
|
||||
shape = SubResource("CapsuleShape2D_e2o6t")
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="." unique_id=1975474809]
|
||||
limit_enabled = false
|
||||
|
||||
[node name="Body" type="Sprite2D" parent="." unique_id=567060128]
|
||||
unique_name_in_owner = true
|
||||
texture = ExtResource("2_yw30f")
|
||||
hframes = 7
|
||||
metadata/_aseprite_wizard_interface_config_ = {
|
||||
"animation_section": false,
|
||||
"layer_section": false,
|
||||
"output_section": false,
|
||||
"pending_changes": {
|
||||
"convert_fps_field": 60.0,
|
||||
"convert_ms_field": 16.0,
|
||||
"convert_to_fps": false,
|
||||
"i_mode": 0,
|
||||
"keep_anim_length": false,
|
||||
"player": "",
|
||||
"source": "res://player/player.aseprite"
|
||||
},
|
||||
"slice_section": false
|
||||
}
|
||||
metadata/_aseprite_wizard_config_ = {
|
||||
"embed_tex": true,
|
||||
"layers": [],
|
||||
"o_ex_p": "",
|
||||
"o_folder": "",
|
||||
"o_name": "",
|
||||
"only_visible": false,
|
||||
"scale": "1.0",
|
||||
"should_round_fps": true,
|
||||
"slice": "",
|
||||
"source": "res://player.aseprite",
|
||||
"source_uid": 8921683997410207965
|
||||
}
|
||||
metadata/_aseprite_wizard_source_file_hash_ = "61168df4a163c039cfaab97f4fccb905"
|
||||
|
||||
[node name="Spring2D" type="Node2D" parent="Body" unique_id=1050714188]
|
||||
show_behind_parent = true
|
||||
script = ExtResource("2_mf2ua")
|
||||
|
||||
[node name="Hair" type="Sprite2D" parent="Body/Spring2D" unique_id=796557000]
|
||||
position = Vector2(-2, 2)
|
||||
texture = ExtResource("3_qjkh3")
|
||||
|
||||
[node name="HandAttachment" type="Node2D" parent="Body" unique_id=1002134601]
|
||||
unique_name_in_owner = true
|
||||
position = Vector2(3, 2)
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=1251324400]
|
||||
libraries/ = SubResource("AnimationLibrary_rgyib")
|
||||
|
||||
[node name="AnimationTree" type="AnimationTree" parent="AnimationPlayer" unique_id=1839424284]
|
||||
unique_name_in_owner = true
|
||||
root_node = NodePath("%AnimationTree/../..")
|
||||
tree_root = SubResource("AnimationNodeStateMachine_yllr7")
|
||||
advance_expression_base_node = NodePath("../..")
|
||||
anim_player = NodePath("..")
|
||||
114
src/player/ribbon.gd
Normal file
114
src/player/ribbon.gd
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
extends Node2D
|
||||
|
||||
@export_custom(PROPERTY_HINT_NONE, "suffix:px")
|
||||
var max_length: float = 120.0
|
||||
@export_custom(PROPERTY_HINT_NONE, "suffix:px")
|
||||
var distance_limit: float = 2000.0
|
||||
@export_custom(PROPERTY_HINT_NONE, "suffix:px")
|
||||
var segment_length: float = 5.0
|
||||
@export var color: Color
|
||||
@export_custom(PROPERTY_HINT_NONE, "suffix:px")
|
||||
var width: float = 1.4
|
||||
@export var fall_speed: float = 5.5
|
||||
## The amount of different update groups to split points into.
|
||||
@export var point_update_groups: int = 3
|
||||
@export var new_segments_damage: bool = false
|
||||
|
||||
var _points: Array[RibbonPoint] = []
|
||||
class RibbonPoint:
|
||||
var position: Vector2
|
||||
|
||||
var _length: float:
|
||||
get():
|
||||
var current_length := 0.0
|
||||
for i in _points.size() - 1:
|
||||
var from = _points[i]
|
||||
var to = _points[i+1]
|
||||
current_length += from.position.distance_to(to.position)
|
||||
return current_length
|
||||
var _point_shape: Shape2D
|
||||
|
||||
func _ready() -> void:
|
||||
_point_shape = CircleShape2D.new()
|
||||
_point_shape.radius = width / 2.0
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var space_state = get_world_2d().direct_space_state
|
||||
var target := global_position
|
||||
if _points.is_empty() or _points.back().position.distance_to(position) > distance_limit:
|
||||
var point := RibbonPoint.new()
|
||||
point.position = target
|
||||
_points = [point]
|
||||
else:
|
||||
var head: RibbonPoint = _points.back()
|
||||
var distance = target.distance_to(head.position)
|
||||
if (distance > segment_length / 2.0):
|
||||
var point_count := ceili(distance / segment_length)
|
||||
for i in point_count:
|
||||
var t: float = float(i + 1) / point_count
|
||||
var point: RibbonPoint = RibbonPoint.new()
|
||||
point.position = lerp(head.position, target, t)
|
||||
_points.push_back(point)
|
||||
|
||||
if new_segments_damage:
|
||||
var query := PhysicsShapeQueryParameters2D.new()
|
||||
var shape = SegmentShape2D.new()
|
||||
shape.a = head.position
|
||||
shape.b = target
|
||||
query.shape = shape
|
||||
query.collision_mask = 0x0000_0004
|
||||
var results := space_state.intersect_shape(query)
|
||||
for result in results:
|
||||
print("hit creature", result.collider)
|
||||
|
||||
var current_length := _length
|
||||
while current_length > max_length:
|
||||
var popped = _points.pop_front()
|
||||
var tail = _points.front()
|
||||
current_length -= popped.position.distance_to(tail.position)
|
||||
|
||||
_update_points(delta)
|
||||
|
||||
func _update_points(delta: float) -> void:
|
||||
var space_state = get_world_2d().direct_space_state
|
||||
var query = PhysicsShapeQueryParameters2D.new()
|
||||
query.shape = _point_shape
|
||||
query.collision_mask = 0x0000_0001
|
||||
|
||||
for i in range(randi() % point_update_groups, _points.size() - 1, point_update_groups):
|
||||
# Skipping the head on purpose, so it doesn't keep falling away,
|
||||
# crating more and more points.
|
||||
var point = _points[i]
|
||||
var next = _points[i+1]
|
||||
|
||||
# Gravity
|
||||
if (point.position.distance_to(next.position) <= segment_length * 1.5
|
||||
or point.position.y < next.position.y):
|
||||
var fall_distance = fall_speed * delta * point_update_groups
|
||||
query.transform = Transform2D.IDENTITY.translated(point.position)
|
||||
query.motion = Vector2.DOWN * fall_distance
|
||||
var result := space_state.cast_motion(query)
|
||||
var safe_proportion := result[0]
|
||||
point.position = point.position + query.motion * safe_proportion
|
||||
|
||||
# Pull together
|
||||
var distance_to_next: float = point.position.distance_to(next.position)
|
||||
if distance_to_next > segment_length:
|
||||
var move_distance = distance_to_next - segment_length
|
||||
query.transform = Transform2D.IDENTITY.translated(point.position)
|
||||
query.motion = (next.position - point.position).normalized() * move_distance
|
||||
var result := space_state.cast_motion(query)
|
||||
var safe_proportion := result[0]
|
||||
point.position = point.position + query.motion * safe_proportion
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
queue_redraw()
|
||||
|
||||
var _packed_points = PackedVector2Array()
|
||||
func _draw() -> void:
|
||||
draw_set_transform_matrix(global_transform.affine_inverse())
|
||||
if (_points.size() < 2): return
|
||||
_packed_points.resize(_points.size())
|
||||
for i in _points.size():
|
||||
_packed_points[i] = _points[i].position
|
||||
draw_polyline(_packed_points, color, width, false)
|
||||
1
src/player/ribbon.gd.uid
Normal file
1
src/player/ribbon.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bk0k3j7th00wu
|
||||
9
src/player/slash_projectile.gd
Normal file
9
src/player/slash_projectile.gd
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
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
src/player/slash_projectile.gd.uid
Normal file
1
src/player/slash_projectile.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://uwfp4ytugp51
|
||||
108
src/player/slash_projectile.tscn
Normal file
108
src/player/slash_projectile.tscn
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
[gd_scene format=3 uid="uid://bikcpm0fyl4pd"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://jdmsv25yp25v" path="res://src/player/attack.aseprite" id="1_3il12"]
|
||||
[ext_resource type="Script" uid="uid://0n1gv56pcc74" path="res://src/player/SlashProjectile.cs" id="1_bi0sp"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_3il12"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Attack:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [0]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Hitbox/CollisionShape2D:disabled")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [true]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_eb3da"]
|
||||
resource_name = "attack"
|
||||
length = 0.4
|
||||
step = 0.1
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Attack:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.1, 0.2),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 1,
|
||||
"values": [0, 1, 2]
|
||||
}
|
||||
tracks/1/type = "method"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath(".")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0.4),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"values": [{
|
||||
"args": [],
|
||||
"method": &"OnAttackFinished"
|
||||
}]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath("Hitbox/CollisionShape2D:disabled")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
"times": PackedFloat32Array(0, 0.1, 0.3),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 1,
|
||||
"values": [true, false, true]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_12t1i"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_3il12"),
|
||||
&"attack": SubResource("Animation_eb3da")
|
||||
}
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_u7cw4"]
|
||||
size = Vector2(32, 10)
|
||||
|
||||
[node name="SlashProjectile" type="Node2D" unique_id=541992074]
|
||||
script = ExtResource("1_bi0sp")
|
||||
|
||||
[node name="Attack" type="Sprite2D" parent="." unique_id=30274790]
|
||||
position = Vector2(16, -3)
|
||||
texture = ExtResource("1_3il12")
|
||||
hframes = 3
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=1896907748]
|
||||
unique_name_in_owner = true
|
||||
libraries/ = SubResource("AnimationLibrary_12t1i")
|
||||
autoplay = &"attack"
|
||||
|
||||
[node name="Hitbox" type="Area2D" parent="." unique_id=133086557]
|
||||
collision_layer = 8
|
||||
collision_mask = 4
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox" unique_id=1668475985]
|
||||
position = Vector2(21, -5)
|
||||
shape = SubResource("RectangleShape2D_u7cw4")
|
||||
disabled = true
|
||||
debug_color = Color(0.99430805, 0, 0.2314094, 0.41960785)
|
||||
|
||||
[connection signal="body_entered" from="Hitbox" to="." method="OnHitboxBodyEntered"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue