diff --git a/MonogameLibrary/UI/Elements/TextBox.cs b/MonogameLibrary/UI/Elements/TextBox.cs index 87534eb..529a8be 100644 --- a/MonogameLibrary/UI/Elements/TextBox.cs +++ b/MonogameLibrary/UI/Elements/TextBox.cs @@ -89,9 +89,9 @@ namespace MonogameLibrary.UI.Elements if (hoverState == HoverState.None) { if (isSelected == IsSelected.Selected) - _spriteBatch.Draw(texture, rectangle, new Color(220, 220, 220)); + _spriteBatch.Draw(texture, rectangle, new Color(211, 211, 211)); else - _spriteBatch.Draw(texture, rectangle, new Color(245, 245, 245)); + _spriteBatch.Draw(texture, rectangle, Color.White); } else if (hoverState == HoverState.Hovering) _spriteBatch.Draw(texture, rectangle, new Color(211, 211, 211)); diff --git a/ZoFo/Content/Content.mgcb b/ZoFo/Content/Content.mgcb index a608235..f9ac38a 100644 --- a/ZoFo/Content/Content.mgcb +++ b/ZoFo/Content/Content.mgcb @@ -34,6 +34,54 @@ /processorParam:TextureFormat=Compressed /build:Fonts/Font3.spritefont +#begin Textures/GUI/background/base.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/base.png + +#begin Textures/GUI/background/join.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/join.png + +#begin Textures/GUI/background/selectMode.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/selectMode.png + +#begin Textures/GUI/background/waiting.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/waiting.png + #begin Textures/GUI/checkboxs_off-on.png /importer:TextureImporter /processor:TextureProcessor diff --git a/ZoFo/Content/Textures/GUI/background/base.png b/ZoFo/Content/Textures/GUI/background/base.png new file mode 100644 index 0000000..11cbac6 Binary files /dev/null and b/ZoFo/Content/Textures/GUI/background/base.png differ diff --git a/ZoFo/Content/Textures/GUI/background/join.png b/ZoFo/Content/Textures/GUI/background/join.png new file mode 100644 index 0000000..59d539a Binary files /dev/null and b/ZoFo/Content/Textures/GUI/background/join.png differ diff --git a/ZoFo/Content/Textures/GUI/background/selectMode.png b/ZoFo/Content/Textures/GUI/background/selectMode.png new file mode 100644 index 0000000..256ae2c Binary files /dev/null and b/ZoFo/Content/Textures/GUI/background/selectMode.png differ diff --git a/ZoFo/Content/Textures/GUI/background/waiting.png b/ZoFo/Content/Textures/GUI/background/waiting.png new file mode 100644 index 0000000..709fb0b Binary files /dev/null and b/ZoFo/Content/Textures/GUI/background/waiting.png differ diff --git a/ZoFo/Content/Textures/GUI/feature/i (1).webp b/ZoFo/Content/Textures/GUI/feature/i (1).webp new file mode 100644 index 0000000..751b392 Binary files /dev/null and b/ZoFo/Content/Textures/GUI/feature/i (1).webp differ diff --git a/ZoFo/Content/Textures/GUI/feature/i (2).webp b/ZoFo/Content/Textures/GUI/feature/i (2).webp new file mode 100644 index 0000000..a59827e Binary files /dev/null and b/ZoFo/Content/Textures/GUI/feature/i (2).webp differ diff --git a/ZoFo/Content/Textures/GUI/feature/i.webp b/ZoFo/Content/Textures/GUI/feature/i.webp new file mode 100644 index 0000000..69b1f1f Binary files /dev/null and b/ZoFo/Content/Textures/GUI/feature/i.webp differ diff --git a/ZoFo/Content/Textures/GUI/feature/огонь-искусства-пиксела-вектора-117929424.webp b/ZoFo/Content/Textures/GUI/feature/огонь-искусства-пиксела-вектора-117929424.webp new file mode 100644 index 0000000..a2178c4 Binary files /dev/null and b/ZoFo/Content/Textures/GUI/feature/огонь-искусства-пиксела-вектора-117929424.webp differ diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index 36351e7..484e82a 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -12,7 +12,9 @@ namespace ZoFo.GameCore { public class Client { - public ClientNetworkManager networkManager; + ClientNetworkManager networkManager; + + public bool IsConnected { get { return networkManager.IsConnected; } } public Client() { networkManager = new ClientNetworkManager(); @@ -24,19 +26,15 @@ namespace ZoFo.GameCore List updateDatas = JsonSerializer.Deserialize>(data); // тут будет switch } - public void GameEndedUnexpectedly(){ } - public void JoinRoom(string ip) { networkManager.JoinRoom(ip); } - public void JoinYourself(){ networkManager.JoinYourself(); } internal void Update(GameTime gameTime) { } - internal void Draw(SpriteBatch spriteBatch) { } diff --git a/ZoFo/GameCore/GUI/MainMenuGUI.cs b/ZoFo/GameCore/GUI/MainMenuGUI.cs index 4683ddd..2c098ac 100644 --- a/ZoFo/GameCore/GUI/MainMenuGUI.cs +++ b/ZoFo/GameCore/GUI/MainMenuGUI.cs @@ -39,8 +39,8 @@ public class MainMenuGUI : AbstractGUI fontName = "Fonts\\Font" }; playButton.LeftButtonPressed += () => - { - AppManager.Instance.SetGUI(new SelectModeMenu()); + { + AppManager.Instance.SetGUI(new SelectModeMenu()); }; Elements.Add(playButton); Button optionButton = new Button(Manager) diff --git a/ZoFo/GameCore/GUI/SelectModeMenu.cs b/ZoFo/GameCore/GUI/SelectModeMenu.cs index 62fac0e..86423c8 100644 --- a/ZoFo/GameCore/GUI/SelectModeMenu.cs +++ b/ZoFo/GameCore/GUI/SelectModeMenu.cs @@ -21,13 +21,13 @@ public class SelectModeMenu : 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\\selectMode" }; Elements.Add(menuBackground); menuBackground.LoadTexture(AppManager.Instance.Content); Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 6, (int)(width / 4), (int)(height / 20)), text = "Select mode", fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font"}); - Button playButton = new Button(Manager) + Button singleButton = new Button(Manager) { rectangle = new Rectangle(width / 4 - (width / 7) / 2, height / 2, (int)(width / 7), (int)(height / 20)), text = "singleplayer", @@ -36,16 +36,23 @@ public class SelectModeMenu : AbstractGUI mainColor = Color.Gray, fontName = "Fonts\\Font" }; - playButton.LeftButtonPressed += () => + singleButton.LeftButtonPressed += () => { // single Server server = new Server(); Client client = new Client(); - server.CreateRoom(2); - TextBox textBox = new TextBox(Manager) { text = client.networkManager.SocketConnected().ToString()}; + server.CreateRoom(1); + client.JoinYourself(); + + AppManager.Instance.SetServer(server); + AppManager.Instance.SetClient(client); + AppManager.Instance.ChangeState(GameState.HostPlaying); + + string key = client.IsConnected.ToString(); + AppManager.Instance.debugHud.Set(key,"SinglePlayer"); // ваш код здесь }; - Elements.Add(playButton); + Elements.Add(singleButton); Button optionButton = new Button(Manager) { rectangle = new Rectangle(width / 2 + width / 4 - (width / 7) / 2, height / 2, (int)(width / 7), (int)(height / 20)), @@ -57,11 +64,25 @@ public class SelectModeMenu : AbstractGUI }; optionButton.LeftButtonPressed += () => { + AppManager.Instance.SetGUI(new SelectingServerGUI()); // multi - + Server server = new Server(); //Server Logic SinglePlayer + Client client = new Client(); + server.CreateRoom(1); + client.JoinYourself(); + AppManager.Instance.SetServer(server); + AppManager.Instance.SetClient(client); // ваш код здесь }; Elements.Add(optionButton); + + 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); + bTExit.LeftButtonPressed += () => + { + AppManager.Instance.SetGUI(new MainMenuGUI()); + }; } public override void Update(GameTime gameTime) diff --git a/ZoFo/GameCore/GUI/SelectingServerGUI.cs b/ZoFo/GameCore/GUI/SelectingServerGUI.cs index 0a7f049..a108a29 100644 --- a/ZoFo/GameCore/GUI/SelectingServerGUI.cs +++ b/ZoFo/GameCore/GUI/SelectingServerGUI.cs @@ -9,19 +9,94 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using MonogameLibrary.UI.Base; using MonogameLibrary.UI.Elements; +using ZoFo.GameCore.GameManagers; namespace ZoFo.GameCore.GUI; public class SelectingServerGUI : AbstractGUI { + private DrawableUIElement menuBackground; protected override void CreateUI() { - // int width = AppManager.Instance.inGameHUDHelperResolution.X; - // int height = AppManager.Instance.inGameHUDHelperResolution.Y; + 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\\join" }; + 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 = "Select server", fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font"}); + + TextBox ipBox = new TextBox(Manager) + { + rectangle = new Rectangle(width / 4 - (width / 4) / 2, height / 4, (int)(width / 4), (int)(height / 20)), + text = "ip", + scale = 0.2f, + fontColor = Color.White, + mainColor = Color.Gray, + textAligment = MonogameLibrary.UI.Enums.TextAligment.Left, + fontName = "Fonts\\Font" + }; + ipBox.TextChanged += input => { + if (input == "ip") + { + ipBox.text = ""; ipBox.fontColor = Color.White; + } + }; + ipBox.StopChanging += input => { + if (input.Length == 0) + { + ipBox.fontColor = Color.White; + ipBox.text = "ip"; + } + }; + Elements.Add(ipBox); + Button joinButton = new Button(Manager) + { + rectangle = new Rectangle(width / 4 + (width / 4) / 2, height / 4, (int)(width / 15), (int)(height / 20)), + text = "Join", + scale = 0.3f, + fontColor = Color.White, + mainColor = Color.Gray, + fontName = "Fonts\\Font" + }; + joinButton.LeftButtonPressed += () => + { + AppManager.Instance.SetGUI(new WaitingForPlayersGUI(false)); + // join + + // ваш код здесь + }; + Elements.Add(joinButton); + Button hostButton = new Button(Manager) + { + rectangle = new Rectangle(width / 4 + (width / 4) / 2 + (width / 15), height / 4, (int)(width / 15), (int)(height / 20)), + text = "Host", + scale = 0.3f, + fontColor = Color.White, + mainColor = Color.Gray, + fontName = "Fonts\\Font" + }; + hostButton.LeftButtonPressed += () => + { + AppManager.Instance.SetGUI(new WaitingForPlayersGUI(true)); + // host + + // ваш код здесь + }; + Elements.Add(hostButton); + + 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); + bTExit.LeftButtonPressed += () => + { + AppManager.Instance.SetGUI(new SelectModeMenu()); + }; } public override void Update(GameTime gameTime) { - + base.Update(gameTime); } } \ No newline at end of file diff --git a/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs b/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs index 893efc6..5c9250d 100644 --- a/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs +++ b/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs @@ -9,19 +9,61 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using MonogameLibrary.UI.Base; using MonogameLibrary.UI.Elements; +using ZoFo.GameCore.GameManagers; namespace ZoFo.GameCore.GUI; public class WaitingForPlayersGUI : AbstractGUI { + private DrawableUIElement menuBackground; + private bool isHost; + + public WaitingForPlayersGUI(bool isHost) + { + this.isHost = isHost; + } protected override void CreateUI() { - // int width = AppManager.Instance.inGameHUDHelperResolution.X; - // int height = AppManager.Instance.inGameHUDHelperResolution.Y; + 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"}); + + if (isHost) + { + Button startButton = new Button(Manager) + { + rectangle = new Rectangle(width / 2 - (width / 15) / 2, height / 2 + height / 4, (int)(width / 15), (int)(height / 20)), + text = "Start", + scale = 0.3f, + fontColor = Color.White, + mainColor = Color.Gray, + fontName = "Fonts\\Font" + }; + startButton.LeftButtonPressed += () => + { + // start + + // ваш код здесь + }; + Elements.Add(startButton); + } + + 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); + bTExit.LeftButtonPressed += () => + { + AppManager.Instance.SetGUI(new SelectingServerGUI()); + }; } public override void Update(GameTime gameTime) { - + base.Update(gameTime); } } \ No newline at end of file diff --git a/ZoFo/GameCore/GameManagers/AppManager.cs b/ZoFo/GameCore/GameManagers/AppManager.cs index 6b111bd..c2c8756 100644 --- a/ZoFo/GameCore/GameManagers/AppManager.cs +++ b/ZoFo/GameCore/GameManagers/AppManager.cs @@ -113,8 +113,6 @@ namespace ZoFo.GameCore.GameManagers { GraphicsDevice.Clear(Color.CornflowerBlue); - - currentGUI.Draw(_spriteBatch); debugHud.Draw(_spriteBatch); switch (gamestate) diff --git a/ZoFo/GameCore/GameManagers/InputManager.cs b/ZoFo/GameCore/GameManagers/InputManager.cs index 642aefc..0dfbc1b 100644 --- a/ZoFo/GameCore/GameManagers/InputManager.cs +++ b/ZoFo/GameCore/GameManagers/InputManager.cs @@ -3,63 +3,59 @@ using Microsoft.Xna.Framework.Input; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Formats.Tar; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers { - public enum ScopeState { Up, Middle, Down } - public enum ControlsState { Gamepad, Keyboard } + public enum ScopeState { Left, Right, Straight, Back, StraightLeft, StraightRight, BackLeft, BackRight } public class InputManager { public delegate void Delegat(); - public event Delegat MovEventJump; - public event Delegat MovEventDown; - public event Delegat ShootEvent; + public event Delegat ShootEvent; // событие удара(когда нажат X, событие срабатывает) + + public event Delegat OnInteract; // событие взаимодействия с collectable(например, лутом) + //с помощью кнопки E. + + public event Delegat TalkEvent; Vector2 vectorMovementDirection; - ScopeState scopeState; // Положение оружия. Up, Middle, Down. - ControlsState controlsState; - private bool _overrideControls = false; + ScopeState currentScopeState; // Положение оружия. Left, Right, Straight, Back, StraightLeft, StraightRight, BackLeft, BackRight. private bool _cheatsEnabled = false; public bool InvincibilityCheat { get; private set; } = false; public bool CollisionsCheat { get; private set; } = false; public bool InfiniteAmmoCheat { get; private set; } = false; - private bool isJumpDown; // Блокирует физическое нажатие прыжка и спуска private bool isShoot; + private bool isInteract; private KeyboardState lastKeyboardState; private GamePadState lastGamePadState; public Vector2 VectorMovementDirection { get => vectorMovementDirection; } - public ScopeState ScopeState { get => scopeState; } + public ScopeState ScopeState { get => currentScopeState; } public string currentControlsState; + public ScopeState CurrentScopeState { get => currentScopeState; } // получить текущее состояние public InputManager() { - this.isJumpDown = false; this.isShoot = false; - scopeState = ScopeState.Middle; - controlsState = ControlsState.Keyboard; + currentScopeState = ScopeState.Straight; vectorMovementDirection = new Vector2(0, 0); } public void Update() { if (_cheatsEnabled) { - //AppManager.Instance.DebugHUD.Set("cheats", _cheatsEnabled.ToString()); - //AppManager.Instance.DebugHUD.Set("invincible", InvincibilityCheat.ToString()); - //AppManager.Instance.DebugHUD.Set("infinite ammo", InfiniteAmmoCheat.ToString()); //TODO + AppManager.Instance.debugHud.Set("cheats", _cheatsEnabled.ToString()); + AppManager.Instance.debugHud.Set("invincible", InvincibilityCheat.ToString()); + AppManager.Instance.debugHud.Set("infinite ammo", InfiniteAmmoCheat.ToString()); //TODO } #region Работа с GamePad - if (_overrideControls ? controlsState == ControlsState.Gamepad : GamePad.GetState(0).IsConnected) - { - controlsState = ControlsState.Gamepad; - #region Обработка гейм-пада. Задает Vector2 vectorMovementDirection являющийся вектором отклонения левого стика. GamePadState gamePadState = GamePad.GetState(0); vectorMovementDirection = gamePadState.ThumbSticks.Left; @@ -78,56 +74,57 @@ namespace ZoFo.GameCore.GameManagers } #endregion // Cheats - #region Обработка нажатия прыжка и спуска. Вызывает события MovEvent. - if (vectorMovementDirection.Y < -0.2 && gamePadState.Buttons.A == ButtonState.Pressed && !isJumpDown) - { - isJumpDown = true; - MovEventDown?.Invoke(); - Debug.WriteLine("Спуск"); - } - else if (gamePadState.Buttons.A == ButtonState.Pressed && lastGamePadState.Buttons.A == ButtonState.Released) - { - MovEventJump?.Invoke(); - Debug.WriteLine("Прыжок"); - } - #endregion - #region Обработка положения оружия. Задает значение полю scopeState. - if (vectorMovementDirection.Y >= 0.7) + if (vectorMovementDirection.Y >= 0.6) { - scopeState = ScopeState.Up; + currentScopeState = ScopeState.Straight; } - else if (vectorMovementDirection.Y <= -0.7 && !isJumpDown) + else if(vectorMovementDirection.Y <= 0.6) { - scopeState = ScopeState.Down; + currentScopeState = ScopeState.Back; } - else + else if(vectorMovementDirection.X >= 0.6) { - scopeState = ScopeState.Middle; + currentScopeState = ScopeState.Right; + } + else if(vectorMovementDirection.X <= 0.6) + { + currentScopeState = ScopeState.Left; + } + else if(vectorMovementDirection.Y >= 0.6 && vectorMovementDirection.X >= 0.6) + { + currentScopeState = ScopeState.StraightRight; + } + else if(vectorMovementDirection.Y >= 0.6 && vectorMovementDirection.X <= 0.6) + { + currentScopeState = ScopeState.StraightLeft; + } + else if(vectorMovementDirection.Y <= 0.6 && vectorMovementDirection.X >= 0.6) + { + currentScopeState = ScopeState.BackRight; + } + else if(vectorMovementDirection.Y <= 0.6 && vectorMovementDirection.X <= 0.6) + { + currentScopeState = ScopeState.BackLeft; } #endregion #region Обработка нажатия выстрела. Вызывает событие ShootEvent - if (gamePadState.Buttons.X == ButtonState.Pressed && !isJumpDown && !isShoot) + if (gamePadState.Buttons.X == ButtonState.Pressed && !isShoot) { isShoot = true; ShootEvent?.Invoke(); Debug.WriteLine("Выстрел"); } - else if (gamePadState.Buttons.X == ButtonState.Released && !isJumpDown) + else if (gamePadState.Buttons.X == ButtonState.Released) { isShoot = false; } #endregion lastGamePadState = gamePadState; - } #endregion #region Работа с KeyBoard - else - { - controlsState = ControlsState.Keyboard; - #region Состояние клавиатуры KeyboardState keyBoardState = Keyboard.GetState(); // Состояние клавиатуры #endregion @@ -154,76 +151,73 @@ namespace ZoFo.GameCore.GameManagers } #endregion // Cheats - #region Обработка движения вправо-влево. Меняет у вектора vectorMovementDirection значение X на -1/0/1. - if (keyBoardState.IsKeyDown(Keys.Left)) + #region Обработка состояния объекта. Задает значение полю scopeState. + if (keyBoardState.IsKeyDown(Keys.Up) || keyBoardState.IsKeyDown(Keys.W)) { - vectorMovementDirection.X = -1; + currentScopeState = ScopeState.Straight; } - else if (keyBoardState.IsKeyDown(Keys.Right)) + else if (keyBoardState.IsKeyDown(Keys.Down) || keyBoardState.IsKeyDown(Keys.S)) { - vectorMovementDirection.X = 1; + currentScopeState = ScopeState.Back; } - else + else if(keyBoardState.IsKeyDown(Keys.Left) || keyBoardState.IsKeyDown(Keys.A)) { - vectorMovementDirection.X = 0; + currentScopeState = ScopeState.Left; } - #endregion - - #region Обработка прыжка и спуска. Вызываются события MovEvent. - if (keyBoardState.IsKeyDown(Keys.LeftShift) && !isJumpDown && keyBoardState.IsKeyDown(Keys.Down)) + else if(keyBoardState.IsKeyDown(Keys.Right) || keyBoardState.IsKeyDown(Keys.D)) { - isJumpDown = true; - MovEventDown?.Invoke(); - Debug.WriteLine("Спуск"); + currentScopeState = ScopeState.Right; } - else if (keyBoardState.IsKeyDown(Keys.LeftShift) && !isJumpDown) + else if(keyBoardState.IsKeyDown(Keys.Right) && keyBoardState.IsKeyDown(Keys.Up) || + keyBoardState.IsKeyDown(Keys.D) && keyBoardState.IsKeyDown(Keys.W)) { - isJumpDown = true; - MovEventJump?.Invoke(); - Debug.WriteLine("Прыжок"); + currentScopeState = ScopeState.StraightRight; } - else if (keyBoardState.IsKeyUp(Keys.LeftShift)) + else if(keyBoardState.IsKeyDown(Keys.Left) && keyBoardState.IsKeyDown(Keys.Up) || + keyBoardState.IsKeyDown(Keys.A) && keyBoardState.IsKeyDown(Keys.W)) { - isJumpDown = false; + currentScopeState = ScopeState.StraightLeft; } - #endregion - - #region Обработка положения оружия. Задает значение полю scopeState. - if (keyBoardState.IsKeyDown(Keys.Up)) + else if(keyBoardState.IsKeyDown(Keys.Right) && keyBoardState.IsKeyDown(Keys.Down) || + keyBoardState.IsKeyDown(Keys.D) && keyBoardState.IsKeyDown(Keys.S)) { - scopeState = ScopeState.Up; + currentScopeState = ScopeState.BackRight; } - else if (keyBoardState.IsKeyDown(Keys.Down) && !isJumpDown) + else if(keyBoardState.IsKeyDown(Keys.Left) && keyBoardState.IsKeyDown(Keys.Down) || + keyBoardState.IsKeyDown(Keys.A) && keyBoardState.IsKeyDown(Keys.S)) { - scopeState = ScopeState.Down; - } - else - { - scopeState = ScopeState.Middle; + currentScopeState = ScopeState.BackLeft; } #endregion #region Обработка нажатия выстрела. Вызывает событие ShootEvent - if (keyBoardState.IsKeyDown(Keys.X) && !isJumpDown && !isShoot) + if (keyBoardState.IsKeyDown(Keys.P) && !isShoot) { isShoot = true; ShootEvent?.Invoke(); Debug.WriteLine("Выстрел"); } - else if (keyBoardState.IsKeyUp(Keys.X) && !isJumpDown) + else if (keyBoardState.IsKeyUp(Keys.P)) { isShoot = false; } #endregion - SetState(ControlsState.Keyboard); + #region Обработка взаимодействия с collectable(например лутом). Вызывает событие OnInteract + if (keyBoardState.IsKeyDown(Keys.E) && !isInteract) + { + + OnInteract?.Invoke(); + Debug.WriteLine("взаимодействие с Collectable"); + } + else if (keyBoardState.IsKeyUp(Keys.E)) + { + isInteract = false; + } + #endregion lastKeyboardState = keyBoardState; - } + #endregion } - public void SetState(ControlsState controlsState) - { - currentControlsState = controlsState.ToString(); - } } } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs index eae3a45..f833988 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs @@ -21,6 +21,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager List updates = new List(); public delegate void OnDataSent(string Data); public event OnDataSent GetDataSent; // event + public bool IsConnected { get { return socket.Connected; } } public ClientNetworkManager() { @@ -69,8 +70,8 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager listen.Start(); } - /// - /// создается одиночная комната к которой ты подключаешься + /// + /// создается одиночная комната к которой ты подключаешься /// public void JoinYourself() // single player { diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs index c092973..b4213e7 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs @@ -29,7 +29,10 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager public ServerNetworkManager() { Init(); } - public void Init() //create Socket + /// + /// Initialize varibles and Sockets + /// + private void Init() { endPoint = new IPEndPoint(ip, port); socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); @@ -37,7 +40,9 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager clients = new List(); updates = new List(); managerThread = new Dictionary(); + socket.Bind(endPoint); } + /// /// отправляет клиенту Data /// @@ -50,6 +55,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager item.SendAsync(databytes); } } + /// /// добавляет в лист updates новую data /// @@ -57,8 +63,12 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager public void AddData(IUpdateData data) { updates.Add(data); - } - public void CloseConnection() //По сути коне игры и отключение игроков + } + + /// + /// По сути конец игры и отключение игроков + /// + public void CloseConnection() { foreach (var item in clients) { @@ -79,6 +89,10 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager clients.Clear(); } + /// + /// Начинает работу сервера (Ожидает подключений) + /// + /// public void Start(object players) { serverTheread = new Thread(StartWaitingForPlayers); @@ -86,10 +100,15 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager } //Потоки Клиентов - public void StartWaitingForPlayers(object players)//Слушает игроков, которые хотят подключиться + + /// + /// Слушает игроков, которые хотят подключиться + /// + /// + public void StartWaitingForPlayers(object players) { int playNumber = (int)players; - socket.Bind(endPoint); + socket.Listen(playNumber); for (int i = 0; i < playNumber; i++) { @@ -101,7 +120,12 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager } } - private void StartListening(object socket)//начать слушать клиентов в самой игре активируют Ивент + + /// + /// начать слушать клиентов в самой игре активируют Ивент + /// + /// + private void StartListening(object socket) { // obj to Socket Socket client = (Socket)socket; diff --git a/ZoFo/GameCore/GameObjects/Entities/Entity.cs b/ZoFo/GameCore/GameObjects/Entities/Entity.cs index 10283c5..a1ab30b 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Entity.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Entity.cs @@ -13,25 +13,11 @@ namespace ZoFo.GameCore.GameObjects.Entities protected override GraphicsComponent graphicsComponent => null; public CollisionComponent collisionComponent { get; protected set; } public int Id { get; set; } - public void CollisionComponent() + protected Entity(Vector2 position) : base(position) { - - } - - public void AnimationComponent() - { - - } - - public void UpdateLogic() - { - } + } } -//вектор -//вилосити -//поситион -//текстура diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs index 843258f..b900e4a 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs @@ -1,7 +1,10 @@ -using System; +using Microsoft.Xna.Framework; +using System; namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables; public class Collectable : Entity { - + public Collectable(Vector2 position) : base(position) + { + } } diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Enemy.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Enemy.cs index 9a3b320..f948689 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Enemy.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Enemy.cs @@ -2,10 +2,13 @@ using System.Collections.Generic; using System.Net.Mime; using System.Reflection; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies; public class Enemy : LivingEntity { - + public Enemy(Vector2 position) : base(position) + { + } } \ 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 d09be3a..05a27ec 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs @@ -9,6 +9,9 @@ public class LivingEntity : Entity { public Vector2 velocity; + public LivingEntity(Vector2 position) : base(position) + { + } public void TextureLoad(SpriteBatch spriteBatch) { diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs index 39b9037..744b2c4 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs @@ -9,6 +9,10 @@ public class Player : LivingEntity private int health; Server server = new Server(); + public Player(Vector2 position) : base(position) + { + } + public void Update(GameTime gameTime) { // server.AddData(); diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Projectiles/Bullet.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Projectiles/Bullet.cs index 83643f0..b72f394 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Projectiles/Bullet.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Projectiles/Bullet.cs @@ -1,7 +1,10 @@ -using System; +using Microsoft.Xna.Framework; +using System; namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Projectiles; public class Bullet : Projectile { - + public Bullet(Vector2 position) : base(position) + { + } } diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Projectiles/Projectile.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Projectiles/Projectile.cs index dba7dae..3ae0f0b 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Projectiles/Projectile.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Projectiles/Projectile.cs @@ -1,7 +1,10 @@ -using System; +using Microsoft.Xna.Framework; +using System; namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Projectiles; public class Projectile : LivingEntity { - + public Projectile(Vector2 position) : base(position) + { + } } diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Projectiles/Rock.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Projectiles/Rock.cs index caf91a4..fa20896 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Projectiles/Rock.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Projectiles/Rock.cs @@ -1,7 +1,10 @@ -using System; +using Microsoft.Xna.Framework; +using System; namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Projectiles; public class Rock : Projectile { - + public Rock(Vector2 position) : base(position) + { + } } diff --git a/ZoFo/GameCore/GameObjects/GameObject.cs b/ZoFo/GameCore/GameObjects/GameObject.cs index 813c583..d309bf9 100644 --- a/ZoFo/GameCore/GameObjects/GameObject.cs +++ b/ZoFo/GameCore/GameObjects/GameObject.cs @@ -1,5 +1,8 @@  using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.ZoFo_graphics; namespace ZoFo.GameCore.GameObjects; @@ -7,9 +10,82 @@ namespace ZoFo.GameCore.GameObjects; public abstract class GameObject { public Vector2 position; - public Vector2 rotation; - + public Vector2 rotation; //вектор направления объекта protected abstract GraphicsComponent graphicsComponent { get; } - public void Draw() { } + #region ServerSide + public GameObject(Vector2 position) + { + this.position = position; + } + public virtual void UpdateLogic(GameTime gameTime) + { + PlayAnimation_OnServer(); + } + + + /// + /// Это вызывается в логике игры, которая на сервере, здесь будет вызываться уведомление об анимации + /// + public void PlayAnimation_OnServer() + { + graphicsComponent.Update(); + } + + #endregion + + + #region Client Side + + /// + /// Для клиента + /// Это вызывается в клиентской части игры + /// + public void PlayAnimation_OnClient() + { + graphicsComponent.Update(); + } + + /// + /// Для клиента + /// Загрузка графического компонента + /// + public void LoadContent() + { + graphicsComponent.LoadContent(); + } + + /// + /// Для клиента + /// Обновление, которое вызывается у клиента, для просмотра анимаций + /// + public virtual void UpdateAnimations(GameTime gameTime) + { + PlayAnimation_OnClient(); + } + + /// + /// Для клиента + /// + public virtual void Draw(SpriteBatch spriteBatch) + { + graphicsComponent.DrawAnimation(graphicsComponent.ObjectDrawRectangle, spriteBatch); + //debug + if (AppManager.Instance.InputManager.CollisionsCheat) + DrawDebugRectangle(spriteBatch, graphicsComponent.ObjectDrawRectangle); + + } + public void DrawDebugRectangle(SpriteBatch spriteBatch, Rectangle _rectangle, Nullable color = null) + { + if (color is null) color = new Color(1, 0, 0, 0.25f); + if (color.Value.A == 255) color = new Color(color.Value, 0.25f); + //spriteBatch.Draw(debugTexture, + // new Rectangle((_rectangle.X - GraphicsComponent.CameraPosition.X) * GraphicsComponent.scaling, + // (_rectangle.Y - GraphicsComponent.CameraPosition.Y) * GraphicsComponent.scaling, + // _rectangle.Width * GraphicsComponent.scaling, + // _rectangle.Height * GraphicsComponent.scaling), color.Value); + + //TODO: debugTexture + } + #endregion } \ No newline at end of file diff --git a/ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs b/ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs new file mode 100644 index 0000000..642b8fb --- /dev/null +++ b/ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs @@ -0,0 +1,30 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ZoFo.GameCore.GameManagers; +using ZoFo.GameCore.ZoFo_graphics; + +namespace ZoFo.GameCore.GameObjects.MapObjects +{ + public class MapObject : GameObject + { + public virtual bool IsColliderOn { get; protected set; } = true; + private Rectangle _sourceRectangle; + protected override GraphicsComponent graphicsComponent => new("tiles"); + + public MapObject(Vector2 position, Vector2 size, Rectangle sourceRectangle, string textureName) : base(position) + { + _sourceRectangle = sourceRectangle; + graphicsComponent.ObjectDrawRectangle = new Rectangle(0,0, (int)size.X, (int)size.Y); + } + public override void Draw(SpriteBatch spriteBatch) + { + graphicsComponent.DrawAnimation(graphicsComponent.ObjectDrawRectangle, spriteBatch, _sourceRectangle); + } + + } +} diff --git a/ZoFo/GameCore/GameObjects/MapObjects/StopObjects/StopObject.cs b/ZoFo/GameCore/GameObjects/MapObjects/StopObjects/StopObject.cs new file mode 100644 index 0000000..862c6bb --- /dev/null +++ b/ZoFo/GameCore/GameObjects/MapObjects/StopObjects/StopObject.cs @@ -0,0 +1,15 @@ +using Microsoft.Xna.Framework; +using System; +using ZoFo.GameCore.GameManagers.CollisionManager; +using ZoFo.GameCore.ZoFo_graphics; + +namespace ZoFo.GameCore.GameObjects.MapObjects.StopObjects; + +public class StopObject : MapObject +{ + CollisionComponent collisionComponent; + + protected StopObject(Vector2 position, Vector2 size, Rectangle sourceRectangle, string textureName) : base(position, size, sourceRectangle, textureName) + { + } +} diff --git a/ZoFo/GameCore/GameObjects/MapObjects/Tiles/Tile.cs b/ZoFo/GameCore/GameObjects/MapObjects/Tiles/Tile.cs new file mode 100644 index 0000000..eb166b8 --- /dev/null +++ b/ZoFo/GameCore/GameObjects/MapObjects/Tiles/Tile.cs @@ -0,0 +1,8 @@ +using System; + +namespace ZoFo.GameCore.GameObjects.MapObjects.Tiles; + +public class Tile +{ + +} diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index 9faf5df..5385ce5 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -15,9 +15,7 @@ namespace ZoFo.GameCore { public class Server { - private List gameObjects; private ServerNetworkManager networkManager; - private List entity; //entity public Server() { networkManager = new ServerNetworkManager(); @@ -30,13 +28,14 @@ namespace ZoFo.GameCore //ТУТ Switch case будет честное слово } /// - /// Для красоты) Отдел Серверов + /// Для красоты) Отдел Серверов /// /// public void AddData(IUpdateData data)//добавляет в лист updates новую data { networkManager.AddData(data); } + /// /// Создает комнату и запускает ожидание подключений /// @@ -56,11 +55,22 @@ namespace ZoFo.GameCore UpdateGameEnded gameEnded = new UpdateGameEnded(); networkManager.AddData(gameEnded); networkManager.CloseConnection(); - } - public void Update(GameTime gameTime) - { } + private List gameObjects; + private List entities; //entity + public void Update(GameTime gameTime) + { + foreach (var go in gameObjects) + { + go.UpdateLogic(gameTime); + } + } + + /// + /// Регистрирует игровой объект + /// + /// public void RegisterEntity(GameObject gameObject) { gameObjects.Add(gameObject); diff --git a/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs b/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs index a60cee1..b6ab88a 100644 --- a/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs +++ b/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs @@ -15,6 +15,10 @@ namespace ZoFo.GameCore.ZoFo_graphics public class GraphicsComponent { + public Rectangle ObjectDrawRectangle { get; set; } + + + public event Action actionOfAnimationEnd; private List animations; private List textures;