godot 4.7, more player controller
This commit is contained in:
parent
f774f8e8a4
commit
eea6830534
9 changed files with 220 additions and 36 deletions
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Godot.NET.Sdk/4.6.3">
|
||||
<Project Sdk="Godot.NET.Sdk/4.7.0">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||
|
|
|
|||
32
Dancer.csproj.old
Normal file
32
Dancer.csproj.old
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<Project Sdk="Godot.NET.Sdk/4.6.3">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<Authors>blossomfiend</Authors>
|
||||
<IsAotCompatible>true</IsAotCompatible>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Chickensoft.AutoInject" Version="2.13.11" PrivateAssets="all" />
|
||||
<PackageReference Include="Chickensoft.AutoInject.Analyzers" Version="2.13.11" PrivateAssets="all" OutputItemType="analyzer" />
|
||||
<PackageReference Include="Chickensoft.GodotNodeInterfaces" Version="3.0.17" />
|
||||
<PackageReference Include="Chickensoft.Introspection" Version="3.0.3" />
|
||||
<PackageReference Include="Chickensoft.Introspection.Generator" Version="3.0.3" PrivateAssets="all" OutputItemType="analyzer" />
|
||||
<PackageReference Include="Chickensoft.LogicBlocks" Version="6.0.0" />
|
||||
<PackageReference Include="Chickensoft.LogicBlocks.Auto" Version="6.0.0" />
|
||||
<PackageReference Include="Chickensoft.LogicBlocks.DiagramGenerator" Version="6.0.0" PrivateAssets="all" OutputItemType="analyzer" />
|
||||
<PackageReference Include="Chickensoft.LogicBlocks.Generator" Version="4.2.2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Remove="script_templates/**" />
|
||||
<None Include="script_templates/**" />
|
||||
<None Include="src/**" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<!-- Root the assemblies to avoid trimming. -->
|
||||
<TrimmerRootAssembly Include="GodotSharp" />
|
||||
<TrimmerRootAssembly Include="$(TargetName)" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -12,7 +12,7 @@ config_version=5
|
|||
|
||||
config/name="Dancer"
|
||||
run/main_scene="uid://cujd7ltkrnxpt"
|
||||
config/features=PackedStringArray("4.6", "C#", "GL Compatibility")
|
||||
config/features=PackedStringArray("4.7", "C#", "GL Compatibility")
|
||||
|
||||
[aseprite]
|
||||
|
||||
|
|
@ -82,6 +82,8 @@ attack={
|
|||
2d_physics/layer_3="enemy_hurtbox"
|
||||
2d_physics/layer_4="player_hitbox"
|
||||
2d_physics/layer_5="enemy_hitbox"
|
||||
2d_physics/layer_6="water"
|
||||
2d_physics/layer_7="platform"
|
||||
|
||||
[physics]
|
||||
|
||||
|
|
@ -89,7 +91,7 @@ attack={
|
|||
common/physics_ticks_per_second=120
|
||||
common/physics_jitter_fix=0.0
|
||||
3d/physics_engine="Dummy"
|
||||
2d/default_gravity=480.0
|
||||
2d/default_gravity=800.0
|
||||
common/physics_interpolation=true
|
||||
|
||||
[rendering]
|
||||
|
|
|
|||
|
|
@ -176,6 +176,7 @@ _data = {
|
|||
|
||||
[node name="Birb" type="CharacterBody2D" unique_id=428810294]
|
||||
collision_layer = 4
|
||||
collision_mask = 65
|
||||
script = ExtResource("1_lyo8d")
|
||||
AttackDistance = 45.0
|
||||
metadata/_edit_group_ = true
|
||||
|
|
@ -189,6 +190,8 @@ offset = Vector2(9, -4)
|
|||
|
||||
[node name="StabHitbox" type="Area2D" parent="Body" unique_id=1373491990]
|
||||
unique_name_in_owner = true
|
||||
process_mode = 4
|
||||
visible = false
|
||||
collision_layer = 16
|
||||
collision_mask = 2
|
||||
script = ExtResource("3_bu42x")
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
BIN
src/level/tiles.aseprite
(Stored with Git LFS)
BIN
src/level/tiles.aseprite
(Stored with Git LFS)
Binary file not shown.
|
|
@ -1,9 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using Chickensoft.LogicBlocks;
|
||||
using Chickensoft.LogicBlocks.Auto;
|
||||
|
||||
namespace Dancer;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner, IProvide<IHitboxOwner>
|
||||
public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
||||
IProvide<IHitboxOwner>
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
|
|
@ -20,13 +24,16 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
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; } = 900.0f;
|
||||
public float WalkAccel { get; set; } = 800.0f;
|
||||
|
||||
[Export(PropertyHint.None, "suffix:px/s²")]
|
||||
public float AirAccel { get; set; } = 210.0f;
|
||||
public float AirAccel { get; set; } = 180.0f;
|
||||
|
||||
[Export(PropertyHint.None, "suffix:px/s²")]
|
||||
public float WaterAccel { get; set; } = 1200.0f;
|
||||
|
||||
[Export(PropertyHint.None, "suffix:s")]
|
||||
public float JumpAscentMaxTime { get; set; } = 0.2f;
|
||||
|
|
@ -52,6 +59,8 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
[Export] public float Health { get; set; }
|
||||
[Export] public bool CanTurn { get; set; } = true;
|
||||
|
||||
[Export] public TileMapLayer WaterTileMap { get; set; } = null!;
|
||||
|
||||
private ulong MaxInputBufferTimeMicroseconds => (ulong)(MaxInputBufferTime * 1_000_000);
|
||||
private float _jumpAscentRemainingTime;
|
||||
private bool _isJumping;
|
||||
|
|
@ -60,8 +69,11 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
private bool _isFacingRight = true;
|
||||
private AnimationNodeStateMachinePlayback _playback = null!;
|
||||
private List<BufferedInput> _inputBuffer = [];
|
||||
private bool _isInWater;
|
||||
private float PlatformIgnoreTime { get; set; }
|
||||
|
||||
[Node] private AnimationTree AnimationTree { get; set; } = null!;
|
||||
[Node] private Area2D SubmersedSensor { get; set; } = null!;
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
|
|
@ -109,15 +121,21 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
|
||||
if (CanTurn) AdjustFacing();
|
||||
|
||||
// Walking on the floor
|
||||
if (IsOnFloor())
|
||||
// Water movement
|
||||
if (_isInWater)
|
||||
{
|
||||
if (Mathf.Sign(velocity.X) != Mathf.Sign(_currentDirection.X))
|
||||
velocity += _currentDirection * WaterAccel * deltaF;
|
||||
}
|
||||
// Walking on the floor
|
||||
else if (IsOnFloor())
|
||||
{
|
||||
var walkInput = IsInputVecSide(_currentDirection) ? _currentDirection.X : 0f;
|
||||
if (Mathf.Sign(velocity.X) != Mathf.Sign(walkInput))
|
||||
velocity.X *= Mathf.Pow(GroundedSpeedStopDecay, deltaF);
|
||||
else
|
||||
velocity.X *= Mathf.Pow(GroundedSpeedDecay, deltaF);
|
||||
|
||||
var targetVelX = Mathf.Sign(_currentDirection.X) * WalkMaxSpeed;
|
||||
var targetVelX = Mathf.Sign(walkInput) * WalkMaxSpeed;
|
||||
var isWalking = targetVelX != 0;
|
||||
|
||||
if (!isWalking || Mathf.Abs(velocity.X) < WalkMaxSpeed)
|
||||
|
|
@ -139,14 +157,21 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
if (_jumpAscentRemainingTime < 0)
|
||||
velocity += GetGravity() * -_jumpAscentRemainingTime;
|
||||
}
|
||||
else if (!IsOnFloor())
|
||||
else if (!IsOnFloor() && !_isInWater)
|
||||
{
|
||||
velocity += GetGravity() * deltaF;
|
||||
}
|
||||
|
||||
// Drag in water
|
||||
if (_isInWater)
|
||||
{
|
||||
velocity += Physics.DragForce(-velocity, 0.02f) * deltaF;
|
||||
}
|
||||
// Drag while in air
|
||||
if (!IsOnFloor() && _jumpAscentRemainingTime <= 0)
|
||||
velocity += Physics.DragForce(-velocity) * deltaF;
|
||||
else if (!IsOnFloor() && _jumpAscentRemainingTime <= 0)
|
||||
{
|
||||
velocity += Physics.DragForce(-velocity, 0.009f) * deltaF;
|
||||
}
|
||||
|
||||
if (IsHoldingWall())
|
||||
{
|
||||
|
|
@ -155,6 +180,15 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
}
|
||||
|
||||
Velocity = velocity;
|
||||
if (PlatformIgnoreTime > 0f)
|
||||
{
|
||||
CollisionMask = 0b1;
|
||||
PlatformIgnoreTime = Mathf.Max(0f, PlatformIgnoreTime - deltaF);
|
||||
}
|
||||
else
|
||||
{
|
||||
CollisionMask = 0b0100_0001;
|
||||
}
|
||||
MoveAndSlide();
|
||||
|
||||
_jumpAllowedTime = Mathf.Max(0, _jumpAllowedTime - deltaF);
|
||||
|
|
@ -168,6 +202,20 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
}
|
||||
}
|
||||
|
||||
public void EnteredWater(Node2D body)
|
||||
{
|
||||
if (_isInWater) return;
|
||||
_isInWater = true;
|
||||
GD.Print("Entered water!");
|
||||
}
|
||||
|
||||
public void LeftWater(Node2D body)
|
||||
{
|
||||
if (!_isInWater || SubmersedSensor.HasOverlappingBodies()) return;
|
||||
GD.Print("Left water!");
|
||||
_isInWater = false;
|
||||
}
|
||||
|
||||
private void AdjustFacing()
|
||||
{
|
||||
if (_currentDirection.X < 0)
|
||||
|
|
@ -211,7 +259,12 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
|
||||
if (input.Event.IsAction("jump"))
|
||||
{
|
||||
if (
|
||||
if (input.Event.IsPressed() && IsInputVecDown(input.Direction) && IsOnFloor())
|
||||
{
|
||||
inputFound = true;
|
||||
DropDown();
|
||||
}
|
||||
else if (
|
||||
input.Event.IsPressed()
|
||||
&& _jumpAllowedTime > 0
|
||||
&& (!IsOnFloor() || !IsInputVecDown(input.Direction)))
|
||||
|
|
@ -243,6 +296,11 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
}
|
||||
}
|
||||
|
||||
private void DropDown()
|
||||
{
|
||||
PlatformIgnoreTime = 0.1f;
|
||||
}
|
||||
|
||||
private void GroundJump()
|
||||
{
|
||||
AdjustFacing();
|
||||
|
|
@ -279,6 +337,12 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
{
|
||||
return Mathf.Abs(vec.AngleTo(Vector2.Down)) < DownInputAngle && vec.Length() > 0.1f;
|
||||
}
|
||||
private bool IsInputVecSide(Vector2 vec)
|
||||
{
|
||||
return vec.Length() > 0.1f
|
||||
&& (Mathf.Abs(vec.AngleTo(Vector2.Left)) < SideInputAngle
|
||||
|| Mathf.Abs(vec.AngleTo(Vector2.Right)) < SideInputAngle) ;
|
||||
}
|
||||
|
||||
private void OnEnemyHit(Hitbox hitbox, Node2D enemy)
|
||||
{
|
||||
|
|
@ -306,4 +370,41 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
public void OnHitboxAdded(Hitbox hitbox) => hitbox.BodyHit += OnEnemyHit;
|
||||
public void OnHitboxRemoved(Hitbox hitbox) => hitbox.BodyHit -= OnEnemyHit;
|
||||
IHitboxOwner IProvide<IHitboxOwner>.Value() => this;
|
||||
|
||||
|
||||
[Meta]
|
||||
public sealed partial class Logic : AutoBlock
|
||||
{
|
||||
public sealed record Data
|
||||
{
|
||||
}
|
||||
|
||||
public Logic()
|
||||
{
|
||||
Set(new Data());
|
||||
Preallocate<Root>();
|
||||
}
|
||||
|
||||
public static class Input
|
||||
{
|
||||
public readonly record struct OnPhysicsProcess(double Delta);
|
||||
}
|
||||
|
||||
[Meta, StateDiagram]
|
||||
public abstract partial record Root : LogicBlockState
|
||||
{
|
||||
[Meta]
|
||||
public sealed partial record Grounded : Root
|
||||
{
|
||||
}
|
||||
[Meta]
|
||||
public sealed partial record Airborne : Root
|
||||
{
|
||||
}
|
||||
[Meta]
|
||||
public sealed partial record Diving : Root
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
BIN
src/player/player.aseprite
(Stored with Git LFS)
BIN
src/player/player.aseprite
(Stored with Git LFS)
Binary file not shown.
|
|
@ -8,6 +8,9 @@
|
|||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_jiejy"]
|
||||
size = Vector2(10, 28)
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_o822w"]
|
||||
size = Vector2(10, 12)
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_244u8"]
|
||||
size = Vector2(27.5, 20)
|
||||
|
||||
|
|
@ -45,7 +48,7 @@ tracks/1/keys = {
|
|||
tracks/2/type = "value"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath("Body/FrontKick/CollisionShape2D:disabled")
|
||||
tracks/2/path = NodePath("Body/FrontKickHitBox/CollisionShape2D:disabled")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
|
|
@ -57,7 +60,7 @@ tracks/2/keys = {
|
|||
tracks/3/type = "value"
|
||||
tracks/3/imported = false
|
||||
tracks/3/enabled = true
|
||||
tracks/3/path = NodePath("Body/FrontKick/CollisionShape2D2:disabled")
|
||||
tracks/3/path = NodePath("Body/FrontKickHitBox/CollisionShape2D2:disabled")
|
||||
tracks/3/interp = 1
|
||||
tracks/3/loop_wrap = true
|
||||
tracks/3/keys = {
|
||||
|
|
@ -98,7 +101,7 @@ tracks/1/keys = {
|
|||
tracks/2/type = "method"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath("Body/FrontKick")
|
||||
tracks/2/path = NodePath("Body/FrontKickHitBox")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
|
|
@ -115,7 +118,7 @@ tracks/2/keys = {
|
|||
tracks/3/type = "value"
|
||||
tracks/3/imported = false
|
||||
tracks/3/enabled = true
|
||||
tracks/3/path = NodePath("Body/FrontKick/CollisionShape2D:disabled")
|
||||
tracks/3/path = NodePath("Body/FrontKickHitBox/CollisionShape2D:disabled")
|
||||
tracks/3/interp = 1
|
||||
tracks/3/loop_wrap = true
|
||||
tracks/3/keys = {
|
||||
|
|
@ -127,7 +130,7 @@ tracks/3/keys = {
|
|||
tracks/4/type = "value"
|
||||
tracks/4/imported = false
|
||||
tracks/4/enabled = true
|
||||
tracks/4/path = NodePath("Body/FrontKick/CollisionShape2D2:disabled")
|
||||
tracks/4/path = NodePath("Body/FrontKickHitBox/CollisionShape2D2:disabled")
|
||||
tracks/4/interp = 1
|
||||
tracks/4/loop_wrap = true
|
||||
tracks/4/keys = {
|
||||
|
|
@ -191,13 +194,30 @@ tracks/0/keys = {
|
|||
"values": [5]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_244u8"]
|
||||
resource_name = "water_idle"
|
||||
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": [15]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_rgyib"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_yw30f"),
|
||||
&"front_kick": SubResource("Animation_g6k8r"),
|
||||
&"idle": SubResource("Animation_qjkh3"),
|
||||
&"run": SubResource("Animation_boad6"),
|
||||
&"wall_hold": SubResource("Animation_rgyib")
|
||||
&"wall_hold": SubResource("Animation_rgyib"),
|
||||
&"water_idle": SubResource("Animation_244u8")
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_qjkh3"]
|
||||
|
|
@ -259,6 +279,7 @@ graph_offset = Vector2(-59.670364, -27)
|
|||
physics_interpolation_mode = 1
|
||||
auto_translate_mode = 1
|
||||
collision_layer = 2
|
||||
collision_mask = 65
|
||||
floor_constant_speed = true
|
||||
floor_max_angle = 0.24783675
|
||||
script = ExtResource("1_244u8")
|
||||
|
|
@ -267,10 +288,21 @@ script = ExtResource("1_244u8")
|
|||
position = Vector2(0, -14)
|
||||
shape = SubResource("RectangleShape2D_jiejy")
|
||||
|
||||
[node name="SubmersedSensor" type="Area2D" parent="." unique_id=1595680866]
|
||||
unique_name_in_owner = true
|
||||
collision_layer = 0
|
||||
collision_mask = 32
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="SubmersedSensor" unique_id=1538343174]
|
||||
position = Vector2(0, -21)
|
||||
shape = SubResource("RectangleShape2D_o822w")
|
||||
debug_color = Color(0, 0.5282814, 0.99723786, 0.41960785)
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="." unique_id=1975474809]
|
||||
position = Vector2(0, -16)
|
||||
process_callback = 0
|
||||
limit_enabled = false
|
||||
position_smoothing_enabled = true
|
||||
|
||||
[node name="PointLight2D" type="PointLight2D" parent="." unique_id=1795955896]
|
||||
position = Vector2(0, -16)
|
||||
|
|
@ -283,7 +315,7 @@ unique_name_in_owner = true
|
|||
texture = ExtResource("2_yw30f")
|
||||
offset = Vector2(0, -24)
|
||||
hframes = 8
|
||||
vframes = 2
|
||||
vframes = 3
|
||||
metadata/_aseprite_wizard_interface_config_ = {
|
||||
"animation_section": false,
|
||||
"layer_section": false,
|
||||
|
|
@ -318,7 +350,7 @@ metadata/_aseprite_wizard_source_file_hash_ = "61168df4a163c039cfaab97f4fccb905"
|
|||
unique_name_in_owner = true
|
||||
position = Vector2(0, -14)
|
||||
|
||||
[node name="FrontKick" type="Area2D" parent="Body" unique_id=1918418417]
|
||||
[node name="FrontKickHitBox" type="Area2D" parent="Body" unique_id=1918418417]
|
||||
process_mode = 4
|
||||
visible = false
|
||||
position = Vector2(0, -16)
|
||||
|
|
@ -326,12 +358,12 @@ collision_layer = 8
|
|||
collision_mask = 4
|
||||
script = ExtResource("4_244u8")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Body/FrontKick" unique_id=2048987579]
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Body/FrontKickHitBox" unique_id=2048987579]
|
||||
position = Vector2(5, 7)
|
||||
shape = SubResource("RectangleShape2D_244u8")
|
||||
debug_color = Color(0.99430805, 0, 0.2314094, 0.41960785)
|
||||
|
||||
[node name="CollisionShape2D2" type="CollisionShape2D" parent="Body/FrontKick" unique_id=734742131]
|
||||
[node name="CollisionShape2D2" type="CollisionShape2D" parent="Body/FrontKickHitBox" unique_id=734742131]
|
||||
position = Vector2(16, -2)
|
||||
shape = SubResource("RectangleShape2D_5f2sf")
|
||||
debug_color = Color(0.99430805, 0, 0.2314094, 0.41960785)
|
||||
|
|
@ -346,3 +378,6 @@ root_node = NodePath("%AnimationTree/../..")
|
|||
tree_root = SubResource("AnimationNodeStateMachine_yllr7")
|
||||
advance_expression_base_node = NodePath("../..")
|
||||
anim_player = NodePath("..")
|
||||
|
||||
[connection signal="body_entered" from="SubmersedSensor" to="." method="EnteredWater"]
|
||||
[connection signal="body_exited" from="SubmersedSensor" to="." method="LeftWater"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue