11using Godot ;
22using System ;
3+ using System . Diagnostics ;
34using System . Text . RegularExpressions ;
45using Godot . Collections ;
56using 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 ( )
0 commit comments