From 226a5a5ccd479feeed77839a7a17025632d00192 Mon Sep 17 00:00:00 2001 From: PetrKu09 Date: Fri, 16 Aug 2024 11:37:43 +0300 Subject: [PATCH 01/11] Add Register Collision --- .../CollisionManager/CollectionComponent.cs | 6 ++++++ .../CollisionManager/CollisionComponent.cs | 7 ++++++- .../CollisionManager/CollisionManager.cs | 12 +++++++----- 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 ZoFo/GameCore/GameManagers/CollisionManager/CollectionComponent.cs diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollectionComponent.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollectionComponent.cs new file mode 100644 index 0000000..7143312 --- /dev/null +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollectionComponent.cs @@ -0,0 +1,6 @@ +namespace ZoFo.GameCore.GameManagers.CollisionManager +{ + public class CollectionComponent + { + } +} \ No newline at end of file diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs index 755fc11..00ee287 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs @@ -13,7 +13,7 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager { //поля public Rectangle Bounds { get; set; } - + //остановлен ли перс bool doesStop; Rectangle stopRectangle; @@ -30,6 +30,11 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager Bounds = new Rectangle(x, y, width, height); } + public CollisionComponent(Rectangle bounds) + { + Bounds = bounds; + } + //events public event EventHandler OnTriggerEnter; diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs index 8cf63f2..81bc36e 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs @@ -19,12 +19,13 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager - public static bool CheckComponentCollision(List collisionComponents, CollisionComponent component) + public bool CheckComponentCollision(List collisionComponents, CollisionComponent component) { foreach (var collisionComponent in collisionComponents) { if (component.Bounds.IntersectsWith(collisionComponent.Bounds)) { + Register(component); return true; } } @@ -47,10 +48,11 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager //} - //public void Register(Rectangle rectangle) - //{ - - //} + public void Register(CollisionComponent component) + { + CollisionComponent.Add(component); + } + } From 9882de93087290645b5af0c6a5b277ec2dd0fbc8 Mon Sep 17 00:00:00 2001 From: PetrKu09 Date: Fri, 16 Aug 2024 19:24:54 +0300 Subject: [PATCH 02/11] Add Register Collision v2 --- .../CollisionManager/CollisionComponent.cs | 5 +-- .../CollisionManager/CollisionManager.cs | 35 +++++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs index 00ee287..cbef012 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs @@ -11,10 +11,11 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager { public class CollisionComponent { - //поля + //==ПОЛЯ== + + public GameObject gameObject { get; set; } public Rectangle Bounds { get; set; } - //остановлен ли перс bool doesStop; Rectangle stopRectangle; diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs index 81bc36e..c8905f8 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs @@ -14,18 +14,21 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager { public class CollisionManager { - public List CollisionComponent; - public List TriggerComponent; + //листики + + public List ObjectsWithCollisions; + public List EntitiesWithMovements; + public List ObjectsWithTriggers; - + //чекаем коллизии в листе public bool CheckComponentCollision(List collisionComponents, CollisionComponent component) { - foreach (var collisionComponent in collisionComponents) + foreach (var collision in collisionComponents) { - if (component.Bounds.IntersectsWith(collisionComponent.Bounds)) + if (component.Bounds.IntersectsWith(collision.Bounds)) { - Register(component); + //Register(component, ); return true; } } @@ -33,24 +36,28 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager return false; } - public void UpdateComponentCollision(List collisionComponents) + //обновление позиций + public void UpdateObjectPosition(List collisionComponents, CollisionComponent component) { - + } - public void UpdatePositions() - { - - } + //получение объекта на поле(карте) //public void GetObjectInArea(Rectangle area) //{ //} - public void Register(CollisionComponent component) + + //регистрация компонента(его коллизии) + public void Register(CollisionComponent component, GameObject gameObject) { - CollisionComponent.Add(component); + if (component.gameObject is Entity) + { + ObjectsWithCollisions.Add(component); + + } } From a644d6c02ab7d70ea7ee49e56cba5956de9ed39c Mon Sep 17 00:00:00 2001 From: rawer470 Date: Sat, 17 Aug 2024 01:18:46 +0300 Subject: [PATCH 03/11] WorkServerWithGUI --- ZoFo/GameCore/Client.cs | 6 ++-- ZoFo/GameCore/GUI/SelectModeMenu.cs | 13 +-------- ZoFo/GameCore/GUI/SelectingServerGUI.cs | 9 ++++-- ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs | 11 ++++---- .../NetworkManager/ClientNetworkManager.cs | 6 ++-- .../NetworkManager/ServerNetworkManager.cs | 28 ++++++++++++++----- ZoFo/GameCore/Server.cs | 5 ++-- 7 files changed, 45 insertions(+), 33 deletions(-) diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index 94e27a0..3a3216e 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -43,9 +43,9 @@ namespace ZoFo.GameCore } public void GameEndedUnexpectedly() { } - public void JoinRoom(string ip) + public void JoinRoom(string ip,int port) { - networkManager.JoinRoom(ip); + networkManager.JoinRoom(ip,port); } public void JoinYourself() { networkManager.JoinYourself(); } @@ -66,7 +66,7 @@ namespace ZoFo.GameCore } } - internal void GotData(IUpdateData update) + internal void GotData(UpdateData update) { if (update is UpdateTileCreated) { diff --git a/ZoFo/GameCore/GUI/SelectModeMenu.cs b/ZoFo/GameCore/GUI/SelectModeMenu.cs index 2ddf7f4..6ae2edc 100644 --- a/ZoFo/GameCore/GUI/SelectModeMenu.cs +++ b/ZoFo/GameCore/GUI/SelectModeMenu.cs @@ -41,12 +41,8 @@ public class SelectModeMenu : AbstractGUI // single Server server = new Server(); Client client = new Client(); -<<<<<<< HEAD server.CreateRoom(1); client.JoinYourself(); - -======= ->>>>>>> e9698a8669e52b8738987a7a6ccb79c6726f91ac AppManager.Instance.SetServer(server); AppManager.Instance.SetClient(client); AppManager.Instance.ChangeState(GameState.HostPlaying); @@ -74,14 +70,7 @@ public class SelectModeMenu : AbstractGUI { AppManager.Instance.SetGUI(new SelectingServerGUI()); // multi - Server server = new Server(); //Server Logic MultiPlayer - Client client = new Client(); - server.CreateRoom(5); - client.JoinRoom("127.0.0.1"); //указать айпишник - AppManager.Instance.SetServer(server); - AppManager.Instance.SetClient(client); - string key = client.IsConnected.ToString(); - AppManager.Instance.debugHud.Set(key, "MultiPlayer"); + // ваш код здесь }; Elements.Add(optionButton); diff --git a/ZoFo/GameCore/GUI/SelectingServerGUI.cs b/ZoFo/GameCore/GUI/SelectingServerGUI.cs index a108a29..ad36b4f 100644 --- a/ZoFo/GameCore/GUI/SelectingServerGUI.cs +++ b/ZoFo/GameCore/GUI/SelectingServerGUI.cs @@ -79,10 +79,15 @@ public class SelectingServerGUI : AbstractGUI }; hostButton.LeftButtonPressed += () => { - AppManager.Instance.SetGUI(new WaitingForPlayersGUI(true)); - // host + // host + Server server = new Server(); //Server Logic MultiPlayer + server.CreateRoom(5); + AppManager.Instance.SetServer(server); + string key = server.MyIp; + AppManager.Instance.debugHud.Set(key, "MultiPlayer"); // ваш код здесь + AppManager.Instance.SetGUI(new WaitingForPlayersGUI(true)); }; Elements.Add(hostButton); diff --git a/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs b/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs index 5c9250d..4c5c6b5 100644 --- a/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs +++ b/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs @@ -17,6 +17,7 @@ public class WaitingForPlayersGUI : AbstractGUI { private DrawableUIElement menuBackground; private bool isHost; + private Label ip; public WaitingForPlayersGUI(bool isHost) { @@ -26,13 +27,13 @@ public class WaitingForPlayersGUI : AbstractGUI { int width = AppManager.Instance.CurentScreenResolution.X; int height = AppManager.Instance.CurentScreenResolution.Y; - + menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures\\GUI\\background\\Waiting" }; Elements.Add(menuBackground); menuBackground.LoadTexture(AppManager.Instance.Content); - - Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 7, (int)(width / 4), (int)(height / 20)), text = "Waiting", fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font"}); - + // string pcIp = + ip = new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 7, (int)(width / 4), (int)(height / 20)), text = AppManager.Instance.server.MyIp, fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font3" }; + Elements.Add(ip); if (isHost) { Button startButton = new Button(Manager) @@ -47,7 +48,7 @@ public class WaitingForPlayersGUI : AbstractGUI startButton.LeftButtonPressed += () => { // start - + // ваш код здесь }; Elements.Add(startButton); diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs index c178154..12ad84d 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs @@ -15,7 +15,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager { public class ClientNetworkManager { - private int port = 7632; + private int port = 0; private EndPoint endPoint; private Socket socket; List updates = new List(); @@ -60,13 +60,14 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager /// /// /// - public void JoinRoom(string ip) // multyplayer + public void JoinRoom(string ip, int port) // multyplayer { endPoint = new IPEndPoint(IPAddress.Parse(ip), port); socket.Connect(endPoint); SendData(); Thread listen = new Thread(StartListening); + listen.IsBackground = true; listen.Start(); } @@ -79,6 +80,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager socket.Connect(endPoint); SendData(); Thread listen = new Thread(StartListening); + listen.IsBackground = true; listen.Start(); } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs index 0686800..dbe149d 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs @@ -16,16 +16,17 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager { public class ServerNetworkManager { - private IPAddress ip =IPAddress.Parse("127.0.0.1"); //IPAddress.Any - private int port = 7632; + private IPAddress ip = IPAddress.Parse("127.0.0.1"); + private const int port = 0; private IPEndPoint endPoint; private Socket socket; private List clients; - public List updates; + public List updates; public delegate void OnDataSend(string data); public event OnDataSend GetDataSend; // event Dictionary managerThread; Thread serverTheread; + public IPEndPoint InfoConnect => endPoint; public ServerNetworkManager() { Init(); } @@ -34,6 +35,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager /// private void Init() { + ip = GetIp(); endPoint = new IPEndPoint(ip, port); socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); managerThread = new Dictionary(); @@ -43,10 +45,21 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager socket.Bind(endPoint); } + /// + /// Получает IP устройства + /// + /// + public static IPAddress GetIp() + { + string hostName = Dns.GetHostName(); // Retrive the Name of HOST + string myIP = Dns.GetHostByName(hostName).AddressList[1].ToString();// Get the IP + return IPAddress.Parse(myIP); + } + /// /// отправляет клиенту Data /// - public void SendData() + public void SendData() { for (int i = 0; i < updates.Count; i++) { @@ -76,7 +89,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager /// /// По сути конец игры и отключение игроков /// - public void CloseConnection() + public void CloseConnection() { foreach (var item in clients) { @@ -104,11 +117,11 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager public void Start(object players) { serverTheread = new Thread(StartWaitingForPlayers); + serverTheread.IsBackground = true; serverTheread.Start(players); } //Потоки Клиентов - /// /// Слушает игроков, которые хотят подключиться /// @@ -116,12 +129,13 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager public void StartWaitingForPlayers(object players) { int playNumber = (int)players; - + socket.Listen(playNumber); for (int i = 0; i < playNumber; i++) { Socket client = socket.Accept(); Thread thread = new Thread(StartListening); + thread.IsBackground = true; thread.Start(client); managerThread.Add(client, thread); clients.Add(client); //добавляем клиентов в лист diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index 72329d9..edc1022 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -19,6 +19,7 @@ namespace ZoFo.GameCore { private ServerNetworkManager networkManager; private int ticks = 0; + public string MyIp { get { return networkManager.InfoConnect.ToString(); } } public Server() { networkManager = new ServerNetworkManager(); @@ -29,7 +30,7 @@ namespace ZoFo.GameCore //TODO Comment pls public void OnDataSend(string data) { - List updateDatas = JsonSerializer.Deserialize>(data); + List updateDatas = JsonSerializer.Deserialize>(data); for (int i = 0; i < updateDatas.Count; i++) { ProcessIUpdateData(updateDatas[i]); @@ -39,7 +40,7 @@ namespace ZoFo.GameCore /// Обработка апдейтсов, которые нам прислал клиент /// /// - public void ProcessIUpdateData(IUpdateData updateData) + public void ProcessIUpdateData(UpdateData updateData) { //ТУТ Switch case будет честное слово From b1f24ce81bd99875cb60e3e7b27e784160632453 Mon Sep 17 00:00:00 2001 From: rawer470 Date: Sat, 17 Aug 2024 01:43:50 +0300 Subject: [PATCH 04/11] WorkServerWithGUI2 --- ZoFo/GameCore/Client.cs | 2 +- ZoFo/GameCore/GUI/SelectModeMenu.cs | 2 +- ZoFo/GameCore/GUI/SelectingServerGUI.cs | 2 +- ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs | 2 +- .../NetworkManager/ClientNetworkManager.cs | 14 +++++++++++--- .../NetworkManager/ServerNetworkManager.cs | 2 +- ZoFo/GameCore/Server.cs | 3 ++- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index 3a3216e..ed77e89 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -47,7 +47,7 @@ namespace ZoFo.GameCore { networkManager.JoinRoom(ip,port); } - public void JoinYourself() { networkManager.JoinYourself(); } + public void JoinYourself(int port) { networkManager.JoinYourself(port); } List mapObjects = new List(); diff --git a/ZoFo/GameCore/GUI/SelectModeMenu.cs b/ZoFo/GameCore/GUI/SelectModeMenu.cs index 6ae2edc..94a9500 100644 --- a/ZoFo/GameCore/GUI/SelectModeMenu.cs +++ b/ZoFo/GameCore/GUI/SelectModeMenu.cs @@ -42,7 +42,7 @@ public class SelectModeMenu : AbstractGUI Server server = new Server(); Client client = new Client(); server.CreateRoom(1); - client.JoinYourself(); + client.JoinYourself(server.MyIp.Port); AppManager.Instance.SetServer(server); AppManager.Instance.SetClient(client); AppManager.Instance.ChangeState(GameState.HostPlaying); diff --git a/ZoFo/GameCore/GUI/SelectingServerGUI.cs b/ZoFo/GameCore/GUI/SelectingServerGUI.cs index ad36b4f..1827f03 100644 --- a/ZoFo/GameCore/GUI/SelectingServerGUI.cs +++ b/ZoFo/GameCore/GUI/SelectingServerGUI.cs @@ -84,7 +84,7 @@ public class SelectingServerGUI : AbstractGUI Server server = new Server(); //Server Logic MultiPlayer server.CreateRoom(5); AppManager.Instance.SetServer(server); - string key = server.MyIp; + string key = server.MyIp.ToString(); AppManager.Instance.debugHud.Set(key, "MultiPlayer"); // ваш код здесь AppManager.Instance.SetGUI(new WaitingForPlayersGUI(true)); diff --git a/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs b/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs index 4c5c6b5..b0a808b 100644 --- a/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs +++ b/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs @@ -32,7 +32,7 @@ public class WaitingForPlayersGUI : AbstractGUI Elements.Add(menuBackground); menuBackground.LoadTexture(AppManager.Instance.Content); // string pcIp = - ip = new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 7, (int)(width / 4), (int)(height / 20)), text = AppManager.Instance.server.MyIp, fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font3" }; + ip = new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 7, (int)(width / 4), (int)(height / 20)), text = AppManager.Instance.server.MyIp.ToString(), fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font3" }; Elements.Add(ip); if (isHost) { diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs index 12ad84d..b55d8cb 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs @@ -16,12 +16,13 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager public class ClientNetworkManager { private int port = 0; - private EndPoint endPoint; + private IPEndPoint endPoint; private Socket socket; List updates = new List(); public delegate void OnDataSent(string Data); public event OnDataSent GetDataSent; // event public bool IsConnected { get { return socket.Connected; } } + public IPEndPoint InfoConnect => (IPEndPoint)socket.LocalEndPoint ?? endPoint; public ClientNetworkManager() { @@ -74,9 +75,9 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager /// /// создается одиночная комната к которой ты подключаешься /// - public void JoinYourself() // single player + public void JoinYourself(int port) // single player { - endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); + endPoint = new IPEndPoint(GetIp(), port); socket.Connect(endPoint); SendData(); Thread listen = new Thread(StartListening); @@ -84,6 +85,13 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager listen.Start(); } + public static IPAddress GetIp() + { + string hostName = Dns.GetHostName(); // Retrive the Name of HOST + string myIP = Dns.GetHostByName(hostName).AddressList[1].ToString();// Get the IP + return IPAddress.Parse(myIP); + } + //поток 2 public void StartListening() { diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs index dbe149d..9b6259e 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs @@ -26,7 +26,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager public event OnDataSend GetDataSend; // event Dictionary managerThread; Thread serverTheread; - public IPEndPoint InfoConnect => endPoint; + public IPEndPoint InfoConnect => (IPEndPoint)socket.LocalEndPoint ?? endPoint; public ServerNetworkManager() { Init(); } diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index edc1022..4b05b1d 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Text; using System.Text.Json; using System.Threading.Tasks; @@ -19,7 +20,7 @@ namespace ZoFo.GameCore { private ServerNetworkManager networkManager; private int ticks = 0; - public string MyIp { get { return networkManager.InfoConnect.ToString(); } } + public IPEndPoint MyIp { get { return networkManager.InfoConnect; } } public Server() { networkManager = new ServerNetworkManager(); From f6663bdd3c90065aaa38b7e8461587f419b9b4b4 Mon Sep 17 00:00:00 2001 From: rawer470 Date: Sat, 17 Aug 2024 10:50:05 +0300 Subject: [PATCH 05/11] StartCreateLogicMultiPlayer --- ZoFo/GameCore/GUI/SelectingServerGUI.cs | 15 ++++++++++++--- .../NetworkManager/ClientNetworkManager.cs | 10 ++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ZoFo/GameCore/GUI/SelectingServerGUI.cs b/ZoFo/GameCore/GUI/SelectingServerGUI.cs index 1827f03..531f9db 100644 --- a/ZoFo/GameCore/GUI/SelectingServerGUI.cs +++ b/ZoFo/GameCore/GUI/SelectingServerGUI.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Net; using System.Xml; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; @@ -62,10 +63,18 @@ public class SelectingServerGUI : AbstractGUI }; joinButton.LeftButtonPressed += () => { - AppManager.Instance.SetGUI(new WaitingForPlayersGUI(false)); + // join - - // ваш код здесь + Client client = new Client(); + var endpoint = ipBox.text.Split(':'); + int port; + if (int.TryParse(endpoint[1], out port)) + { + client.JoinRoom(endpoint[0], port); + AppManager.Instance.SetClient(client); + AppManager.Instance.SetGUI(new WaitingForPlayersGUI(false)); + } + // ваш код здесь }; Elements.Add(joinButton); Button hostButton = new Button(Manager) diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs index b55d8cb..2a93f71 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs @@ -71,6 +71,16 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager listen.IsBackground = true; listen.Start(); } + public void JoinRoom(IPEndPoint endPoint) // multyplayer + { + + this.endPoint = endPoint; + socket.Connect(endPoint); + SendData(); + Thread listen = new Thread(StartListening); + listen.IsBackground = true; + listen.Start(); + } /// /// создается одиночная комната к которой ты подключаешься From 557c3712226aff3f2acc2baa94d7f1440cba0d84 Mon Sep 17 00:00:00 2001 From: polten0 Date: Sat, 17 Aug 2024 10:50:20 +0300 Subject: [PATCH 06/11] fix1 --- ZoFo/Content/MapData/MapSession.tiled-session | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 ZoFo/Content/MapData/MapSession.tiled-session diff --git a/ZoFo/Content/MapData/MapSession.tiled-session b/ZoFo/Content/MapData/MapSession.tiled-session new file mode 100644 index 0000000..f0d6bf6 --- /dev/null +++ b/ZoFo/Content/MapData/MapSession.tiled-session @@ -0,0 +1,33 @@ +{ + "fileStates": { + "TileMaps/TileSets/TileSet 1.tsj": { + "scaleInDock": 1 + }, + "TileMaps/main.tmj": { + "scale": 0.25, + "selectedLayer": 0, + "viewCenter": { + "x": 1734, + "y": 1652 + } + }, + "TileSets/TileSet 1.tsj": { + "scaleInDock": 1, + "scaleInEditor": 1.5 + }, + "TileSets/WallSet.tsj": { + "scaleInDock": 1, + "scaleInEditor": 1 + } + }, + "openFiles": [ + "TileSets/TileSet 1.tsj", + "TileSets/WallSet.tsj", + "TileMaps/main.tmj" + ], + "recentFiles": [ + "TileMaps/main.tmj", + "TileSets/WallSet.tsj", + "TileSets/TileSet 1.tsj" + ] +} From bbc1a8857136928bb425a654d3cedec75c682e1b Mon Sep 17 00:00:00 2001 From: Mootfrost777 Date: Sat, 17 Aug 2024 10:58:46 +0300 Subject: [PATCH 07/11] Tried to fix map rendering issues --- ZoFo/GameCore/GameManagers/AppManager.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ZoFo/GameCore/GameManagers/AppManager.cs b/ZoFo/GameCore/GameManagers/AppManager.cs index afff18d..4381cfd 100644 --- a/ZoFo/GameCore/GameManagers/AppManager.cs +++ b/ZoFo/GameCore/GameManagers/AppManager.cs @@ -83,7 +83,6 @@ namespace ZoFo.GameCore.GameManagers currentGUI.LoadContent(); animationBuilder = new AnimationBuilder(); animationBuilder.LoadAnimations(); - } @@ -121,7 +120,9 @@ namespace ZoFo.GameCore.GameManagers currentGUI.Draw(_spriteBatch); debugHud.Draw(_spriteBatch); - _spriteBatch.Begin(); + + // Pointwrap + _spriteBatch.Begin(samplerState: SamplerState.PointWrap); switch (gamestate) { case GameState.ClientPlaying: From c1d2a6b210cd5bd9c22a2a07c006325cab43dc1d Mon Sep 17 00:00:00 2001 From: rawer470 Date: Sat, 17 Aug 2024 11:10:17 +0300 Subject: [PATCH 08/11] StartCreateLogicMultiPlayer2 --- ZoFo/GameCore/Client.cs | 2 +- ZoFo/GameCore/GameManagers/AppManager.cs | 10 +++++----- .../NetworkManager/ClientNetworkManager.cs | 2 +- .../NetworkManager/ServerNetworkManager.cs | 2 +- ZoFo/GameCore/Server.cs | 5 +++++ 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index 4bc324e..10f2ef0 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -39,7 +39,7 @@ namespace ZoFo.GameCore } public void GameEndedUnexpectedly() { } - public void JoinRoom(string ip) + public void JoinRoom(string ip, int port) { networkManager.JoinRoom(ip); } diff --git a/ZoFo/GameCore/GameManagers/AppManager.cs b/ZoFo/GameCore/GameManagers/AppManager.cs index afff18d..afda697 100644 --- a/ZoFo/GameCore/GameManagers/AppManager.cs +++ b/ZoFo/GameCore/GameManagers/AppManager.cs @@ -59,7 +59,7 @@ namespace ZoFo.GameCore.GameManagers SettingsManager.LoadSettings(); SoundManager = new SoundManager(); SoundManager.LoadSounds(); - + currentGUI = new MainMenuGUI(); debugHud = new DebugHUD(); @@ -70,7 +70,7 @@ namespace ZoFo.GameCore.GameManagers protected override void Initialize() { currentGUI.Initialize(); - debugHud.Initialize(); + debugHud.Initialize(); base.Initialize(); @@ -83,15 +83,15 @@ namespace ZoFo.GameCore.GameManagers currentGUI.LoadContent(); animationBuilder = new AnimationBuilder(); animationBuilder.LoadAnimations(); - + } protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || - Keyboard.GetState().IsKeyDown(Keys.Escape)) - Exit(); + Keyboard.GetState().IsKeyDown(Keys.Escape)) { server.CloseConnection(); Exit(); } + debugHud.Set("key", "value"); diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs index c178154..b8ba458 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs @@ -60,7 +60,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager /// /// /// - public void JoinRoom(string ip) // multyplayer + public void JoinRoom(string ip, int port) // multyplayer { endPoint = new IPEndPoint(IPAddress.Parse(ip), port); diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs index 658605e..eeaee4c 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs @@ -152,7 +152,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager string response = Encoding.UTF8.GetString(buff, 0, answ); GetDataSend(response); } - Thread.Sleep(-1); + Task.Delay(-1); } } diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index f374401..fe2e470 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -46,6 +46,11 @@ namespace ZoFo.GameCore //ТУТ Switch case будет честное слово } + public void CloseConnection() + { + networkManager.CloseConnection(); + } + /// /// Для красоты) Отдел Серверов /// добавляет в лист updates новую data From 997f5db24a017f024a25614bfe4e0af8a4733156 Mon Sep 17 00:00:00 2001 From: PetrKu09 Date: Sat, 17 Aug 2024 11:12:27 +0300 Subject: [PATCH 09/11] CheckComponentCollision normak version --- .../CollisionManager/CollisionComponent.cs | 20 ++--- .../CollisionManager/CollisionManager.cs | 83 ++++++++++++++++--- 2 files changed, 80 insertions(+), 23 deletions(-) diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs index cbef012..5f69441 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs @@ -13,9 +13,11 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager { //==ПОЛЯ== - public GameObject gameObject { get; set; } - public Rectangle Bounds { get; set; } - + //public GameObject gameObject { get; set; } + //public Rectangle Bounds { get; set; } + + public Rectangle Rectangle => new Rectangle(); + bool doesStop; Rectangle stopRectangle; @@ -26,15 +28,11 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager //delegate public delegate void EventHandler(object sender, EventArgs e); - public CollisionComponent(int x, int y, int width, int height) - { - Bounds = new Rectangle(x, y, width, height); - } + //public CollisionComponent(int x, int y, int width, int height) + //{ + // Bounds = new Rectangle(x, y, width, height); + //} - public CollisionComponent(Rectangle bounds) - { - Bounds = bounds; - } //events diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs index c8905f8..05808b4 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs @@ -22,22 +22,81 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager //чекаем коллизии в листе - public bool CheckComponentCollision(List collisionComponents, CollisionComponent component) + public void CheckComponentCollision(Entity entity) { - foreach (var collision in collisionComponents) - { - if (component.Bounds.IntersectsWith(collision.Bounds)) + //for (int i = 0; i < ObjectsWithCollisions.Count; i++) + //{ + var currentRect = entity.Rectangle;//задаём РЕК + var newRect = currentRect; // задаём значение старого РЕК новому РЕК + bool flagRemovedObject = false; //флаг удаления + + + var collidedX = false; // соприкосновение + var tryingRectX = currentRect;//переменная для попытки перемещения по X + + tryingRectX.Offset((int)(entity.velocity.X), 0);//задаём значения для tryingRectX по X и по Y + + foreach (var item in ObjectsWithCollisions)//фильтрация { - //Register(component, ); - return true; + if (Math.Abs(item.Pos.X - entity.Pos.X) < 550 + && Math.Abs(item.Pos.Y - entity.Pos.Y) < 550 + && tryingRectX.Intersect(item.Rectangle)) + + { + collidedX = true;// меняем значение соприкосновения на true + entity.OnCollision(item);//подписываем entity на ивент коллизии + + break;// выход + } + } + + if (collidedX)// срабатывает, если перемещение блокируется + { + entity.velocity.X = 0;// задаём значение смещения entity на 0 } + else + { + newRect.X = tryingRectX.X;//значение по X для нового РЕК приравниваем к значению испытуемого РЕК + } + + //==ПОВТОРЯЕМ ТОЖЕ САМОЕ ДЛЯ Y== + + var collidedY = false; // соприкосновение + var tryingRectY = currentRect;//переменная для попытки перемещения по X + + tryingRectY.Offset((int)(0, entity.velocity.Y));//задаём значения для tryingRectX по X и по Y + + foreach (var item in ObjectsWithCollisions)//фильтрация + { + if (Math.Abs(item.Pos.X - entity.Pos.X) < 550 + && Math.Abs(item.Pos.Y - entity.Pos.Y) < 550 + && tryingRectY.Intersect(item.Rectangle)) + + { + collidedY = true;// меняем значение соприкосновения на true + entity.OnCollision(item);//подписываем entity на ивент коллизии + + break;// выход + } } - return false; + if (collidedY)// срабатывает, если перемещение блокируется + { + entity.velocity.Y = 0;// задаём значение смещения entity на 0 + } + else + { + newRect.Y = tryingRectY.Y;//значение по X для нового РЕК приравниваем к значению испытуемого РЕК + } + + + + + //} } - //обновление позиций - public void UpdateObjectPosition(List collisionComponents, CollisionComponent component) + //обновление позиции объекта + public void UpdateObjectsPositions() { } @@ -51,12 +110,12 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager //регистрация компонента(его коллизии) - public void Register(CollisionComponent component, GameObject gameObject) + public void Register(CollisionComponent component) { + ObjectsWithCollisions.Add(component); if (component.gameObject is Entity) { - ObjectsWithCollisions.Add(component); - + EntitiesWithMovements.Add(component); } } From 72bfd52ae54c9ab4e012cf9b49c9b0b6f5e9baaa Mon Sep 17 00:00:00 2001 From: Mootfrost777 Date: Sat, 17 Aug 2024 11:22:38 +0300 Subject: [PATCH 10/11] Start resolving issues --- .../GameManagers/CollisionManager/CollisionManager.cs | 4 +++- .../GameObjects/Entities/LivingEntities/LivingEntity.cs | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs index 193d540..943694f 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs @@ -9,6 +9,8 @@ using ZoFo.GameCore.GameObjects; using ZoFo.GameCore.GameManagers.CollisionManager; using Microsoft.Xna.Framework; using ZoFo.GameCore.GameManagers.MapManager.MapElements; +using ZoFo.GameCore.GameObjects.Entities; +using ZoFo.GameCore.GameObjects.Entities.LivingEntities; namespace ZoFo.GameCore.GameManagers.CollisionManager { @@ -22,7 +24,7 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager //чекаем коллизии в листе - public void CheckComponentCollision(Entity entity) + public void CheckComponentCollision(LivingEntity entity) { //for (int i = 0; i < ObjectsWithCollisions.Count; i++) //{ diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs index 6842723..84e7d45 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs @@ -4,6 +4,7 @@ using System; using ZoFo.GameCore.GameObjects.Entities; using ZoFo.GameCore.ZoFo_graphics; using ZoFo.GameCore.GameManagers; +using ZoFo.GameCore.GameManagers.CollisionManager; namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities; public class LivingEntity : Entity @@ -26,6 +27,11 @@ public class LivingEntity : Entity }*/ #endregion + public void OnCollision(CollisionComponent component) + { + + } + } From 1b77e35c32ed5eb85e83ae3c2dabe364e9eecc24 Mon Sep 17 00:00:00 2001 From: PetrKu09 Date: Sat, 17 Aug 2024 11:36:18 +0300 Subject: [PATCH 11/11] Resolve issues --- .../CollisionManager/CollisionComponent.cs | 15 +++++++++------ .../CollisionManager/CollisionManager.cs | 17 ++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs index f22b906..880e159 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs @@ -1,10 +1,11 @@ -using System; +using Microsoft.Xna.Framework; +using System; using System.Collections.Generic; -using System.Drawing; using System.Linq; using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; +using ZoFo.GameCore.GameObjects; using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; namespace ZoFo.GameCore.GameManagers.CollisionManager @@ -13,17 +14,19 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager { //==ПОЛЯ== - //public GameObject gameObject { get; set; } + public GameObject gameObject { get; set; } //public Rectangle Bounds { get; set; } - public Rectangle Rectangle => new Rectangle(); + //public Rectangle Rectangle => new Rectangle(); + + bool doesStop; - Rectangle stopRectangle; + public Rectangle stopRectangle; // triggers for rectangle bool isTrigger; - Rectangle triggerRectangle; + public Rectangle triggerRectanglee; //delegate public delegate void EventHandler(object sender, EventArgs e); diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs index 943694f..96c9cbc 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs @@ -1,7 +1,6 @@ using Microsoft.VisualBasic; using System; using System.Collections.Generic; -using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -28,7 +27,7 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager { //for (int i = 0; i < ObjectsWithCollisions.Count; i++) //{ - var currentRect = entity.Rectangle;//задаём РЕК + var currentRect = entity.collisionComponent.stopRectangle;//задаём РЕК var newRect = currentRect; // задаём значение старого РЕК новому РЕК bool flagRemovedObject = false; //флаг удаления @@ -40,9 +39,9 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager foreach (var item in ObjectsWithCollisions)//фильтрация { - if (Math.Abs(item.Pos.X - entity.Pos.X) < 550 - && Math.Abs(item.Pos.Y - entity.Pos.Y) < 550 - && tryingRectX.Intersect(item.Rectangle)) + if (Math.Abs(item.stopRectangle.X - entity.collisionComponent.stopRectangle.X) < 550 + && Math.Abs(item.stopRectangle.Y - entity.collisionComponent.stopRectangle.Y) < 550 + && tryingRectX.Intersects(item.stopRectangle)) { collidedX = true;// меняем значение соприкосновения на true @@ -66,13 +65,13 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager var collidedY = false; // соприкосновение var tryingRectY = currentRect;//переменная для попытки перемещения по X - tryingRectY.Offset((int)(0, entity.velocity.Y));//задаём значения для tryingRectX по X и по Y + tryingRectY.Offset(new Point(0, (int)entity.velocity.Y));//задаём значения для tryingRectX по X и по Y foreach (var item in ObjectsWithCollisions)//фильтрация { - if (Math.Abs(item.Pos.X - entity.Pos.X) < 550 - && Math.Abs(item.Pos.Y - entity.Pos.Y) < 550 - && tryingRectY.Intersect(item.Rectangle)) + if (Math.Abs(item.stopRectangle.X - entity.collisionComponent.stopRectangle.X) < 550 + && Math.Abs(item.stopRectangle.Y - entity.collisionComponent.stopRectangle.Y) < 550 + && tryingRectY.Intersects(item.stopRectangle)) { collidedY = true;// меняем значение соприкосновения на true