diff --git a/MonogameLibrary/UI/Elements/Slider.cs b/MonogameLibrary/UI/Elements/Slider.cs index fd884d8..0e3b784 100644 --- a/MonogameLibrary/UI/Elements/Slider.cs +++ b/MonogameLibrary/UI/Elements/Slider.cs @@ -21,6 +21,9 @@ namespace MonogameLibrary.UI.Elements public int indentation = 5; Texture2D texture2; + /// + /// ректенгл ползунка + /// public Rectangle sliderRect = new Rectangle(0, 0, 40, 40); private float sliderValue = 0; private float minValue = 0, maxValue = 1; diff --git a/ZoFo/Content/Content.mgcb b/ZoFo/Content/Content.mgcb index 6cde49b..b023b03 100644 --- a/ZoFo/Content/Content.mgcb +++ b/ZoFo/Content/Content.mgcb @@ -103,6 +103,18 @@ /processorParam:TextureFormat=Color /build:Textures/GUI/background/base.png +#begin Textures/GUI/background/endGame.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/GUI/background/endGame.png + #begin Textures/GUI/background/join.png /importer:TextureImporter /processor:TextureProcessor @@ -115,6 +127,30 @@ /processorParam:TextureFormat=Color /build:Textures/GUI/background/join.png +#begin Textures/GUI/background/mainMenu.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/GUI/background/mainMenu.png + +#begin Textures/GUI/background/options.png +/importer:TextureImporter +/processor:TextureProcessor +/processorParam:ColorKeyColor=255,0,255,255 +/processorParam:ColorKeyEnabled=True +/processorParam:GenerateMipmaps=False +/processorParam:PremultiplyAlpha=True +/processorParam:ResizeToPowerOfTwo=False +/processorParam:MakeSquare=False +/processorParam:TextureFormat=Color +/build:Textures/GUI/background/options.png + #begin Textures/GUI/background/selectMode.png /importer:TextureImporter /processor:TextureProcessor diff --git a/ZoFo/Content/Textures/GUI/background/endGame.png b/ZoFo/Content/Textures/GUI/background/endGame.png new file mode 100644 index 0000000..2d9926c Binary files /dev/null and b/ZoFo/Content/Textures/GUI/background/endGame.png differ diff --git a/ZoFo/Content/Textures/GUI/background/join.png b/ZoFo/Content/Textures/GUI/background/join.png index 59d539a..6d45273 100644 Binary files a/ZoFo/Content/Textures/GUI/background/join.png and b/ZoFo/Content/Textures/GUI/background/join.png differ diff --git a/ZoFo/Content/Textures/GUI/background/mainMenu.png b/ZoFo/Content/Textures/GUI/background/mainMenu.png new file mode 100644 index 0000000..a0778fb Binary files /dev/null and b/ZoFo/Content/Textures/GUI/background/mainMenu.png differ diff --git a/ZoFo/Content/Textures/GUI/background/options.png b/ZoFo/Content/Textures/GUI/background/options.png new file mode 100644 index 0000000..ef917ce Binary files /dev/null and b/ZoFo/Content/Textures/GUI/background/options.png differ diff --git a/ZoFo/Content/Textures/GUI/background/selectMode.png b/ZoFo/Content/Textures/GUI/background/selectMode.png index 256ae2c..25bc33b 100644 Binary files a/ZoFo/Content/Textures/GUI/background/selectMode.png and b/ZoFo/Content/Textures/GUI/background/selectMode.png differ diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index f96599a..81b4166 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -28,17 +28,11 @@ namespace ZoFo.GameCore public void OnDataSend(string data) { - List updateDatas = JsonSerializer.Deserialize>(data); + List updateDatas = JsonSerializer.Deserialize>(data); // тут будет switch foreach (var item in updateDatas) { - /* switch (item.UpdateType) Здесь нужно отлавливать и регистрировать - { - case "Tile": - MapObject map = new MapObject(); - - break; - }*/ + GotData(item); } } @@ -66,7 +60,7 @@ namespace ZoFo.GameCore } } - internal void GotData(IUpdateData update) + internal void GotData(UpdateData update) { if (update is UpdateTileCreated) { diff --git a/ZoFo/GameCore/GUI/HUD.cs b/ZoFo/GameCore/GUI/HUD.cs index 2a65222..a2b1892 100644 --- a/ZoFo/GameCore/GUI/HUD.cs +++ b/ZoFo/GameCore/GUI/HUD.cs @@ -13,13 +13,7 @@ using MonogameLibrary.UI.Elements; namespace ZoFo.GameCore.GUI; public class HUD : AbstractGUI -{ - protected UIManager Manager = new(); - protected List Elements = new(); - private List ActiveElements; - protected DrawableUIElement SelectedElement; - private bool isStartedPrint = false; - private bool isPressed = false; +{ private GraphicsDevice graphicsDevice; public virtual void Initialize() diff --git a/ZoFo/GameCore/GUI/MainMenuGUI.cs b/ZoFo/GameCore/GUI/MainMenuGUI.cs index 2c098ac..8ebfd74 100644 --- a/ZoFo/GameCore/GUI/MainMenuGUI.cs +++ b/ZoFo/GameCore/GUI/MainMenuGUI.cs @@ -21,15 +21,15 @@ public class MainMenuGUI : 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\\MenuBackground" }; + + menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures\\GUI\\background\\mainMenu" }; Elements.Add(menuBackground); menuBackground.LoadTexture(AppManager.Instance.Content); - - Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 5, (int)(width / 4), (int)(height / 20)), text = "ZoFo", fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font" }); - - - Button playButton = new Button(Manager) + + Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 5, (int)(width / 4), (int)(height / 20)), text = "ZoFo", fontColor = Color.Black, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font"}); + + + Button playButton = new Button(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + height / 20 + height / 40, (int)(width / 5), (int)(height / 20)), text = "Play", diff --git a/ZoFo/GameCore/GUI/OptionsGUI.cs b/ZoFo/GameCore/GUI/OptionsGUI.cs index 991c04b..d2fbf92 100644 --- a/ZoFo/GameCore/GUI/OptionsGUI.cs +++ b/ZoFo/GameCore/GUI/OptionsGUI.cs @@ -21,56 +21,76 @@ public class OptionsGUI : 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\\MenuBackground" }; + menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures\\GUI\\background\\options" }; Elements.Add(menuBackground); menuBackground.LoadTexture(AppManager.Instance.Content); - Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 5, (int)(width / 4), (int)(height / 20)), text = "Options", fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font"}); + Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 5, (int)(width / 4), (int)(height / 20)), text = "Options", fontColor = Color.Black, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font"}); Label label_OverallVolume = new Label(Manager) - { fontName = "Fonts\\Font", scale = 0.2f, text = "All Volume", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; + { fontName = "Fonts\\Font", scale = 0.2f, text = "All Volume", fontColor = Color.Black, rectangle = new Rectangle(width / 3, height / 3, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; Elements.Add(label_OverallVolume); + + Label label_OverallVolume_Percent = new Label(Manager) + { fontName = "Fonts\\Font3", scale = 0.4f, text = "", fontColor = Color.Black, rectangle = new Rectangle(width / 2 + width / 10, height / 3, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; + Elements.Add(label_OverallVolume_Percent); var slider_OverallVolume = new Slider(Manager) - { rectangle = new Rectangle(width / 2, height / 3, width / 10, height / 20), indentation = 4, textureName = "Textures\\GUI\\Switch_backgrownd", MinValue = 0, MaxValue = 1 }; + { rectangle = new Rectangle(width / 2, height / 3, width / 10, height / 20), indentation = 7, textureName = "Textures\\GUI\\Switch_backgrownd", MinValue = 0, MaxValue = 1 }; slider_OverallVolume.SetValue(AppManager.Instance.SettingsManager.MainVolume); slider_OverallVolume.SliderChanged += (newVal) => { + label_OverallVolume_Percent.text = Math.Round(slider_OverallVolume.GetSliderValue * 100) + "%"; AppManager.Instance.SettingsManager.SetMainVolume(newVal); }; Elements.Add(slider_OverallVolume); + //-------------------------------------- + Label label_MusicVolume = new Label(Manager) - { fontName = "Fonts\\Font", scale = 0.2f, text = "Music Volume", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 1, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; + { fontName = "Fonts\\Font", scale = 0.2f, text = "Music Volume", fontColor = Color.Black, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 1, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; Elements.Add(label_MusicVolume); + Label label_MusicVolume_Percent = new Label(Manager) + { fontName = "Fonts\\Font3", scale = 0.4f, text = "", fontColor = Color.Black, rectangle = new Rectangle(width / 2 + width / 10, height / 3 + (height / 20 + height / 40) * 1, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; + Elements.Add(label_MusicVolume_Percent); + var slider_MusicVolume = new Slider(Manager) - { rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 1, width / 10, height / 20), indentation = 4, textureName = "Textures\\GUI\\Switch_backgrownd", MinValue = 0, MaxValue = 1 }; + { rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 1, width / 10, height / 20), indentation = 7, textureName = "Textures\\GUI\\Switch_backgrownd", MinValue = 0, MaxValue = 1 }; slider_MusicVolume.SetValue(AppManager.Instance.SettingsManager.MusicVolume); slider_MusicVolume.SliderChanged += (newVal) => { + label_MusicVolume_Percent.text = Math.Round(slider_MusicVolume.GetSliderValue * 100) + "%"; AppManager.Instance.SettingsManager.SetMusicVolume(newVal); }; Elements.Add(slider_MusicVolume); + //-------------------------------------- Label label_EffectsVolume = new Label(Manager) - { fontName = "Fonts\\Font", scale = 0.2f, text = "Effects Volume", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 2, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; + { fontName = "Fonts\\Font", scale = 0.2f, text = "Effects Volume", fontColor = Color.Black, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 2, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; Elements.Add(label_EffectsVolume); + + Label label_EffectsVolume_Percent = new Label(Manager) + { fontName = "Fonts\\Font3", scale = 0.4f, text = "", fontColor = Color.Black, rectangle = new Rectangle(width / 2 + width / 10, height / 3 + (height / 20 + height / 40) * 2, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; + Elements.Add(label_EffectsVolume_Percent); var slider_EffectsVolume = new Slider(Manager) - { rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 2, width / 10, height / 20), indentation = 4, textureName = "Textures\\GUI\\Switch_backgrownd", MinValue = 0, MaxValue = 1 }; + { rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 2, width / 10, height / 20), indentation = 7, textureName = "Textures\\GUI\\Switch_backgrownd", MinValue = 0, MaxValue = 1 }; slider_EffectsVolume.SetValue(AppManager.Instance.SettingsManager.SoundEffectsVolume); slider_EffectsVolume.SliderChanged += (newVal) => { + label_EffectsVolume_Percent.text = Math.Round(slider_EffectsVolume.GetSliderValue * 100) + "%"; AppManager.Instance.SettingsManager.SetSoundEffectsVolume(newVal); }; Elements.Add(slider_EffectsVolume); + //-------------------------------------- + Label lblSwitchMode = new Label(Manager) - { fontName = "Fonts\\Font", scale = 0.2f, text = "Resolution set", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 3, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; + { fontName = "Fonts\\Font", scale = 0.2f, text = "Resolution set", fontColor = Color.Black, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 3, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; Elements.Add(lblSwitchMode); //var button_left_right_mode = new CheckBox(Manager) { rectangle = new Rectangle(rightBorder - checkboxlength, lblSwitchMode.rectangle.Y - 12, checkboxlength, checkboxlength) }; @@ -79,7 +99,7 @@ public class OptionsGUI : AbstractGUI Label label_IsFullScreen = new Label(Manager) - { fontName = "Fonts\\Font", scale = 0.2f, text = "Full Screen", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 4, width / 40, width / 40), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; + { fontName = "Fonts\\Font", scale = 0.2f, text = "Full Screen", fontColor = Color.Black, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 4, width / 40, width / 40), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; Elements.Add(label_IsFullScreen); var button_FullScreen = new CheckBox(Manager) { rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 4, width / 40, width / 40) }; @@ -90,7 +110,8 @@ public class OptionsGUI : AbstractGUI }; Elements.Add(button_FullScreen); - + //-------------------------------------- + Button bTExit = new Button(Manager) { fontName = "Fonts\\Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), textureName = "Textures\\GUI\\checkboxs_off"}; Elements.Add(bTExit); diff --git a/ZoFo/GameCore/GUI/SelectModeMenu.cs b/ZoFo/GameCore/GUI/SelectModeMenu.cs index db075bb..af3dad0 100644 --- a/ZoFo/GameCore/GUI/SelectModeMenu.cs +++ b/ZoFo/GameCore/GUI/SelectModeMenu.cs @@ -39,8 +39,11 @@ public class SelectModeMenu : AbstractGUI singleButton.LeftButtonPressed += () => { // single - Server server = new Server(); //Server Logic SinglePlayer + Server server = new Server(); Client client = new Client(); + server.CreateRoom(1); + client.JoinYourself(); + AppManager.Instance.SetServer(server); AppManager.Instance.SetClient(client); AppManager.Instance.ChangeState(GameState.HostPlaying); diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs index 8cf63f2..5242d4a 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs @@ -17,7 +17,10 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager public List CollisionComponent; public List TriggerComponent; - + public void RegisterComponent() + { + + } public static bool CheckComponentCollision(List collisionComponents, CollisionComponent component) { diff --git a/ZoFo/GameCore/GameManagers/InputManager.cs b/ZoFo/GameCore/GameManagers/InputManager.cs index 0dfbc1b..4ee0980 100644 --- a/ZoFo/GameCore/GameManagers/InputManager.cs +++ b/ZoFo/GameCore/GameManagers/InputManager.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers { public enum ScopeState { Left, Right, Straight, Back, StraightLeft, StraightRight, BackLeft, BackRight } + public class InputManager { public delegate void Delegat(); diff --git a/ZoFo/GameCore/GameManagers/MapManager/MapManager.cs b/ZoFo/GameCore/GameManagers/MapManager/MapManager.cs index a9f13d0..d65d74c 100644 --- a/ZoFo/GameCore/GameManagers/MapManager/MapManager.cs +++ b/ZoFo/GameCore/GameManagers/MapManager/MapManager.cs @@ -37,9 +37,9 @@ namespace ZoFo.GameCore.GameManagers.MapManager // Загрузка TileSet-ов по TileSetInfo List tileSets = new List(); - foreach (TileSetInfo tileSetInfo in tileMap.TileSets) + foreach (TileSetInfo tileSetInfo in tileMap.TileSets) { - TileSet tileSet = LoadTileSet("Content/MapData/TileMaps/" + tileSetInfo.Source); + TileSet tileSet = LoadTileSet(Path.Combine("Content", "MapData", "TileMaps", tileSetInfo.Source)); tileSet.FirstGid = tileSetInfo.FirstGid; tileSets.Add(tileSet); } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs index eeb69b3..c178154 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs @@ -18,7 +18,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager private int port = 7632; private EndPoint endPoint; private Socket socket; - List updates = new List(); + List updates = new List(); public delegate void OnDataSent(string Data); public event OnDataSent GetDataSent; // event public bool IsConnected { get { return socket.Connected; } } @@ -28,6 +28,11 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager Init(); } + public bool SocketConnected() + { + return socket.Connected; + } + public void Init() //create endPoint, socket { socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); @@ -39,7 +44,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager socket.Send(bytes); } - public void AddData(IUpdateData UpdateData) + public void AddData(UpdateData UpdateData) { updates.Add(UpdateData); } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs index bb8717a..658605e 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs @@ -1,9 +1,11 @@ -using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics.PackedVector; using System; using System.Collections.Generic; using System.Linq; using System.Net; +using System.Net.Http; using System.Net.Sockets; using System.Text; using System.Text.Json; @@ -21,7 +23,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager 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; @@ -38,7 +40,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); managerThread = new Dictionary(); clients = new List(); - updates = new List(); + updates = new List(); managerThread = new Dictionary(); socket.Bind(endPoint); } @@ -56,19 +58,25 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager updates.Clear(); return; //TODO TODO REMOVE TO ADD NETWORK TODO REMOVE TO ADD NETWORK TODO REMOVE TO ADD NETWORK TODO REMOVE TO ADD NETWORK - string data = JsonSerializer.Serialize(updates); + //по 10 паков за раз TODO FIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXIT + List datasToSend = new List(); + for (int i = 0; i < 5 && i /// добавляет в лист updates новую data /// /// - public void AddData(IUpdateData data) + public void AddData(UpdateData data) { updates.Add(data); } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateInput.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateInput.cs index 81af1d9..bb2ea93 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateInput.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdateInput.cs @@ -6,9 +6,12 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer { - public class UpdateInput :IUpdateData + public class UpdateInput :UpdateData { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + // public int IdEntity { get; set; } + public UpdateInput() + { + UpdateType = "UpdateInput"; + } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdatePlayerExit.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdatePlayerExit.cs index ba6c6ca..7cb0b44 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdatePlayerExit.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ClientToServer/UpdatePlayerExit.cs @@ -6,9 +6,8 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer { - public class UpdatePlayerExit : IUpdateData + public class UpdatePlayerExit : UpdateData { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdatePlayerExit() { UpdateType = "UpdatePlayerExit"; } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateAnimation.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateAnimation.cs index 6f07770..4e9b972 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateAnimation.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateAnimation.cs @@ -6,9 +6,11 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { - public class UpdateAnimation : IUpdateData //хранит новую анимации + /// + /// Хранит новое сосотяние анимации + /// + public class UpdateAnimation : UpdateData { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdateAnimation() { UpdateType = "UpdateAnimation"; } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateEntityHealth.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateEntityHealth.cs index 618770e..71f95a2 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateEntityHealth.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateEntityHealth.cs @@ -6,9 +6,11 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { - public class UpdateEntityHealth : IUpdateData//хранит новое хп entity + /// + /// Обнивляет хп сущности + /// + public class UpdateEntityHealth : UpdateData { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdateEntityHealth() { UpdateType = "UpdateEntityHealth"; } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameEnded.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameEnded.cs index 10173b7..d89c9a7 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameEnded.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameEnded.cs @@ -6,9 +6,11 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { - public class UpdateGameEnded : IUpdateData //хранит полученый лут и уведомляет о конце игры + /// + /// Хранит полученый лут и уведомляет о конце игры + /// + public class UpdateGameEnded : UpdateData { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdateGameEnded() { UpdateType = "UpdateGameEnded"; } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectCreated.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectCreated.cs index 4cf8a42..32052a0 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectCreated.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectCreated.cs @@ -6,9 +6,11 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { - public class UpdateGameObjectCreated : IUpdateData //Хранит объект, который только отправили + /// + /// Хранит объект, который только отправили + /// + public class UpdateGameObjectCreated : UpdateData { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdateGameObjectCreated() { UpdateType = "UpdateGameObjectCreated"; } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectDeleted.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectDeleted.cs new file mode 100644 index 0000000..88d4e98 --- /dev/null +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectDeleted.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient +{ + /// + /// Хранит объект, который надо удлить + /// + public class UpdateGameObjectDeleted : UpdateData + { + public UpdateGameObjectDeleted() { UpdateType = "UpdateGameObjectDeleted"; } + } +} \ No newline at end of file diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteraction.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteraction.cs new file mode 100644 index 0000000..e42f0f4 --- /dev/null +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteraction.cs @@ -0,0 +1,10 @@ +namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; + +/// +/// При попытке взаимодействия с объектом +/// +public class UpdateInteraction : UpdateData +{ + public int IdEntity { get; set; } + public string UpdateType { get; set; } +} \ No newline at end of file diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteractionReady.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteractionReady.cs new file mode 100644 index 0000000..db4d01d --- /dev/null +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateInteractionReady.cs @@ -0,0 +1,14 @@ +namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; + +/// +/// При изменении возможности повзаимодействовать с объектом +/// +/// +/// +public class UpdateInteractionReady(int idEntity, bool isReady) + : UpdateData +{ + public int IdEntity { get; set; } = idEntity; + public string UpdateType { get; set; } + public bool IsReady { get; set; } = isReady; +} \ No newline at end of file diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateLoot.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateLoot.cs index e7f8a51..2337f74 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateLoot.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateLoot.cs @@ -6,9 +6,11 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { - public class UpdateLoot : IUpdateData //Хранит лут + /// + /// Хранит лут + /// + public class UpdateLoot : UpdateData { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdateLoot() { UpdateType = "UpdateLoot"; } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePlayerParametrs.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePlayerParametrs.cs index 36a2544..100c8d0 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePlayerParametrs.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePlayerParametrs.cs @@ -6,9 +6,11 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { - public class UpdatePlayerParametrs : IUpdateData //Хранит хп, радиацию + /// + /// Хранит хп, радиацию + /// + public class UpdatePlayerParametrs : UpdateData { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdatePlayerParametrs() { UpdateType = "UpdatePlayerParametrs"; } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePosition.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePosition.cs index fda8a39..8d93d7b 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePosition.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePosition.cs @@ -6,9 +6,11 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { - public class UpdatePosition : IUpdateData //Хранит новую позицию + /// + /// Хранит новую позицию + /// + public class UpdatePosition : UpdateData { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdatePosition() { UpdateType = "UpdatePosition"; } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateTileCreated.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateTileCreated.cs index 56f9aed..0799653 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateTileCreated.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateTileCreated.cs @@ -10,11 +10,13 @@ using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { - - public class UpdateTileCreated : IUpdateData + + /// + /// При создании тайла + /// + public class UpdateTileCreated : UpdateData { - public int IdEntity { get; set; } - public string UpdateType { get; set; } + public UpdateTileCreated() { UpdateType = "UpdateTileCreated"; } public Texture2D TextureTile { get; set; } public Vector2 Position { get; set; } public Point Size { get; set; } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/IUpdateData.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/UpdateData.cs similarity index 76% rename from ZoFo/GameCore/GameManagers/NetworkManager/Updates/IUpdateData.cs rename to ZoFo/GameCore/GameManagers/NetworkManager/Updates/UpdateData.cs index 5c363d7..a96b270 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/IUpdateData.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/UpdateData.cs @@ -14,16 +14,19 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates [JsonDerivedType(typeof(UpdateEntityHealth))] [JsonDerivedType(typeof(UpdateGameEnded))] [JsonDerivedType(typeof(UpdateGameObjectCreated))] + [JsonDerivedType(typeof(UpdateGameObjectDeleted))] [JsonDerivedType(typeof(UpdateLoot))] [JsonDerivedType(typeof(UpdatePlayerParametrs))] [JsonDerivedType(typeof(UpdatePosition))] [JsonDerivedType(typeof(UpdateTileCreated))] [JsonDerivedType(typeof(UpdateInput))] [JsonDerivedType(typeof(UpdatePlayerExit))] - - public interface IUpdateData + [JsonDerivedType(typeof(UpdateInteractionReady))] + [JsonDerivedType(typeof(UpdateInteraction))] + + public class UpdateData { public int IdEntity { get; set; } //Id объекта - public string UpdateType { get; set; } //тип обновления + public string UpdateType { get; protected set; } //тип обновления } } diff --git a/ZoFo/GameCore/GameObjects/Entities/Entity.cs b/ZoFo/GameCore/GameObjects/Entities/Entity.cs index ae903a2..a9e8670 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Entity.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Entity.cs @@ -16,8 +16,10 @@ namespace ZoFo.GameCore.GameObjects.Entities protected Entity(Vector2 position) : base(position) { } - + public virtual void Update() + { + } } } diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs index b900e4a..d31d536 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs @@ -2,7 +2,7 @@ using System; namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables; -public class Collectable : Entity +public class Collectable : Interactable { public Collectable(Vector2 position) : base(position) { diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Door.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Door.cs new file mode 100644 index 0000000..06bdec5 --- /dev/null +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Door.cs @@ -0,0 +1,8 @@ +namespace ZoFo.GameCore.GameObjects.Entities.Interactables; + +public class Door +{ + public bool isOpened; + + +} \ No newline at end of file diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs new file mode 100644 index 0000000..6299155 --- /dev/null +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs @@ -0,0 +1,26 @@ +using Microsoft.Xna.Framework; +using ZoFo.GameCore.GameManagers; +using ZoFo.GameCore.GameManagers.CollisionManager; +using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; +using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; + +namespace ZoFo.GameCore.GameObjects.Entities.Interactables; + +public class Interactable : Entity +{ + public Interactable(Vector2 position) : base(position) + { + collisionComponent.OnTriggerEnter += (sender, e) => ChangeInteraction(sender, e, true); + collisionComponent.OnTriggerExit += (sender, e) => ChangeInteraction(sender, e, false); + } + + private void ChangeInteraction(object sender, CollisionComponent e, bool isReady) + { + AppManager.Instance.server.AddData(new UpdateInteractionReady((sender as Player).Id, isReady)); + } + + public void OnInteraction() + { + + } +} \ No newline at end of file diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs index 05a27ec..1d73ead 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs @@ -3,20 +3,26 @@ using Microsoft.Xna.Framework.Graphics; using System; using ZoFo.GameCore.GameObjects.Entities; using ZoFo.GameCore.ZoFo_graphics; +using ZoFo.GameCore.GameManagers; namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities; public class LivingEntity : Entity { public Vector2 velocity; + private InputManager inputManager; + public LivingEntity(Vector2 position) : base(position) { + inputManager = new InputManager(); } - public void TextureLoad(SpriteBatch spriteBatch) + #region Server side + /*public override void Update() { - - } + + }*/ + #endregion } diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs index 744b2c4..20bbe18 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs @@ -1,25 +1,27 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; +using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; + public class Player : LivingEntity { + public Vector2 InputWeaponRotation{ get; set; } + public Vector2 InputPlayerRotation{ get; set;} + public bool IsTryingToShoot{get;set;} + Texture2D texture; + private float speed; private int health; - Server server = new Server(); - public Player(Vector2 position) : base(position) { + //InputWeaponRotation = new Vector2(0, 0); + //InputPlayerRotation = new Vector2(0, 0); } public void Update(GameTime gameTime) { - // server.AddData(); - } - - public void TextureLoad(SpriteBatch spriteBatch) - { - + } } diff --git a/ZoFo/GameCore/GameObjects/GameObject.cs b/ZoFo/GameCore/GameObjects/GameObject.cs index 6305674..14c306f 100644 --- a/ZoFo/GameCore/GameObjects/GameObject.cs +++ b/ZoFo/GameCore/GameObjects/GameObject.cs @@ -4,19 +4,21 @@ using Microsoft.Xna.Framework.Graphics; using System; using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.ZoFo_graphics; +using ZoFo.GameCore; namespace ZoFo.GameCore.GameObjects; public abstract class GameObject { public Vector2 position; + public Vector2 rotation; //вектор направления объекта public abstract GraphicsComponent graphicsComponent { get; } #region ServerSide public GameObject(Vector2 position) { - this.position = position; + this.position = position; graphicsComponent.LoadContent(); } diff --git a/ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs b/ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs index 300cbcc..51a3a4e 100644 --- a/ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs +++ b/ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs @@ -15,12 +15,19 @@ namespace ZoFo.GameCore.GameObjects.MapObjects public class MapObject : GameObject { public virtual bool IsColliderOn { get; protected set; } = true;//Who added that? - public Rectangle _sourceRectangle; + public Rectangle sourceRectangle; public override GraphicsComponent graphicsComponent { get; } = new(); + /// + /// Создается простой объект на карте - no animations, только где, насколько крупно рисовать, по какой сорс ректанглу рисовать и из какой текстуры + /// + /// + /// + /// + /// public MapObject(Vector2 position, Vector2 size, Rectangle sourceRectangle, string textureName) : base(position) { - _sourceRectangle = sourceRectangle; + this.sourceRectangle = sourceRectangle; graphicsComponent.ObjectDrawRectangle = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y); graphicsComponent.BuildComponent(textureName); graphicsComponent.LoadContent(); @@ -28,7 +35,7 @@ namespace ZoFo.GameCore.GameObjects.MapObjects } public override void Draw(SpriteBatch spriteBatch) { - graphicsComponent.DrawAnimation(graphicsComponent.ObjectDrawRectangle, spriteBatch, _sourceRectangle); + graphicsComponent.DrawAnimation(graphicsComponent.ObjectDrawRectangle, spriteBatch, sourceRectangle); } } diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index 0d7fc66..f844da2 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -29,7 +29,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 +39,7 @@ namespace ZoFo.GameCore /// Обработка апдейтсов, которые нам прислал клиент /// /// - public void ProcessIUpdateData(IUpdateData updateData) + public void ProcessIUpdateData(UpdateData updateData) { //ТУТ Switch case будет честное слово @@ -50,7 +50,7 @@ namespace ZoFo.GameCore /// добавляет в лист updates новую data /// /// - public void AddData(IUpdateData data) + public void AddData(UpdateData data)//добавляет в лист updates новую data { networkManager.AddData(data); } @@ -87,8 +87,7 @@ namespace ZoFo.GameCore networkManager.AddData(gameEnded); networkManager.CloseConnection(); } - #endregion - private List gameObjects; + private List gameObjects = new List(); private List entities; //entity public void Update(GameTime gameTime) { @@ -118,11 +117,12 @@ namespace ZoFo.GameCore AddData(new UpdateTileCreated() { Position = (gameObject as MapObject).position, - sourceRectangle = (gameObject as MapObject)._sourceRectangle, + sourceRectangle = (gameObject as MapObject).sourceRectangle, Size = (gameObject as MapObject).graphicsComponent.ObjectDrawRectangle.Size, tileSetName = (gameObject as MapObject).graphicsComponent.mainTextureName });//TODO } } } + #endregion }