From eef6e038b80f8ecc9037d8d44e6525c4a5d922b3 Mon Sep 17 00:00:00 2001 From: Lev Date: Fri, 16 Aug 2024 18:06:51 +0300 Subject: [PATCH] add register game objects --- ZoFo/GameCore/GameManagers/InputManager.cs | 1 + .../NetworkManager/ServerNetworkManager.cs | 1 + ZoFo/GameCore/GameObjects/Entities/Entity.cs | 4 +++- .../Entities/LivingEntities/LivingEntity.cs | 12 +++++++++--- .../Entities/LivingEntities/Player/Player.cs | 18 ++++++++++-------- ZoFo/GameCore/GameObjects/GameObject.cs | 5 +++++ ZoFo/GameCore/Server.cs | 2 +- 7 files changed, 30 insertions(+), 13 deletions(-) diff --git a/ZoFo/GameCore/GameManagers/InputManager.cs b/ZoFo/GameCore/GameManagers/InputManager.cs index 0dfbc1b..4ee0980 100644 --- a/ZoFo/GameCore/GameManagers/InputManager.cs +++ b/ZoFo/GameCore/GameManagers/InputManager.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers { public enum ScopeState { Left, Right, Straight, Back, StraightLeft, StraightRight, BackLeft, BackRight } + public class InputManager { public delegate void Delegat(); diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs index b4213e7..bb1948e 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Net; +using System.Net.Http; using System.Net.Sockets; using System.Text; using System.Text.Json; diff --git a/ZoFo/GameCore/GameObjects/Entities/Entity.cs b/ZoFo/GameCore/GameObjects/Entities/Entity.cs index a1ab30b..26eb6c0 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Entity.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Entity.cs @@ -16,8 +16,10 @@ namespace ZoFo.GameCore.GameObjects.Entities protected Entity(Vector2 position) : base(position) { } - + public virtual void Update() + { + } } } diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs index 05a27ec..1d73ead 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs @@ -3,20 +3,26 @@ using Microsoft.Xna.Framework.Graphics; using System; using ZoFo.GameCore.GameObjects.Entities; using ZoFo.GameCore.ZoFo_graphics; +using ZoFo.GameCore.GameManagers; namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities; public class LivingEntity : Entity { public Vector2 velocity; + private InputManager inputManager; + public LivingEntity(Vector2 position) : base(position) { + inputManager = new InputManager(); } - public void TextureLoad(SpriteBatch spriteBatch) + #region Server side + /*public override void Update() { - - } + + }*/ + #endregion } diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs index 744b2c4..20bbe18 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs @@ -1,25 +1,27 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; +using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; + public class Player : LivingEntity { + public Vector2 InputWeaponRotation{ get; set; } + public Vector2 InputPlayerRotation{ get; set;} + public bool IsTryingToShoot{get;set;} + Texture2D texture; + private float speed; private int health; - Server server = new Server(); - public Player(Vector2 position) : base(position) { + //InputWeaponRotation = new Vector2(0, 0); + //InputPlayerRotation = new Vector2(0, 0); } public void Update(GameTime gameTime) { - // server.AddData(); - } - - public void TextureLoad(SpriteBatch spriteBatch) - { - + } } diff --git a/ZoFo/GameCore/GameObjects/GameObject.cs b/ZoFo/GameCore/GameObjects/GameObject.cs index d309bf9..02c90d1 100644 --- a/ZoFo/GameCore/GameObjects/GameObject.cs +++ b/ZoFo/GameCore/GameObjects/GameObject.cs @@ -4,12 +4,15 @@ using Microsoft.Xna.Framework.Graphics; using System; using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.ZoFo_graphics; +using ZoFo.GameCore; namespace ZoFo.GameCore.GameObjects; public abstract class GameObject { public Vector2 position; + + private Server server; public Vector2 rotation; //вектор направления объекта protected abstract GraphicsComponent graphicsComponent { get; } @@ -17,6 +20,8 @@ public abstract class GameObject public GameObject(Vector2 position) { this.position = position; + server = new Server(); + server.RegisterEntity(this); } public virtual void UpdateLogic(GameTime gameTime) { diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index 5fcb39c..325d0ee 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -58,7 +58,7 @@ namespace ZoFo.GameCore networkManager.CloseConnection(); } - private List gameObjects; + private List gameObjects = new List(); private List entities; //entity public void Update(GameTime gameTime) {