From 424583837a4458606e3eb3e5d8bd19ff989b5cb3 Mon Sep 17 00:00:00 2001 From: AnloGames <7383an@gmail.com> Date: Fri, 18 Aug 2023 01:20:35 +0300 Subject: [PATCH 1/7] Pre 3 player support --- .../GameObjects/LivingEntities/Player/Player.cs | 12 +++++++----- DangerousD/GameCore/Managers/AppManager.cs | 12 +++++++++--- DangerousD/GameCore/Managers/GameManager.cs | 5 ++--- DangerousD/GameCore/Managers/MapManager.cs | 12 +++++++++++- DangerousD/GameCore/Managers/PhysicsManager.cs | 6 +++--- DangerousD/GameCore/Network/NetworkManager.cs | 13 +++++++++---- 6 files changed, 41 insertions(+), 19 deletions(-) diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index 03c24b6..5149e24 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -27,15 +27,17 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities private bool isAttacked = false; public GameObject objectAttack; - public Player(Vector2 position) : base(position) + public Player(Vector2 position, bool isNetworkPlayer = false) : base(position) { Width = 16; Height = 32; - AppManager.Instance.InputManager.ShootEvent += Shoot; - - AppManager.Instance.InputManager.MovEventJump += Jump; - AppManager.Instance.InputManager.MovEventDown += MoveDown; + if (!isNetworkPlayer) + { + AppManager.Instance.InputManager.ShootEvent += Shoot; + AppManager.Instance.InputManager.MovEventJump += Jump; + AppManager.Instance.InputManager.MovEventDown += MoveDown; + } velocity = new Vector2(0, 0); rightBorder = (int)position.X + 100; diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index 5e53677..49187a0 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -231,16 +231,22 @@ namespace DangerousD.GameCore case NetworkTaskOperationEnum.ChangeState: break; case NetworkTaskOperationEnum.ConnectToHost: - Player connectedPlayer = new Player(Vector2.Zero); + Player connectedPlayer = new Player(Vector2.Zero, true); NetworkTasks.Add(new NetworkTask(connectedPlayer.id)); NetworkTask task = new NetworkTask(); - NetworkTasks.Add(task.AddConnectedPlayer(GameManager.GetPlayer1.id, GameManager.GetPlayer1.Pos)); + foreach (Player player in GameManager.players) + { + if (player.id != connectedPlayer.id) + { + NetworkTasks.Add(task.AddConnectedPlayer(player.id, player.Pos)); + } + } break; case NetworkTaskOperationEnum.GetClientPlayerId: GameManager.GetPlayer1.id = networkTask.objId; break; case NetworkTaskOperationEnum.AddConnectedPlayer: - Player remoteConnectedPlayer = new Player(networkTask.position); + Player remoteConnectedPlayer = new Player(networkTask.position, true); remoteConnectedPlayer.id = networkTask.objId; GameManager.players.Add(remoteConnectedPlayer); break; diff --git a/DangerousD/GameCore/Managers/GameManager.cs b/DangerousD/GameCore/Managers/GameManager.cs index 7e4851a..d4363d5 100644 --- a/DangerousD/GameCore/Managers/GameManager.cs +++ b/DangerousD/GameCore/Managers/GameManager.cs @@ -99,7 +99,8 @@ namespace DangerousD.GameCore public void Update(GameTime gameTime) { - AppManager.Instance.DebugHUD.Set("playerId: ", GetPlayer1.id.ToString()); + Player p = players.Find(x => x.id == 16); + if (p != null) AppManager.Instance.DebugHUD.Set("NextPlayerVelocity: ", p.velocity.ToString()); if (AppManager.Instance.NetworkTasks.Count > 0) { AppManager.Instance.NetworkManager.SendMsg(AppManager.Instance.NetworkTasks.ToList()); @@ -117,7 +118,6 @@ namespace DangerousD.GameCore { livingEntitiesWithoutPlayers[i].Update(gameTime); } - GetPlayer1.Update(gameTime); } else { @@ -125,7 +125,6 @@ namespace DangerousD.GameCore { livingEntitiesWithoutPlayers[i].PlayAnimation(); } - GetPlayer1.Update(gameTime); } GetPlayer1.Update(gameTime); foreach (var item in otherObjects) diff --git a/DangerousD/GameCore/Managers/MapManager.cs b/DangerousD/GameCore/Managers/MapManager.cs index 5d7d6fc..3367a2f 100644 --- a/DangerousD/GameCore/Managers/MapManager.cs +++ b/DangerousD/GameCore/Managers/MapManager.cs @@ -9,6 +9,7 @@ using Microsoft.Xna.Framework.Graphics; using System.Xml.Serialization; using DangerousD.GameCore.GameObjects; using System.Globalization; +using DangerousD.GameCore.GameObjects.LivingEntities; namespace DangerousD.GameCore.Managers { @@ -106,7 +107,16 @@ namespace DangerousD.GameCore.Managers foreach (XmlNode entity in group.ChildNodes) { Type type = Type.GetType($"DangerousD.GameCore.GameObjects.{entityType}"); - Entity inst = (Entity)Activator.CreateInstance(type, new Vector2(float.Parse(entity.Attributes["x"].Value, CultureInfo.InvariantCulture) + offsetX, float.Parse(entity.Attributes["y"].Value, CultureInfo.InvariantCulture) + offsetY) * _scale); + Vector2 vector = new Vector2(float.Parse(entity.Attributes["x"].Value, CultureInfo.InvariantCulture) + offsetX, float.Parse(entity.Attributes["y"].Value, CultureInfo.InvariantCulture) + offsetY); + Entity inst; + if (type.Equals(typeof(Player))) + { + inst = (Entity)Activator.CreateInstance(type, vector * _scale, false); + } + else + { + inst = (Entity)Activator.CreateInstance(type, vector * _scale); + } inst.SetPosition(new Vector2(inst.Pos.X, inst.Pos.Y - inst.Height)); inst.Height *= _scale; inst.Width *= _scale; diff --git a/DangerousD/GameCore/Managers/PhysicsManager.cs b/DangerousD/GameCore/Managers/PhysicsManager.cs index 7899c98..95bb8a1 100644 --- a/DangerousD/GameCore/Managers/PhysicsManager.cs +++ b/DangerousD/GameCore/Managers/PhysicsManager.cs @@ -21,9 +21,9 @@ namespace DangerousD.GameCore.Managers item.velocity = item.velocity + item.acceleration * delta; } - CheckCollisionsLE_MO(livingEntities, mapObjects); - CheckCollisionsE_LE(entities, livingEntities); - CheckCollisionsLE_LE(livingEntities); + CheckCollisionsLE_MO(livingEntities.ToList(), mapObjects); + CheckCollisionsE_LE(entities, livingEntities.ToList()); + CheckCollisionsLE_LE(livingEntities.ToList()); //entities dont move //Living entities dont move diff --git a/DangerousD/GameCore/Network/NetworkManager.cs b/DangerousD/GameCore/Network/NetworkManager.cs index 292e210..2d6bfc5 100644 --- a/DangerousD/GameCore/Network/NetworkManager.cs +++ b/DangerousD/GameCore/Network/NetworkManager.cs @@ -91,7 +91,7 @@ namespace DangerousD.GameCore.Network } catch { } } - public void SendMsg(List networkTask) + public void SendMsg(List networkTask, Socket ignoreSocket = null) { byte[] Data = Encoding.Unicode.GetBytes(JsonConvert.SerializeObject(networkTask)); int count = Data.Length; @@ -101,8 +101,11 @@ namespace DangerousD.GameCore.Network { foreach (Socket socket in clientSockets) { - socket.Send(BitConverter.GetBytes(count)); - socket.Send(Data); + if (!(socket == ignoreSocket)) + { + socket.Send(BitConverter.GetBytes(count)); + socket.Send(Data); + } } } catch { } @@ -148,7 +151,9 @@ namespace DangerousD.GameCore.Network } else { - GetReceivingMessages(JsonConvert.DeserializeObject>(so.sb.ToString())); + List tasks = JsonConvert.DeserializeObject>(so.sb.ToString()); + //SendMsg(tasks, clientSocket); + GetReceivingMessages(tasks); } } catch { } From 5f36ee7b79deba5dfb0653759a9a43cf391710e7 Mon Sep 17 00:00:00 2001 From: bmvolf Date: Fri, 18 Aug 2023 02:19:11 +0300 Subject: [PATCH 2/7] edited player --- DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index 066b1d4..eef557f 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -9,6 +9,7 @@ using DangerousD.GameCore.GameObjects.PlayerDeath; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Graphics; using DangerousD.GameCore.GameObjects.LivingEntities.Monsters; +using DangerousD.GameCore.Network; namespace DangerousD.GameCore.GameObjects.LivingEntities { From f26c88ffdcbe56f6b27a22afea47d992a1d714cd Mon Sep 17 00:00:00 2001 From: bmvolf Date: Fri, 18 Aug 2023 03:16:42 +0300 Subject: [PATCH 3/7] nightCommit --- DangerousD/GameCore/GUI/HUD.cs | 4 +--- .../GameCore/GameObjects/LivingEntities/Player/Player.cs | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DangerousD/GameCore/GUI/HUD.cs b/DangerousD/GameCore/GUI/HUD.cs index 07e446a..ee17186 100644 --- a/DangerousD/GameCore/GUI/HUD.cs +++ b/DangerousD/GameCore/GUI/HUD.cs @@ -11,7 +11,6 @@ namespace DangerousD.GameCore.GUI { public class HUD : AbstractGui { - int ammout = 0; List rects = new List { }; int wigth = AppManager.Instance.inGameResolution.X; int height = AppManager.Instance.inGameResolution.Y; @@ -27,9 +26,8 @@ namespace DangerousD.GameCore.GUI } public override void Update(GameTime gameTime) { - rects.Clear(); - for (int i = 0; i < ammout; i++) + for (int i = 0; i < AppManager.Instance.GameManager.GetPlayer1.Bullets; i++) { rects.Add(new Rect(Manager) { rectangle = new Rectangle(wigth / 29 + i * 13, height / 17, 5, 20), mainColor = Color.Yellow }); rects[i].LoadTexture(AppManager.Instance.Content); diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index eef557f..2a2a7ca 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -30,6 +30,8 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities public GameObject objectAttack; private int bullets; + public int Bullets { get { return bullets; } } + public Player(Vector2 position) : base(position) { Width = 16; From 0681d14f06e52d7d6617cd967fa051320bc5eeda Mon Sep 17 00:00:00 2001 From: AnloGames <7383an@gmail.com> Date: Fri, 18 Aug 2023 04:07:28 +0300 Subject: [PATCH 4/7] Only 2 Players Support --- DangerousD/GameCore/GameObjects/GameObject.cs | 1 + DangerousD/GameCore/Managers/AppManager.cs | 21 +++++++++++++++---- DangerousD/GameCore/Managers/GameManager.cs | 2 -- DangerousD/GameCore/Network/NetworkManager.cs | 1 - 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/DangerousD/GameCore/GameObjects/GameObject.cs b/DangerousD/GameCore/GameObjects/GameObject.cs index ceb5e5a..65bf8c9 100644 --- a/DangerousD/GameCore/GameObjects/GameObject.cs +++ b/DangerousD/GameCore/GameObjects/GameObject.cs @@ -15,6 +15,7 @@ namespace DangerousD.GameCore protected Vector2 _pos; public Vector2 Pos => _pos; public int id; + public bool isIdFromHost = false; public int Width { get; set; } public int Height { get; set; } public Rectangle Rectangle => new Rectangle((int)Pos.X, (int)Pos.Y, Width, Height); diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index 49187a0..c9f5788 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -12,6 +12,7 @@ using MonogameLibrary.UI.Base; using DangerousD.GameCore.Managers; using DangerousD.GameCore.GameObjects.LivingEntities; using DangerousD.GameCore.GameObjects; +using System.Threading.Tasks; namespace DangerousD.GameCore { @@ -111,6 +112,8 @@ namespace DangerousD.GameCore if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); + if (GameManager.GetPlayer1 != null) + DebugHUD.Set("Objid: ", GameManager.GetPlayer1.id.ToString()); InputManager.Update(); SoundManager.Update(); @@ -225,8 +228,15 @@ namespace DangerousD.GameCore case NetworkTaskOperationEnum.CreateEntity: break; case NetworkTaskOperationEnum.SendPosition: - LivingEntity entity = GameManager.livingEntities.Find(x => x.id == networkTask.objId); - entity.SetPosition(networkTask.position); + if (networkTask.objId != GameManager.GetPlayer1.id) + { + LivingEntity entity = GameManager.livingEntities.Find(x => x.id == networkTask.objId); + entity.SetPosition(networkTask.position); + if (multiPlayerStatus == MultiPlayerStatus.Host) + { + NetworkTasks.Add(networkTask); + } + } break; case NetworkTaskOperationEnum.ChangeState: break; @@ -243,12 +253,15 @@ namespace DangerousD.GameCore } break; case NetworkTaskOperationEnum.GetClientPlayerId: - GameManager.GetPlayer1.id = networkTask.objId; + if (!GameManager.GetPlayer1.isIdFromHost) + { + GameManager.GetPlayer1.id = networkTask.objId; + GameManager.GetPlayer1.isIdFromHost = true; + } break; case NetworkTaskOperationEnum.AddConnectedPlayer: Player remoteConnectedPlayer = new Player(networkTask.position, true); remoteConnectedPlayer.id = networkTask.objId; - GameManager.players.Add(remoteConnectedPlayer); break; default: break; diff --git a/DangerousD/GameCore/Managers/GameManager.cs b/DangerousD/GameCore/Managers/GameManager.cs index d4363d5..693f4d7 100644 --- a/DangerousD/GameCore/Managers/GameManager.cs +++ b/DangerousD/GameCore/Managers/GameManager.cs @@ -99,8 +99,6 @@ namespace DangerousD.GameCore public void Update(GameTime gameTime) { - Player p = players.Find(x => x.id == 16); - if (p != null) AppManager.Instance.DebugHUD.Set("NextPlayerVelocity: ", p.velocity.ToString()); if (AppManager.Instance.NetworkTasks.Count > 0) { AppManager.Instance.NetworkManager.SendMsg(AppManager.Instance.NetworkTasks.ToList()); diff --git a/DangerousD/GameCore/Network/NetworkManager.cs b/DangerousD/GameCore/Network/NetworkManager.cs index 2d6bfc5..56ac3a1 100644 --- a/DangerousD/GameCore/Network/NetworkManager.cs +++ b/DangerousD/GameCore/Network/NetworkManager.cs @@ -152,7 +152,6 @@ namespace DangerousD.GameCore.Network else { List tasks = JsonConvert.DeserializeObject>(so.sb.ToString()); - //SendMsg(tasks, clientSocket); GetReceivingMessages(tasks); } } From 6229d7dda407187dfe8ffe7c743af1172ef5b143 Mon Sep 17 00:00:00 2001 From: AnloGames <7383an@gmail.com> Date: Fri, 18 Aug 2023 04:19:55 +0300 Subject: [PATCH 5/7] merge commit --- .../GameCore/GameObjects/LivingEntities/Player/Player.cs | 5 ----- DangerousD/GameCore/Managers/MapManager.cs | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index 7fd1732..0a986b3 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -62,11 +62,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities }; } - public Player(Vector2 position, bool isInvincible) : this(position) - { - this.isInvincible = isInvincible; - } - public bool IsAlive { get { return isAlive; } } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "playerMoveLeft", "playerMoveRight", "DeathFromZombie", "playerRightStay", "playerStayLeft", diff --git a/DangerousD/GameCore/Managers/MapManager.cs b/DangerousD/GameCore/Managers/MapManager.cs index fd23e3c..6ab49b0 100644 --- a/DangerousD/GameCore/Managers/MapManager.cs +++ b/DangerousD/GameCore/Managers/MapManager.cs @@ -98,9 +98,9 @@ namespace DangerousD.GameCore.Managers new Vector2(float.Parse(entity.Attributes["x"].Value, CultureInfo.InvariantCulture) + offsetX, float.Parse(entity.Attributes["y"].Value, CultureInfo.InvariantCulture) + offsetY) * _scale; Entity inst; - if (type.Equals(typeof(Player)) && entity.Attributes["name"] is not null && entity.Attributes["name"].Value == "DEBUGUS") + if (type.Equals(typeof(Player))) { - inst = (Entity)Activator.CreateInstance(type, pos, true); + inst = (Entity)Activator.CreateInstance(type, pos, false); } else { From 7b45a41dc1e1f376cc8c5b7a2c2214f5858cae26 Mon Sep 17 00:00:00 2001 From: Kaktus200020 Date: Fri, 18 Aug 2023 04:22:29 +0300 Subject: [PATCH 6/7] ParticlesReady --- .../Content/animations/GibsMoveLeftBottom | 1 + DangerousD/Content/animations/GibsMoveLeftTop | 1 + .../Content/animations/GibsMoveRightBottom | 1 + .../Content/animations/GibsMoveRightTop | 1 + DangerousD/Content/animations/GibsNotMove | 1 + DangerousD/Content/map.tmx | 75 +++++++++++++++++++ .../LivingEntities/Monsters/Zombie.cs | 7 ++ .../GameObjects/LivingEntities/Particle.cs | 46 ++++++++++++ 8 files changed, 133 insertions(+) create mode 100644 DangerousD/Content/animations/GibsMoveLeftBottom create mode 100644 DangerousD/Content/animations/GibsMoveLeftTop create mode 100644 DangerousD/Content/animations/GibsMoveRightBottom create mode 100644 DangerousD/Content/animations/GibsMoveRightTop create mode 100644 DangerousD/Content/animations/GibsNotMove create mode 100644 DangerousD/Content/map.tmx create mode 100644 DangerousD/GameCore/GameObjects/LivingEntities/Particle.cs diff --git a/DangerousD/Content/animations/GibsMoveLeftBottom b/DangerousD/Content/animations/GibsMoveLeftBottom new file mode 100644 index 0000000..b0f96f0 --- /dev/null +++ b/DangerousD/Content/animations/GibsMoveLeftBottom @@ -0,0 +1 @@ +{"id":"GibsMoveLeftBottom","textureName":"MonstersAnimations","startSpriteRectangle":{"X":70,"Y":724,"Width":14,"Height":11},"frameSecond":[{"Item1":0,"Item2":6}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/GibsMoveLeftTop b/DangerousD/Content/animations/GibsMoveLeftTop new file mode 100644 index 0000000..e80c714 --- /dev/null +++ b/DangerousD/Content/animations/GibsMoveLeftTop @@ -0,0 +1 @@ +{"id":"GibsMoveLeftTop","textureName":"MonstersAnimations","startSpriteRectangle":{"X":2,"Y":721,"Width":14,"Height":12},"frameSecond":[{"Item1":0,"Item2":8}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/GibsMoveRightBottom b/DangerousD/Content/animations/GibsMoveRightBottom new file mode 100644 index 0000000..246ab34 --- /dev/null +++ b/DangerousD/Content/animations/GibsMoveRightBottom @@ -0,0 +1 @@ +{"id":"GibsMoveRightBottom","textureName":"MonstersAnimations","startSpriteRectangle":{"X":106,"Y":722,"Width":13,"Height":12},"frameSecond":[{"Item1":0,"Item2":6}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/GibsMoveRightTop b/DangerousD/Content/animations/GibsMoveRightTop new file mode 100644 index 0000000..4b193fd --- /dev/null +++ b/DangerousD/Content/animations/GibsMoveRightTop @@ -0,0 +1 @@ +{"id":"GibsMoveRightTop","textureName":"MonstersAnimations","startSpriteRectangle":{"X":37,"Y":721,"Width":14,"Height":13},"frameSecond":[{"Item1":0,"Item2":6}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/GibsNotMove b/DangerousD/Content/animations/GibsNotMove new file mode 100644 index 0000000..e5333b8 --- /dev/null +++ b/DangerousD/Content/animations/GibsNotMove @@ -0,0 +1 @@ +{"id":"GibsNotMove","textureName":"MonstersAnimations","startSpriteRectangle":{"X":137,"Y":731,"Width":16,"Height":5},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/map.tmx b/DangerousD/Content/map.tmx new file mode 100644 index 0000000..813425e --- /dev/null +++ b/DangerousD/Content/map.tmx @@ -0,0 +1,75 @@ + + + + + + +294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294 + + +294,294,294,294,294,321,321,321,321,321,321,321,321,321,321,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,321,321,321,321,321,321,321,321,321,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +294,294,294,294,321,321,321,321,321,321,321,321,321,321,321,321 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs index 188dfb9..82dcc2a 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs @@ -78,7 +78,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Death() { + for (int i = 0; i < 3; i++) + { + Particle particle = new Particle(Pos); + } + AppManager.Instance.GameManager.Remove(this); + } public override void Move(GameTime gameTime) @@ -160,6 +166,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { monster_health--; GraphicsComponent.StartAnimation("ZombieRightAttack"); + Particle particle = new Particle(Pos); if (monster_health <= 0) { Death(); diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Particle.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Particle.cs new file mode 100644 index 0000000..cf08319 --- /dev/null +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Particle.cs @@ -0,0 +1,46 @@ +using DangerousD.GameCore.Graphics; +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DangerousD.GameCore.GameObjects.LivingEntities +{ + public class Particle : LivingEntity + { + int delay; + public Particle(Vector2 position) : base(position) + { + Width = 14; + Height = 14; + Random random = new Random(); + velocity = new Vector2(random.Next(3, 15), random.Next(3,30)); + acceleration.Y = 10; + delay = 100; + + } + + protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "GibsMoveLeftBottom", "GibsMoveLeftTop", "GibsMoveRightBottom", "GibsMoveRightTop" }, "GibsMoveRightTop"); + public override void Update(GameTime gameTime) + { + delay--; + if (velocity.X > 0) + { + velocity.X--; + } + if(velocity.Y<=0) + { + GraphicsComponent.StartAnimation("GipsNoMove"); +; } + if(delay<=0) + { + AppManager.Instance.GameManager.Remove(this); + } + base.Update(gameTime); + } + + } +} From 08acf4fd1f52a72a3f0420a7d662602791c79023 Mon Sep 17 00:00:00 2001 From: Timofey06 Date: Fri, 18 Aug 2023 05:11:17 +0300 Subject: [PATCH 7/7] FullCamerFixToScale4 --- DangerousD/Content/lvl.tmx | 2 +- .../GameCore/Graphics/GraphicsComponent.cs | 36 ++++++++++++++----- DangerousD/GameCore/Managers/AppManager.cs | 3 +- DangerousD/GameCore/Managers/GameManager.cs | 27 +++++++++++++- 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/DangerousD/Content/lvl.tmx b/DangerousD/Content/lvl.tmx index 5377e12..0f91aa8 100644 --- a/DangerousD/Content/lvl.tmx +++ b/DangerousD/Content/lvl.tmx @@ -752,7 +752,7 @@ - + diff --git a/DangerousD/GameCore/Graphics/GraphicsComponent.cs b/DangerousD/GameCore/Graphics/GraphicsComponent.cs index f218ba6..00d6298 100644 --- a/DangerousD/GameCore/Graphics/GraphicsComponent.cs +++ b/DangerousD/GameCore/Graphics/GraphicsComponent.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework; +using DangerousD.GameCore.Managers; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using System; @@ -16,7 +17,7 @@ namespace DangerousD.GameCore.Graphics private List textures; private List texturesNames; private AnimationContainer currentAnimation; - static private int scaling=3; + static private int scaling = 4; public AnimationContainer CurrentAnimation { get @@ -129,12 +130,12 @@ namespace DangerousD.GameCore.Graphics { if (!currentAnimation.IsCycle) { - if(actionOfAnimationEnd != null) + if (actionOfAnimationEnd != null) { actionOfAnimationEnd(currentAnimation.Id); - } + } currentAnimation = neitralAnimation; - + } currentFrame = 0; @@ -152,12 +153,12 @@ namespace DangerousD.GameCore.Graphics { Texture2D texture = textures[texturesNames.FindIndex(x => x == currentAnimation.TextureName)]; float scale; - if (currentAnimation.Offset.X!=0) + if (currentAnimation.Offset.X != 0) { destinationRectangle.X -= (int)currentAnimation.Offset.X; - scale=destinationRectangle.Height/sourceRectangle.Height; + scale = destinationRectangle.Height / sourceRectangle.Height; destinationRectangle.Width = (int)(sourceRectangle.Width * scale); - + } else if (currentAnimation.Offset.Y != 0) { @@ -235,9 +236,26 @@ namespace DangerousD.GameCore.Graphics } public static void SetCameraPosition(Vector2 playerPosition) { - CameraPosition=(playerPosition).ToPoint(); + CameraPosition = (playerPosition).ToPoint(); CameraPosition.X -= 300; CameraPosition.Y -= 200; + if (CameraPosition.X < AppManager.Instance.GameManager.CameraBorder.X) + { + CameraPosition.X = (int)AppManager.Instance.GameManager.CameraBorder.X; + } + if (CameraPosition.X > AppManager.Instance.GameManager.CameraBorder.Y - 460) + { + CameraPosition.X = (int)AppManager.Instance.GameManager.CameraBorder.Y - 460; + } + if (CameraPosition.Y < AppManager.Instance.GameManager.CameraBorder.Z) + { + CameraPosition.Y = (int)AppManager.Instance.GameManager.CameraBorder.Z; + } + if (CameraPosition.Y > AppManager.Instance.GameManager.CameraBorder.W - 470) + { + CameraPosition.Y = (int)AppManager.Instance.GameManager.CameraBorder.W - 470; + } + AppManager.Instance.DebugHUD.Set("CameraPosition", $"{CameraPosition.X}, {CameraPosition.Y}"); } public static Point CameraPosition = new Point(-700, 300); } diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index 661932c..f957271 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -202,7 +202,8 @@ namespace DangerousD.GameCore case GameState.Lobby: break; case GameState.Game: - GameManager.mapManager.LoadLevel("boss"); + GameManager.mapManager.LoadLevel("lvl"); + GameManager.FindBorders(); break; case GameState.Death: break; diff --git a/DangerousD/GameCore/Managers/GameManager.cs b/DangerousD/GameCore/Managers/GameManager.cs index 6b3c2b4..b60d776 100644 --- a/DangerousD/GameCore/Managers/GameManager.cs +++ b/DangerousD/GameCore/Managers/GameManager.cs @@ -28,7 +28,7 @@ namespace DangerousD.GameCore public PhysicsManager physicsManager; public List players; public List otherObjects = new(); - + public Vector4 CameraBorder; public Player GetPlayer1 { get; private set; } public GameManager() { @@ -42,6 +42,7 @@ namespace DangerousD.GameCore players = new List(); mapManager = new MapManager(1); physicsManager = new PhysicsManager(); + CameraBorder = Vector4.Zero; } @@ -150,6 +151,8 @@ namespace DangerousD.GameCore GetPlayer1.Update(gameTime); } else + + { for (int i = 0; i < livingEntitiesWithoutPlayers.Count; i++) { @@ -163,5 +166,27 @@ namespace DangerousD.GameCore physicsManager.UpdateCollisions(entities, livingEntities, mapObjects, players, gameTime); } + public void FindBorders() + { + foreach (var item in GetAllGameObjects) + { + if (item.Pos.X CameraBorder.Y) + { + CameraBorder.Y = item.Pos.X; + } + if (item.Pos.Y < CameraBorder.Z) + { + CameraBorder.Z = item.Pos.X; + } + if (item.Pos.Y > CameraBorder.W) + { + CameraBorder.W = item.Pos.X; + } + } + } } } \ No newline at end of file