refactor: Removed Network Code From Paddle
This commit is contained in:
parent
89b756a615
commit
ea3c4a2d2a
|
@ -12,7 +12,7 @@ using Syntriax.Engine.Network.Abstract;
|
||||||
|
|
||||||
namespace Pong.Behaviours;
|
namespace Pong.Behaviours;
|
||||||
|
|
||||||
public class PaddleBehaviour(Keys Up, Keys Down, float High, float Low, float Speed) : NetworkBehaviour
|
public class PaddleBehaviour(Keys Up, Keys Down, float High, float Low, float Speed) : BehaviourOverride
|
||||||
{
|
{
|
||||||
private Keys Up { get; } = Up;
|
private Keys Up { get; } = Up;
|
||||||
private Keys Down { get; } = Down;
|
private Keys Down { get; } = Down;
|
||||||
|
@ -41,20 +41,13 @@ public class PaddleBehaviour(Keys Up, Keys Down, float High, float Low, float Sp
|
||||||
|
|
||||||
private void MovePaddle(Vector2D vectorToAdd)
|
private void MovePaddle(Vector2D vectorToAdd)
|
||||||
{
|
{
|
||||||
if (!LocalAssigned && !IsServer)
|
|
||||||
return;
|
|
||||||
|
|
||||||
GameObject.Transform.Position += vectorToAdd;
|
GameObject.Transform.Position += vectorToAdd;
|
||||||
|
|
||||||
NetDataWriter dataWriter = communicator.GetMessageWriter(this);
|
|
||||||
dataWriter.Put(Transform.Position);
|
|
||||||
communicator.Manager.SendToAll(dataWriter, LiteNetLib.DeliveryMethod.Unreliable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnFirstActiveFrame()
|
protected override void OnFirstActiveFrame()
|
||||||
{
|
{
|
||||||
if (!BehaviourController.TryGetBehaviour<IButtonInputs<Keys>>(out var behaviourResult))
|
BehaviourController.TryGetBehaviour<IButtonInputs<Keys>>(out var behaviourResult);
|
||||||
inputs = behaviourResult ?? BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
|
inputs = behaviourResult ?? throw new Exception($"{nameof(IButtonInputs<Keys>)} is missing on {GameObject.Name}.");
|
||||||
|
|
||||||
if (!GameObject.GameManager.TryFindBehaviour(out INetworkCommunicator? foundCommunicator))
|
if (!GameObject.GameManager.TryFindBehaviour(out INetworkCommunicator? foundCommunicator))
|
||||||
throw new Exception($"{nameof(INetworkCommunicator)} is missing on GameManager.");
|
throw new Exception($"{nameof(INetworkCommunicator)} is missing on GameManager.");
|
||||||
|
|
Loading…
Reference in New Issue