diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index 626f732..7ef5ac6 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -49,6 +49,15 @@ namespace ZoFo.GameCore InputMovementDirection = AppManager.Instance.InputManager.InputMovementDirection, InputAttackDirection = AppManager.Instance.InputManager.InputAttackDirection }); + + }; + AppManager.Instance.InputManager.OnInteract += () => + { + networkManager.AddData(new UpdateInputInteraction() { }); + }; + AppManager.Instance.InputManager.ShootEvent += () => + { + networkManager.AddData(new UpdateInputShoot() { }); }; } @@ -77,6 +86,7 @@ namespace ZoFo.GameCore List gameObjects = new List(); List players = new List(); List stopObjects = new List(); + /// /// Клиент должен обнговлять игру анимаций /// @@ -88,6 +98,8 @@ namespace ZoFo.GameCore AppManager.Instance.debugHud.Set("GameTime", gameTime.TotalGameTime.ToString()); gameObjects[i].UpdateAnimations(); } + + networkManager.SendData();//set to ticks } internal void Draw(SpriteBatch spriteBatch) { diff --git a/ZoFo/GameCore/GameManagers/InputManager.cs b/ZoFo/GameCore/GameManagers/InputManager.cs index dd13535..c390273 100644 --- a/ZoFo/GameCore/GameManagers/InputManager.cs +++ b/ZoFo/GameCore/GameManagers/InputManager.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Reflection.Metadata.Ecma335; using System.Text; using System.Threading.Tasks; +using ZoFo.GameCore.GUI; namespace ZoFo.GameCore.GameManagers { @@ -27,9 +28,6 @@ namespace ZoFo.GameCore.GameManagers private Vector2 prevInputMovementDirection; public Vector2 InputAttackDirection; private Vector2 prevInputAttackDirection; - - public event Action TalkEvent; - public ScopeState currentScopeState; // Положение оружия. Left, Right, Straight, Back, StraightLeft, StraightRight, BackLeft, BackRight. private ScopeState prevCurrentScopeState; private bool _cheatsEnabled = false; @@ -48,6 +46,7 @@ namespace ZoFo.GameCore.GameManagers public InputManager() { + isInteract = true; InputMovementDirection = new Vector2(0, 0); InputAttackDirection = new Vector2(0, 0); this.isShoot = false; @@ -173,38 +172,46 @@ namespace ZoFo.GameCore.GameManagers if (keyBoardState.IsKeyDown(Keys.Up) || keyBoardState.IsKeyDown(Keys.W)) { currentScopeState = ScopeState.Straight; + InputMovementDirection = new Vector2(0, -1); } else if (keyBoardState.IsKeyDown(Keys.Down) || keyBoardState.IsKeyDown(Keys.S)) { currentScopeState = ScopeState.Back; + InputMovementDirection = new Vector2(0, 1); } else if(keyBoardState.IsKeyDown(Keys.Left) || keyBoardState.IsKeyDown(Keys.A)) { currentScopeState = ScopeState.Left; + InputMovementDirection = new Vector2(-1, 0); } else if(keyBoardState.IsKeyDown(Keys.Right) || keyBoardState.IsKeyDown(Keys.D)) { currentScopeState = ScopeState.Right; + InputMovementDirection = new Vector2(1, 0); } else if(keyBoardState.IsKeyDown(Keys.Right) && keyBoardState.IsKeyDown(Keys.Up) || keyBoardState.IsKeyDown(Keys.D) && keyBoardState.IsKeyDown(Keys.W)) { currentScopeState = ScopeState.StraightRight; + InputMovementDirection = new Vector2(1, 1); } else if(keyBoardState.IsKeyDown(Keys.Left) && keyBoardState.IsKeyDown(Keys.Up) || keyBoardState.IsKeyDown(Keys.A) && keyBoardState.IsKeyDown(Keys.W)) { currentScopeState = ScopeState.StraightLeft; + InputMovementDirection = new Vector2(-1, 1); } else if(keyBoardState.IsKeyDown(Keys.Right) && keyBoardState.IsKeyDown(Keys.Down) || keyBoardState.IsKeyDown(Keys.D) && keyBoardState.IsKeyDown(Keys.S)) { currentScopeState = ScopeState.BackRight; + InputMovementDirection = new Vector2(1, -1); } else if(keyBoardState.IsKeyDown(Keys.Left) && keyBoardState.IsKeyDown(Keys.Down) || keyBoardState.IsKeyDown(Keys.A) && keyBoardState.IsKeyDown(Keys.S)) { currentScopeState = ScopeState.BackLeft; + InputMovementDirection = new Vector2(-1, -1); } #endregion @@ -247,6 +254,8 @@ namespace ZoFo.GameCore.GameManagers prevInputAttackDirection = InputAttackDirection; prevCurrentScopeState = currentScopeState; #endregion + + DebugHUD.Instance.Set("controls", currentScopeState.ToString()); } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs index f75fb9a..f24e951 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs @@ -42,6 +42,13 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager public void SendData() { + for (int i = 0; i < updates.Count; i++) + { + + AppManager.Instance.server.ProcessIUpdateData(updates[i]); + } + updates.Clear(); + return;// TODO remove byte[] bytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(updates)); //нужно сериализовать socket.Send(bytes); } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateInputInteraction.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateInputInteraction.cs new file mode 100644 index 0000000..243fce0 --- /dev/null +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateInputInteraction.cs @@ -0,0 +1,12 @@ +using System; +using ZoFo.GameCore.GameManagers.NetworkManager; + +namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer; + +/// +/// уведомляет сервер о том, что игрок взаимодействует +/// +public class UpdateInputInteraction : UpdateData +{ + public UpdateInputInteraction() { UpdateType = "UpdateInputInteraction"; } +} diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateShootInteraction.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateShootInteraction.cs new file mode 100644 index 0000000..d5ef20c --- /dev/null +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateShootInteraction.cs @@ -0,0 +1,9 @@ +using System; +using ZoFo.GameCore.GameManagers.NetworkManager.Updates; + +namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer; + +public class UpdateInputShoot : UpdateData +{ + public UpdateInputShoot() { UpdateType = "UpdateInputShoot"; } +} diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteraction.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteraction.cs index 6f4711d..25848ca 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteraction.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteraction.cs @@ -2,6 +2,8 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; /// /// При попытке взаимодействия с объектом +/// отправляет пользователю разрешение на взаимодействие +/// TODO: Вероятно убрать(обсудить) /// public class UpdateInteraction : UpdateData { diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs index bc504f9..e0dcb39 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs @@ -15,7 +15,7 @@ namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies public Zombie(Vector2 position) : base(position) { health = 5; - speed =2; + speed =5; collisionComponent.stopRectangle = new Rectangle(0, 0, 100, 100); graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 100, 100); } diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs index 42d89c2..b6d43be 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs @@ -18,17 +18,19 @@ public class Player : LivingEntity /// /// Факт того, что плеер в этом апдейте пытается стрелять /// - public bool IsTryingToShoot { get; set; } + //public bool IsTryingToShoot { get; set; } private float speed; private int health; public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List { "player_look_down" }, "player_look_down"); private LootData lootData; + //public bool isTryingToInteract { get; set; } public Player(Vector2 position) : base(position) { - //InputWeaponRotation = new Vector2(0, 0); - //InputPlayerRotation = new Vector2(0, 0); graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 100, 100); collisionComponent.stopRectangle = new Rectangle(0, 0, 100, 100); + speed = 10; + //isTryingToInteract = false; + //IsTryingToShoot = false; } @@ -37,20 +39,21 @@ public class Player : LivingEntity MovementLogic(); } - float t; public void MovementLogic() { - //velocity.X = 3+(float)Math.Sin(t); - t++; - if (InputPlayerRotation.X > 0.9) - { - } - if (Keyboard.GetState().IsKeyDown(Keys.D)) velocity.X = 5; - if (Keyboard.GetState().IsKeyDown(Keys.A)) velocity.X = -5; - if (Keyboard.GetState().IsKeyDown(Keys.S)) velocity.Y = 5; - if (Keyboard.GetState().IsKeyDown(Keys.W)) velocity.Y = -5; + velocity = InputPlayerRotation * speed; } public void HandleNewInput(UpdateInput updateInput) + { + InputPlayerRotation = updateInput.InputMovementDirection; + InputWeaponRotation = updateInput.InputAttackDirection; + + } + public void HandleInteract(UpdateInputInteraction updateInputInteraction) + { + //isTryingToInteract = true; + } + public void HandleShoot(UpdateInputShoot updateInputShoot) { } diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index dbbfa94..1e4ec8d 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -12,6 +12,7 @@ using ZoFo.GameCore.GameManagers.CollisionManager; using ZoFo.GameCore.GameManagers.MapManager; using ZoFo.GameCore.GameManagers.NetworkManager; using ZoFo.GameCore.GameManagers.NetworkManager.Updates; +using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using ZoFo.GameCore.GameObjects; using ZoFo.GameCore.GameObjects.Entities; @@ -77,11 +78,17 @@ namespace ZoFo.GameCore break; case "UpdatePlayerParametrs": break; - case "UpdatePosition": + case "UpdateInput": + players[0].HandleNewInput(updateData as UpdateInput); break; case "UpdateTileCreated": break; - + case "UpdateInputInteraction": + players[0].HandleInteract(updateData as UpdateInputInteraction); + break; + case "UpdateInputShoot": + players[0].HandleShoot(updateData as UpdateInputShoot); + break; } } @@ -130,6 +137,9 @@ namespace ZoFo.GameCore //AppManager.Instance.server.RegisterGameObject(new EntittyForAnimationTests(new Vector2(0, 0))); AppManager.Instance.server.RegisterGameObject(new Player(new Vector2(740, 140))); AppManager.Instance.server.RegisterGameObject(new Zombie(new Vector2(1000, 1000))); + AppManager.Instance.server.RegisterGameObject(new Zombie(new Vector2(1300, 1000))); + AppManager.Instance.server.RegisterGameObject(new Zombie(new Vector2(1500, 1000))); + AppManager.Instance.server.RegisterGameObject(new Zombie(new Vector2(1700, 1000))); AppManager.Instance.server.RegisterGameObject(new Ammo(new Vector2(140, 440))); AppManager.Instance.server.RegisterGameObject(new Ammo(new Vector2(240, 440))); }