From 05dfb92babdc696c9cd849554713dffe64824003 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Mon, 29 Jul 2024 23:18:48 +0300 Subject: [PATCH] feat: Paddle Transform Over Network --- Game/Behaviours/PaddleBehaviour.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Game/Behaviours/PaddleBehaviour.cs b/Game/Behaviours/PaddleBehaviour.cs index eca82ff..e4bcf2c 100644 --- a/Game/Behaviours/PaddleBehaviour.cs +++ b/Game/Behaviours/PaddleBehaviour.cs @@ -60,16 +60,17 @@ public class PaddleBehaviour(Keys Up, Keys Down, float High, float Low, float Sp inputs.UnregisterOnRelease(Down, OnDownReleased); } - private void OnUpPressed(IButtonInputs inputs, Keys keys) { isUpPressed = true; SendData(new PaddleInputs() { IsUpPressed = isUpPressed, IsDownPressed = isDownPressed }); } - private void OnUpReleased(IButtonInputs inputs, Keys keys) { isUpPressed = false; SendData(new PaddleInputs() { IsUpPressed = isUpPressed, IsDownPressed = isDownPressed }); } - private void OnDownPressed(IButtonInputs inputs, Keys keys) { isDownPressed = true; SendData(new PaddleInputs() { IsUpPressed = isUpPressed, IsDownPressed = isDownPressed }); } - private void OnDownReleased(IButtonInputs inputs, Keys keys) { isDownPressed = false; SendData(new PaddleInputs() { IsUpPressed = isUpPressed, IsDownPressed = isDownPressed }); } + private void OnUpPressed(IButtonInputs inputs, Keys keys) { isUpPressed = true; SendData(new PaddleInputs() { IsUpPressed = isUpPressed, IsDownPressed = isDownPressed, PositionY = Transform.Position.Y }); } + private void OnUpReleased(IButtonInputs inputs, Keys keys) { isUpPressed = false; SendData(new PaddleInputs() { IsUpPressed = isUpPressed, IsDownPressed = isDownPressed, PositionY = Transform.Position.Y }); } + private void OnDownPressed(IButtonInputs inputs, Keys keys) { isDownPressed = true; SendData(new PaddleInputs() { IsUpPressed = isUpPressed, IsDownPressed = isDownPressed, PositionY = Transform.Position.Y }); } + private void OnDownReleased(IButtonInputs inputs, Keys keys) { isDownPressed = false; SendData(new PaddleInputs() { IsUpPressed = isUpPressed, IsDownPressed = isDownPressed, PositionY = Transform.Position.Y }); } public override void ReceiveData(T data) { if (data is not PaddleInputs paddleInputs) return; + Transform.Position = new(Transform.Position.X, paddleInputs.PositionY); isUpPressed = paddleInputs.IsUpPressed; isDownPressed = paddleInputs.IsDownPressed; } @@ -77,17 +78,20 @@ public class PaddleBehaviour(Keys Up, Keys Down, float High, float Low, float Sp [System.Serializable] public struct PaddleInputs : INetworkPacket { + public float PositionY { get; set; } public bool IsUpPressed { get; set; } public bool IsDownPressed { get; set; } public void Deserialize(NetDataReader reader) { + PositionY = reader.GetFloat(); IsUpPressed = reader.GetBool(); IsDownPressed = reader.GetBool(); } public void Serialize(NetDataWriter writer) { + writer.Put(PositionY); writer.Put(IsUpPressed); writer.Put(IsDownPressed); }