Skip to content

Commit adbc1cb

Browse files
authored
Merge pull request #7 from magarich228/dev
Наработки по скрипту игрока с dev.
2 parents c9edf6a + f346d0f commit adbc1cb

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
## TODO:
44
* Замена ui событий на кастомные.
5-
* Отрефачить код _Process + баги анимации после прыжка.
6-
* Передвижение в присяде.
5+
* Отрефачить код _Process.
76
* Фикс странной механики замедленного движения при зажатых ui_up, ui_down.
7+
* Фикс состояния Stand после прекращения передвижения в присяде.
88

99
![image](https://github.com/magarich228/TDP5/assets/78496868/e8e352f7-186e-45a4-aea9-f5b1e19b06db)

player/stickplayer.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Godot;
22
using System;
3+
using System.Diagnostics;
34
using System.Text.RegularExpressions;
45
using Godot.Collections;
56
using Tdp5.player;
@@ -9,23 +10,12 @@ public partial class stickplayer : CharacterBody2D
910
public const float Speed = 300.0f;
1011
public const float JumpVelocity = -500.0f;
1112

12-
public PlayerState State
13-
{
14-
get => _state;
15-
set
16-
{
17-
if (value != _state)
18-
{
19-
_state = value;
20-
Animate();
21-
}
22-
}
23-
}
13+
public PlayerState State { get; set; }
2414
public float Gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle();
2515

2616
private AnimationPlayer _animationPlayer;
2717
private Dictionary<PlayerState, string> _stateAnimations;
28-
private PlayerState _state;
18+
private Stopwatch _watch = new Stopwatch();
2919

3020
public override void _Ready()
3121
{
@@ -59,12 +49,14 @@ public override void _Ready()
5949

6050
public override void _PhysicsProcess(double delta)
6151
{
52+
var oldState = State;
6253
Vector2 velocity = Velocity;
6354

6455
if (IsOnFloor() && velocity.X.Equals(0) && !Input.IsActionPressed("ui_down"))
6556
{
57+
Console.WriteLine("stand");
6658
State = PlayerState.Stand;
67-
}
59+
} else { Console.WriteLine($"not stand ({State})"); }
6860

6961
if (!IsOnFloor())
7062
velocity.Y += Gravity * (float)delta;
@@ -92,17 +84,22 @@ public override void _PhysicsProcess(double delta)
9284
State = PlayerState.Run;
9385
}
9486

95-
if (velocity.Y != 0 && !Input.IsActionJustPressed("ui_down"))
87+
if (velocity.Y != 0 && !Input.IsActionPressed("ui_down"))
9688
{
97-
Console.WriteLine($"{velocity.Y}");
9889
State = PlayerState.Jump;
9990
}
10091

101-
if (Input.IsActionJustPressed("ui_down"))
92+
if (Input.IsActionPressed("ui_down"))
10293
{
10394
State = PlayerState.Sit;
10495
}
10596

97+
if (velocity.X != 0 && Input.IsActionPressed("ui_down") &&
98+
(Input.IsActionPressed("ui_left") || Input.IsActionPressed("ui_right")))
99+
{
100+
State = PlayerState.SitWalk;
101+
}
102+
106103
var localMousePosition = GetLocalMousePosition();
107104
var globalMousePosition = GetGlobalMousePosition();
108105

@@ -125,6 +122,12 @@ public override void _PhysicsProcess(double delta)
125122
Velocity = velocity;
126123

127124
MoveAndSlide();
125+
126+
if (State == PlayerState.Sit && oldState == PlayerState.SitWalk)
127+
_animationPlayer.Play("sit", fromEnd: true);
128+
129+
if (State != oldState)
130+
Animate();
128131
}
129132

130133
private void Animate()

player/stickplayer.tscn

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,18 @@ tracks/16/keys = {
215215
"update": 0,
216216
"values": [0.0]
217217
}
218+
tracks/17/type = "value"
219+
tracks/17/imported = false
220+
tracks/17/enabled = true
221+
tracks/17/path = NodePath("CollisionShape2D2:scale")
222+
tracks/17/interp = 1
223+
tracks/17/loop_wrap = true
224+
tracks/17/keys = {
225+
"times": PackedFloat32Array(0),
226+
"transitions": PackedFloat32Array(1),
227+
"update": 0,
228+
"values": [Vector2(2.54, 2.4)]
229+
}
218230

219231
[sub_resource type="Animation" id="Animation_fcopi"]
220232
resource_name = "creep"
@@ -866,6 +878,7 @@ tracks/18/keys = {
866878

867879
[sub_resource type="Animation" id="Animation_4uhs2"]
868880
resource_name = "sit_walk"
881+
loop_mode = 1
869882
tracks/0/type = "value"
870883
tracks/0/imported = false
871884
tracks/0/enabled = true
@@ -1493,3 +1506,4 @@ shape = SubResource("CapsuleShape2D_ix8b3")
14931506
libraries = {
14941507
"": SubResource("AnimationLibrary_houuf")
14951508
}
1509+
next/RESET = &"sit"

0 commit comments

Comments
 (0)