From 8358be3a406b34a4265811ac8e8e803266d2ca95 Mon Sep 17 00:00:00 2001 From: SergoDobro Date: Sat, 17 Aug 2024 19:48:33 +0300 Subject: [PATCH 1/9] disabled Map --- ZoFo/GameCore/Server.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index ecd3683..70c5e0f 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -92,7 +92,7 @@ namespace ZoFo.GameCore collisionManager = new CollisionManager(); gameObjects = new List(); entities = new List(); - new MapManager().LoadMap(); + //new MapManager().LoadMap(); AppManager.Instance.server.RegisterGameObject(new EntittyForAnimationTests(new Vector2(40, 40))); AppManager.Instance.server.RegisterGameObject(new Player(new Vector2(140, 140))); From d0dc0c47142d84fa166e4bf5a4212addd8da7f66 Mon Sep 17 00:00:00 2001 From: PetrKu09 Date: Sat, 17 Aug 2024 19:50:47 +0300 Subject: [PATCH 2/9] Add CollisionComponent designer --- .../CollisionManager/CollisionComponent.cs | 42 +++++++------------ .../Updates/ServerToClient/UpdatePosition.cs | 1 + ZoFo/GameCore/Server.cs | 7 +++- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs index 880e159..6daa962 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework; +using Microsoft.Win32; +using Microsoft.Xna.Framework; using System; using System.Collections.Generic; using System.Linq; @@ -12,29 +13,29 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager { public class CollisionComponent { + //==КОНСТРУКТОР== + public CollisionComponent(GameObject gameObject) + { + this.gameObject = gameObject; + AppManager.Instance.server.collisionManager.Register(this); + } + + //==ПОЛЯ== public GameObject gameObject { get; set; } - //public Rectangle Bounds { get; set; } - - //public Rectangle Rectangle => new Rectangle(); - - bool doesStop; + bool hasCollision; public Rectangle stopRectangle; // triggers for rectangle bool isTrigger; - public Rectangle triggerRectanglee; + public Rectangle triggerRectangle; //delegate public delegate void EventHandler(object sender, EventArgs e); - //public CollisionComponent(int x, int y, int width, int height) - //{ - // Bounds = new Rectangle(x, y, width, height); - //} @@ -43,22 +44,11 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager public event EventHandler OnTriggerZone; public event EventHandler OnTriggerExit; + public event EventHandler OnCollision; + + // methods-event - public void TriggerEnter(object component, Player player, - EventArgs e) - { - - } - public void TriggerZone(object component,Player player, - EventArgs e) - { - - } - public void TriggerExit(object component,Player player, - EventArgs e) - { - - } + } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePosition.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePosition.cs index 8d93d7b..df1cba3 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePosition.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePosition.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using ZoFo.GameCore.GameObjects.Entities.LivingEntities; namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient { diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index d11eee1..fa9bcf4 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -7,6 +7,7 @@ using System.Text; using System.Text.Json; using System.Threading.Tasks; using ZoFo.GameCore.GameManagers; +using ZoFo.GameCore.GameManagers.CollisionManager; using ZoFo.GameCore.GameManagers.MapManager; using ZoFo.GameCore.GameManagers.NetworkManager; using ZoFo.GameCore.GameManagers.NetworkManager.Updates; @@ -21,11 +22,15 @@ namespace ZoFo.GameCore { private ServerNetworkManager networkManager; private int ticks = 0; - public IPEndPoint MyIp { get { return networkManager.InfoConnect; } } + public IPEndPoint MyIp { get { return networkManager.InfoConnect; } } + + public CollisionManager collisionManager; + public Server() { networkManager = new ServerNetworkManager(); networkManager.GetDataSend += OnDataSend; + collisionManager = new CollisionManager(); } #region server logic as App From 96e6e37b56c75bf3b52ec8a9a4a8f68d527e3d5f Mon Sep 17 00:00:00 2001 From: SergoDobro Date: Sat, 17 Aug 2024 20:12:25 +0300 Subject: [PATCH 3/9] minor fixes and cleaning --- .../CollisionManager/CollectionComponent.cs | 6 --- .../CollisionManager/CollisionComponent.cs | 42 ++++++++----------- .../CollisionManager/CollisionManager.cs | 12 +++--- .../GameManagers/ItemManager/ItemInfo.cs | 2 +- .../Entities/Interactables/Interactable.cs | 2 +- ZoFo/GameCore/Server.cs | 4 +- 6 files changed, 26 insertions(+), 42 deletions(-) delete mode 100644 ZoFo/GameCore/GameManagers/CollisionManager/CollectionComponent.cs diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollectionComponent.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollectionComponent.cs deleted file mode 100644 index 7143312..0000000 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollectionComponent.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace ZoFo.GameCore.GameManagers.CollisionManager -{ - public class CollectionComponent - { - } -} \ No newline at end of file diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs index 0132188..0313417 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs @@ -13,13 +13,29 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager { public class CollisionComponent { - //==КОНСТРУКТОР== + //==КОНСТРУКТОР== public CollisionComponent(GameObject gameObject) { + this.gameObject = gameObject; + hasCollision = false; + this.isTrigger = false; AppManager.Instance.server.collisionManager.Register(this); } + public CollisionComponent(GameObject gameObject, bool hasCollision = false, Rectangle? collisionRectangle = null, bool isTrigger = false, Rectangle? triggerRectangle = null) + { + this.gameObject = gameObject; + + hasCollision = hasCollision; + this.isTrigger = isTrigger; + if (hasCollision) + this.stopRectangle = collisionRectangle.Value; + if (isTrigger) + this.triggerRectangle = triggerRectangle.Value; + + AppManager.Instance.server.collisionManager.Register(this); + } //==ПОЛЯ== @@ -46,30 +62,8 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager public event EventHandler OnCollision; - - // methods-event + - public CollisionComponent(GameObject gameObject) - { - - this.gameObject = gameObject; - doesStop = false; - this.isTrigger = false; - AppManager.Instance.server.collisionManager.Register(this); - } - public CollisionComponent(GameObject gameObject, bool hasCollision = false, Rectangle? collisionRectangle = null, bool isTrigger = false, Rectangle? triggerRectangle = null) - { - this.gameObject = gameObject; - - doesStop = hasCollision; - this.isTrigger = isTrigger; - if (hasCollision) - this.stopRectangle = collisionRectangle.Value; - if (isTrigger) - this.triggerRectanglee = triggerRectangle.Value; - - AppManager.Instance.server.collisionManager.Register(this); - } } } diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs index 903c056..2269a32 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs @@ -31,8 +31,10 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager //for (int i = 0; i < ObjectsWithCollisions.Count; i++) //{ var currentRect = entity.collisionComponent.stopRectangle;//задаём РЕК - var newRect = currentRect; // задаём значение старого РЕК новому РЕК - bool flagRemovedObject = false; //флаг удаления + currentRect.X+=(int)entity.position.X; + currentRect.Y+=(int)entity.position.Y; + + var newRect = currentRect; // задаём значение старого РЕК новому РЕК var collidedX = false; // соприкосновение @@ -100,11 +102,7 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager entity.velocity = Vector2.Zero; } - //обновление позиции объекта - public void UpdateObjectsPositions() - { - - } + //обновление позиции объекта public void UpdatePositions() { diff --git a/ZoFo/GameCore/GameManagers/ItemManager/ItemInfo.cs b/ZoFo/GameCore/GameManagers/ItemManager/ItemInfo.cs index 375d745..cfd5a4f 100644 --- a/ZoFo/GameCore/GameManagers/ItemManager/ItemInfo.cs +++ b/ZoFo/GameCore/GameManagers/ItemManager/ItemInfo.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.ItemManager { - class ItemInfo + public class ItemInfo { //поля string tag; diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs index bfe1b42..2701d49 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs @@ -15,7 +15,7 @@ public class Interactable : Entity { collisionComponent.OnTriggerEnter += (sender, e) => ChangeInteraction(sender, e, true); collisionComponent.OnTriggerExit += (sender, e) => ChangeInteraction(sender, e, false); - collisionComponent.OnTriggerInteract += OnInteraction; + collisionComponent.OnTriggerZone += OnInteraction; } private void ChangeInteraction(object sender, CollisionComponent e, bool isReady) diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index 045f399..886f923 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -25,9 +25,7 @@ namespace ZoFo.GameCore private ServerNetworkManager networkManager; private int ticks = 0; public IPEndPoint MyIp { get { return networkManager.InfoConnect; } } - - public CollisionManager collisionManager; - + public Server() { networkManager = new ServerNetworkManager(); From 25031737292ab913f3ebcd2b1aa5d67583fc9833 Mon Sep 17 00:00:00 2001 From: SergoDobro Date: Sat, 17 Aug 2024 20:16:16 +0300 Subject: [PATCH 4/9] fastFix --- .../GameManagers/CollisionManager/CollisionManager.cs | 7 ++++--- .../Updates/ServerToClient/UpdatePosition.cs | 9 ++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs index 2269a32..2cf80af 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs @@ -96,9 +96,10 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager entity.position.X += entity.velocity.Y; newRect.Y = tryingRectY.Y;//значение по X для нового РЕК приравниваем к значению испытуемого РЕК } - - entity.collisionComponent.stopRectangle = newRect; - entity.graphicsComponent.ObjectDrawRectangle = newRect; + + entity.graphicsComponent.ObjectDrawRectangle.x = (int)entity.position.X; + entity.graphicsComponent.ObjectDrawRectangle.y = (int)entity.position.Y; + AppManager.Instance.server.AddData(new UpdatePosition() { NewPosition = entity.position }); entity.velocity = Vector2.Zero; } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePosition.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePosition.cs index df1cba3..189a299 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePosition.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePosition.cs @@ -1,6 +1,7 @@ -using System; +using Microsoft.Xna.Framework; +using System; using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Text; using System.Threading.Tasks; using ZoFo.GameCore.GameObjects.Entities.LivingEntities; @@ -10,8 +11,10 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient /// /// Хранит новую позицию /// - public class UpdatePosition : UpdateData + public class UpdatePosition : UpdateData { public UpdatePosition() { UpdateType = "UpdatePosition"; } + + public Vector2 NewPosition { get; set; } } } From b105f67df2d5b231f16d42eff08ca73e937b0c90 Mon Sep 17 00:00:00 2001 From: MARKPRO44 <119742977+MARKPRO4444@users.noreply.github.com> Date: Sat, 17 Aug 2024 21:22:18 +0300 Subject: [PATCH 5/9] FixServer --- ZoFo/GameCore/Server.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index 045f399..c562032 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -112,7 +112,6 @@ namespace ZoFo.GameCore networkManager.CloseConnection(); } - public CollisionManager collisionManager; private List gameObjects = new List(); private List entities; //entity public void Update(GameTime gameTime) From 473820b14d6ade621d4039c3d3afafbd767a766a Mon Sep 17 00:00:00 2001 From: MARKPRO44 <119742977+MARKPRO4444@users.noreply.github.com> Date: Sat, 17 Aug 2024 21:50:23 +0300 Subject: [PATCH 6/9] Fix Bags --- .../CollisionManager/CollisionComponent.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs index 0132188..c8969f8 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs @@ -14,11 +14,11 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager public class CollisionComponent { //==КОНСТРУКТОР== - public CollisionComponent(GameObject gameObject) - { - this.gameObject = gameObject; - AppManager.Instance.server.collisionManager.Register(this); - } + // public CollisionComponent(GameObject gameObject) + // { + // this.gameObject = gameObject; + // AppManager.Instance.server.collisionManager.Register(this); + // } //==ПОЛЯ== @@ -26,6 +26,7 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager public GameObject gameObject { get; set; } + bool doesStop; bool hasCollision; public Rectangle stopRectangle; @@ -67,7 +68,7 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager if (hasCollision) this.stopRectangle = collisionRectangle.Value; if (isTrigger) - this.triggerRectanglee = triggerRectangle.Value; + this.triggerRectangle = triggerRectangle.Value; AppManager.Instance.server.collisionManager.Register(this); } From a69f44468cffba8fc6532f5d00c278b919ef4c69 Mon Sep 17 00:00:00 2001 From: SergoDobro Date: Sat, 17 Aug 2024 23:13:11 +0300 Subject: [PATCH 7/9] Player now appears on client side + entityidsearch --- ZoFo/GameCore/Client.cs | 46 +++++++++++++++---- ZoFo/GameCore/GUI/DebugHUD.cs | 2 + ZoFo/GameCore/GameManagers/AppManager.cs | 3 ++ .../CollisionManager/CollisionComponent.cs | 5 +- .../CollisionManager/CollisionManager.cs | 7 +-- ZoFo/GameCore/GameObjects/Entities/Entity.cs | 14 +++++- .../Entities/LivingEntities/LivingEntity.cs | 1 + .../Entities/LivingEntities/Player/Player.cs | 9 ++-- ZoFo/GameCore/GameObjects/GameObject.cs | 13 ++++-- ZoFo/GameCore/Server.cs | 17 +++++-- 10 files changed, 92 insertions(+), 25 deletions(-) diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index 8d14374..e4da2a7 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -13,11 +13,17 @@ using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using System.Drawing; using System.Reflection; using ZoFo.GameCore.GameObjects.Entities; +using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; +using System.Linq; +using System.Web; +using ZoFo.GameCore.GUI; namespace ZoFo.GameCore { public class Client { + #region Network part + ClientNetworkManager networkManager; public bool IsConnected { get { return networkManager.IsConnected; } } @@ -39,12 +45,13 @@ namespace ZoFo.GameCore } public void GameEndedUnexpectedly() { } - public void JoinRoom(string ip,int port) + public void JoinRoom(string ip, int port) { - networkManager.JoinRoom(ip,port); + networkManager.JoinRoom(ip, port); } public void JoinYourself(int port) { networkManager.JoinYourself(port); } + #endregion List mapObjects = new List(); List gameObjects = new List(); @@ -85,20 +92,43 @@ namespace ZoFo.GameCore } else if (update is UpdateGameObjectCreated) { - var a = Assembly.GetAssembly(typeof(GameObject)); if ((update as UpdateGameObjectCreated).GameObjectType == "EntittyForAnimationTests") - { + gameObjects.Add(new EntittyForAnimationTests(new Vector2(100, 100))); + if ((update as UpdateGameObjectCreated).GameObjectType == "Player") + gameObjects.Add(new Player(new Vector2(100, 100))); - gameObjects.Add( - new EntittyForAnimationTests(new Vector2(100,100)) - ); - } + (gameObjects.Last() as Entity).SetIdByClient((update as UpdateGameObjectCreated).IdEntity); + //var a = Assembly.GetAssembly(typeof(GameObject)); //gameObjects.Add( TODO reflection //Activator.CreateInstance(Type.GetType("ZoFo.GameCore.GameObjects.Entities.EntittyForAnimationTests") ///*(update as UpdateGameObjectCreated).GameObjectType*/, new []{ new Vector2(100, 100) }) //as GameObject //); } + else if (update is UpdatePosition) + { + var ent = FindEntityById(update.IdEntity); + + ent.position = (update as UpdatePosition).NewPosition; + DebugHUD.Instance.Log("newPosition " + ent.position); + } } + + + public Entity FindEntityById(int id) + { + for (int i = 0; i < gameObjects.Count; i++) + { + if (gameObjects[i] is Entity) + { + if ((gameObjects[i] as Entity).Id == id) + { + return gameObjects[i] as Entity; + } + } + } + return null; + } + } } \ No newline at end of file diff --git a/ZoFo/GameCore/GUI/DebugHUD.cs b/ZoFo/GameCore/GUI/DebugHUD.cs index fdc5371..294530a 100644 --- a/ZoFo/GameCore/GUI/DebugHUD.cs +++ b/ZoFo/GameCore/GUI/DebugHUD.cs @@ -13,9 +13,11 @@ public class DebugHUD private SpriteFont _spriteFont; private Dictionary _text = new(); private List _log = new(); + public static DebugHUD Instance { get; private set; } public void Initialize() { + Instance = this; } public void LoadContent() diff --git a/ZoFo/GameCore/GameManagers/AppManager.cs b/ZoFo/GameCore/GameManagers/AppManager.cs index 224dba2..42e886a 100644 --- a/ZoFo/GameCore/GameManagers/AppManager.cs +++ b/ZoFo/GameCore/GameManagers/AppManager.cs @@ -12,6 +12,7 @@ using ZoFo.GameCore.GameManagers.ItemManager; using ZoFo.GameCore.GUI; using static System.Collections.Specialized.BitVector32; using MonogameLibrary.UI.Base; +using ZoFo.GameCore.GameObjects; namespace ZoFo.GameCore.GameManagers { @@ -83,6 +84,8 @@ namespace ZoFo.GameCore.GameManagers currentGUI.LoadContent(); animationBuilder = new AnimationBuilder(); animationBuilder.LoadAnimations(); + GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1); + GameObject.debugTexture.SetData(new Color[] { Color.White }); } protected override void Update(GameTime gameTime) diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs index 0313417..e4ec32d 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionComponent.cs @@ -20,7 +20,6 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager this.gameObject = gameObject; hasCollision = false; this.isTrigger = false; - AppManager.Instance.server.collisionManager.Register(this); } public CollisionComponent(GameObject gameObject, bool hasCollision = false, Rectangle? collisionRectangle = null, bool isTrigger = false, Rectangle? triggerRectangle = null) @@ -33,8 +32,10 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager this.stopRectangle = collisionRectangle.Value; if (isTrigger) this.triggerRectangle = triggerRectangle.Value; + + - AppManager.Instance.server.collisionManager.Register(this); + } //==ПОЛЯ== diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs index 2cf80af..6bb9698 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs @@ -97,9 +97,10 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager newRect.Y = tryingRectY.Y;//значение по X для нового РЕК приравниваем к значению испытуемого РЕК } - entity.graphicsComponent.ObjectDrawRectangle.x = (int)entity.position.X; - entity.graphicsComponent.ObjectDrawRectangle.y = (int)entity.position.Y; - AppManager.Instance.server.AddData(new UpdatePosition() { NewPosition = entity.position }); + entity.graphicsComponent.ObjectDrawRectangle.X = (int)entity.position.X; + entity.graphicsComponent.ObjectDrawRectangle.Y = (int)entity.position.Y; + AppManager.Instance.server.AddData(new UpdatePosition() { NewPosition = entity.position, IdEntity = entity.Id }); + AppManager.Instance.debugHud.Set("testPos", entity.position.ToString()); //TODO remove entity.velocity = Vector2.Zero; } diff --git a/ZoFo/GameCore/GameObjects/Entities/Entity.cs b/ZoFo/GameCore/GameObjects/Entities/Entity.cs index db68013..456d8da 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Entity.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Entity.cs @@ -12,10 +12,22 @@ namespace ZoFo.GameCore.GameObjects.Entities //public override GraphicsComponent graphicsComponent => null; public CollisionComponent collisionComponent { get; protected set; } public int Id { get; set; } + static int totalEntitiesCreated = 0; protected Entity(Vector2 position) : base(position) { - + Id = totalEntitiesCreated; + totalEntitiesCreated++; + collisionComponent = new CollisionComponent(this); } + /// + /// For initialisation on Client + /// + /// + public void SetIdByClient(int newId) + { + Id = newId; + } + public virtual void Update() { } diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs index e7e15f1..cc6cb9c 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs @@ -34,6 +34,7 @@ public class LivingEntity : Entity { } + } diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs index 026a746..60a489a 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs @@ -26,20 +26,23 @@ public class Player : LivingEntity //InputWeaponRotation = new Vector2(0, 0); //InputPlayerRotation = new Vector2(0, 0); - collisionComponent = new CollisionComponent(this, true, new Rectangle(0, 0, 10, 10)); + collisionComponent.stopRectangle = new Rectangle(0, 0, 10, 10); + graphicsComponent.ObjectDrawRectangle = new Rectangle(0,0,100,100); } - public void Update(GameTime gameTime) + public override void Update() { MovementLogic(); } + float t; public void MovementLogic() { + velocity.X = (float)Math.Sin(t); + t++; if (InputPlayerRotation.X > 0.9) { - velocity.X = 5; } } public void HandleNewInput(UpdateInput updateInput) diff --git a/ZoFo/GameCore/GameObjects/GameObject.cs b/ZoFo/GameCore/GameObjects/GameObject.cs index 66cb30d..02ed2df 100644 --- a/ZoFo/GameCore/GameObjects/GameObject.cs +++ b/ZoFo/GameCore/GameObjects/GameObject.cs @@ -46,6 +46,7 @@ public abstract class GameObject #region Client Side + public static Texture2D debugTexture; /// /// Для клиента /// Это вызывается в клиентской части игры @@ -82,6 +83,8 @@ public abstract class GameObject { graphicsComponent.DrawAnimation(graphicsComponent.ObjectDrawRectangle, spriteBatch); //debug + DrawDebugRectangle(spriteBatch, graphicsComponent.ObjectDrawRectangle); + if (AppManager.Instance.InputManager.CollisionsCheat) DrawDebugRectangle(spriteBatch, graphicsComponent.ObjectDrawRectangle); @@ -90,11 +93,11 @@ public abstract class GameObject { 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); + 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 } diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index 886f923..49beeab 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -15,6 +15,7 @@ using ZoFo.GameCore.GameManagers.NetworkManager.Updates; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using ZoFo.GameCore.GameObjects; using ZoFo.GameCore.GameObjects.Entities; +using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies; using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; using ZoFo.GameCore.GameObjects.MapObjects; @@ -149,10 +150,20 @@ namespace ZoFo.GameCore });//TODO return; } + if (gameObject is Entity) + { + AddData(new UpdateGameObjectCreated() { GameObjectType = gameObject.GetType().Name, IdEntity = (gameObject as Entity).Id }); + collisionManager.Register((gameObject as Entity).collisionComponent); + } + else + AddData(new UpdateGameObjectCreated() { GameObjectType = gameObject.GetType().Name }); - AddData(new UpdateGameObjectCreated() - { GameObjectType = gameObject.GetType().Name } - ); + + ////var elems = gameObject.GetType().GetProperties(System.Reflection.BindingFlags.Public); + ////if (elems.Count()>0) TODO + ////{ + //// AppManager.Instance.server.collisionManager.Register((elems.First().GetValue(gameObject) as CollisionComponent)); + ////} } From 6afd91b0b7cdf79d9bdc0a9f28b2be85bdc583bf Mon Sep 17 00:00:00 2001 From: SergoDobro Date: Sat, 17 Aug 2024 23:34:20 +0300 Subject: [PATCH 8/9] hotfixes --- ZoFo/GameCore/Client.cs | 2 +- .../GameObjects/Entities/LivingEntities/Player/Player.cs | 2 +- ZoFo/GameCore/GameObjects/GameObject.cs | 2 +- ZoFo/GameCore/Server.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index e4da2a7..19252a8 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -95,7 +95,7 @@ namespace ZoFo.GameCore if ((update as UpdateGameObjectCreated).GameObjectType == "EntittyForAnimationTests") gameObjects.Add(new EntittyForAnimationTests(new Vector2(100, 100))); if ((update as UpdateGameObjectCreated).GameObjectType == "Player") - gameObjects.Add(new Player(new Vector2(100, 100))); + gameObjects.Add(new Player(new Vector2(500, 100))); (gameObjects.Last() as Entity).SetIdByClient((update as UpdateGameObjectCreated).IdEntity); //var a = Assembly.GetAssembly(typeof(GameObject)); diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs index 60a489a..c5fccc3 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs @@ -26,7 +26,7 @@ public class Player : LivingEntity //InputWeaponRotation = new Vector2(0, 0); //InputPlayerRotation = new Vector2(0, 0); - collisionComponent.stopRectangle = new Rectangle(0, 0, 10, 10); + collisionComponent.stopRectangle = new Rectangle(0, 0, 100, 100); graphicsComponent.ObjectDrawRectangle = new Rectangle(0,0,100,100); } diff --git a/ZoFo/GameCore/GameObjects/GameObject.cs b/ZoFo/GameCore/GameObjects/GameObject.cs index 02ed2df..7a4eb43 100644 --- a/ZoFo/GameCore/GameObjects/GameObject.cs +++ b/ZoFo/GameCore/GameObjects/GameObject.cs @@ -91,7 +91,7 @@ public abstract class GameObject } public void DrawDebugRectangle(SpriteBatch spriteBatch, Rectangle _rectangle, Nullable color = null) { - if (color is null) color = new Color(1, 0, 0, 0.25f); + if (color is null) color = new Color(1, 0, 0, 0.1f); if (color.Value.A == 255) color = new Color(color.Value, 0.25f); spriteBatch.Draw(debugTexture, new Rectangle((_rectangle.X - GraphicsComponent.CameraPosition.X) * GraphicsComponent.scaling, diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index 924af8b..de52802 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -83,7 +83,7 @@ namespace ZoFo.GameCore #endregion #region Game Methods - + public CollisionManager collisionManager; /// /// Запуск игры в комнате /// From 0f6937dbf4d001ee9b4e77963dff68935d2370c5 Mon Sep 17 00:00:00 2001 From: SergoDobro Date: Sat, 17 Aug 2024 23:48:39 +0300 Subject: [PATCH 9/9] updates sets position on client --- ZoFo/GameCore/Client.cs | 4 ++-- .../Updates/ServerToClient/UpdateGameObjectCreated.cs | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index 19252a8..c99c3b2 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -93,9 +93,9 @@ namespace ZoFo.GameCore else if (update is UpdateGameObjectCreated) { if ((update as UpdateGameObjectCreated).GameObjectType == "EntittyForAnimationTests") - gameObjects.Add(new EntittyForAnimationTests(new Vector2(100, 100))); + gameObjects.Add(new EntittyForAnimationTests((update as UpdateGameObjectCreated).position)); if ((update as UpdateGameObjectCreated).GameObjectType == "Player") - gameObjects.Add(new Player(new Vector2(500, 100))); + gameObjects.Add(new Player((update as UpdateGameObjectCreated).position)); (gameObjects.Last() as Entity).SetIdByClient((update as UpdateGameObjectCreated).IdEntity); //var a = Assembly.GetAssembly(typeof(GameObject)); diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectCreated.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectCreated.cs index 0ca86a4..8e1b5b6 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectCreated.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectCreated.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Xna.Framework; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -14,5 +15,6 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient public UpdateGameObjectCreated() { UpdateType = "UpdateGameObjectCreated"; } public string GameObjectType; public string GameObjectId; + public Vector2 position; } }