@@ -15,8 +15,10 @@ public class ClientPlayer : OtherPlayer
1515 private Label LabelPosition { get ; set ; }
1616
1717 private float Speed = 250f ;
18- private Timer TimerNotifyServerProcessDelta { get ; set ; }
18+ private Timer NotifyServerPlayerDirection { get ; set ; }
1919 private float Delta { get ; set ; }
20+ private Direction DirectionHorizontal { get ; set ; }
21+ private Direction DirectionVertical { get ; set ; }
2022
2123 public override void _Ready ( )
2224 {
@@ -26,26 +28,20 @@ public override void _Ready()
2628
2729 if ( GameClient . Running )
2830 {
29- //await NotifyServerOfProcessDelta();
30-
31- if ( GameClient . IsHost )
32- {
33- /*TimerNotifyServerProcessDelta = new Timer(3000);
34- TimerNotifyServerProcessDelta.Elapsed += TimerNotifyServerProcessDeltaCallback;
35- TimerNotifyServerProcessDelta.AutoReset = true;
36- TimerNotifyServerProcessDelta.Enabled = true;*/
37- }
31+ NotifyServerPlayerDirection = new Timer ( 500 ) ;
32+ NotifyServerPlayerDirection . Elapsed += NotifyServerPlayerDirectionCallback ;
33+ NotifyServerPlayerDirection . AutoReset = true ;
34+ NotifyServerPlayerDirection . Enabled = true ;
3835 }
3936 }
4037
41- public async void TimerNotifyServerProcessDeltaCallback ( System . Object source , ElapsedEventArgs args ) =>
42- await NotifyServerOfProcessDelta ( ) ;
43-
44- private async Task NotifyServerOfProcessDelta ( ) =>
45- await GameClient . Send ( ClientPacketOpcode . ProcessDelta , new CPacketProcessDelta
46- {
47- Delta = Delta
38+ public async void NotifyServerPlayerDirectionCallback ( System . Object source , ElapsedEventArgs args )
39+ {
40+ await GameClient . Send ( ClientPacketOpcode . PlayerDirectionPressed , new CPacketPlayerDirectionPressed {
41+ DirectionHorizontal = DirectionHorizontal ,
42+ DirectionVertical = DirectionVertical
4843 } ) ;
44+ }
4945
5046 public override void _Process ( float delta )
5147 {
@@ -54,7 +50,7 @@ public override void _Process(float delta)
5450 HandleMovement ( delta ) ;
5551 }
5652
57- private async void HandleMovement ( float delta )
53+ private void HandleMovement ( float delta )
5854 {
5955 var dir = new Vector2 ( ) ;
6056
@@ -69,57 +65,33 @@ private async void HandleMovement(float delta)
6965
7066 Position += dir * Speed * delta ;
7167
72- await SendDirection ( ) ;
68+ UpdateDirectionPressed ( ) ;
7369 }
7470
75- private async Task SendDirection ( )
71+ private void UpdateDirectionPressed ( )
7672 {
7773 if ( ! GameClient . Running )
7874 return ;
7975
8076 // PRESSED
8177 if ( Input . IsActionJustPressed ( "ui_left" ) )
82- await GameClient . Send ( ClientPacketOpcode . PlayerDirectionPressed , new CPacketPlayerDirectionPressed
83- {
84- Direction = Direction . West
85- } ) ;
78+ DirectionHorizontal = Direction . West ;
8679 if ( Input . IsActionJustPressed ( "ui_right" ) )
87- await GameClient . Send ( ClientPacketOpcode . PlayerDirectionPressed , new CPacketPlayerDirectionPressed
88- {
89- Direction = Direction . East
90- } ) ;
80+ DirectionHorizontal = Direction . East ;
9181 if ( Input . IsActionJustPressed ( "ui_up" ) )
92- await GameClient . Send ( ClientPacketOpcode . PlayerDirectionPressed , new CPacketPlayerDirectionPressed
93- {
94- Direction = Direction . North
95- } ) ;
82+ DirectionVertical = Direction . North ;
9683 if ( Input . IsActionJustPressed ( "ui_down" ) )
97- await GameClient . Send ( ClientPacketOpcode . PlayerDirectionPressed , new CPacketPlayerDirectionPressed
98- {
99- Direction = Direction . South
100- } ) ;
84+ DirectionVertical = Direction . South ;
10185
10286 // RELEASED
10387 if ( Input . IsActionJustReleased ( "ui_left" ) )
104- await GameClient . Send ( ClientPacketOpcode . PlayerDirectionReleased , new CPacketPlayerDirectionReleased
105- {
106- Direction = Direction . West
107- } ) ;
88+ DirectionHorizontal = Direction . None ;
10889 if ( Input . IsActionJustReleased ( "ui_right" ) )
109- await GameClient . Send ( ClientPacketOpcode . PlayerDirectionReleased , new CPacketPlayerDirectionReleased
110- {
111- Direction = Direction . East
112- } ) ;
90+ DirectionHorizontal = Direction . None ;
11391 if ( Input . IsActionJustReleased ( "ui_up" ) )
114- await GameClient . Send ( ClientPacketOpcode . PlayerDirectionReleased , new CPacketPlayerDirectionReleased
115- {
116- Direction = Direction . North
117- } ) ;
92+ DirectionVertical = Direction . None ;
11893 if ( Input . IsActionJustReleased ( "ui_down" ) )
119- await GameClient . Send ( ClientPacketOpcode . PlayerDirectionReleased , new CPacketPlayerDirectionReleased
120- {
121- Direction = Direction . South
122- } ) ;
94+ DirectionVertical = Direction . None ;
12395 }
12496
12597 public void SetHealth ( int v )
0 commit comments