diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index 82e5f20..58257fd 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -23,7 +23,6 @@ using System.Web; using ZoFo.GameCore.GUI; using ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables; using ZoFo.GameCore.GameObjects.MapObjects.StopObjects; -using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies; using ZoFo.GameCore.Graphics; using Newtonsoft.Json.Linq; using Newtonsoft.Json; @@ -50,17 +49,17 @@ namespace ZoFo.GameCore networkManager.AddData(new UpdateInput() { InputMovementDirection = AppManager.Instance.InputManager.InputMovementDirection, - InputAttackDirection = AppManager.Instance.InputManager.InputAttackDirection + InputAttackDirection = AppManager.Instance.InputManager.InputAttackDirection }); - + }; AppManager.Instance.InputManager.OnInteract += () => { networkManager.AddData(new UpdateInputInteraction() { }); }; - AppManager.Instance.InputManager.ShootEvent += () => + AppManager.Instance.InputManager.ShootEvent += () => { - networkManager.AddData(new UpdateInputShoot() { }); + networkManager.AddData(new UpdateInputShoot() { }); }; } @@ -95,7 +94,7 @@ namespace ZoFo.GameCore Player myPlayer; List mapObjects = new List(); - List gameObjects = new List(); + List gameObjects = new List(); List players = new List(); List stopObjects = new List(); @@ -112,8 +111,13 @@ namespace ZoFo.GameCore } networkManager.SendData();//set to ticks - if (myPlayer!=null) - GraphicsComponent.CameraPosition = (myPlayer.position + myPlayer.graphicsComponent.ObjectDrawRectangle.Size.ToVector2()/2 - AppManager.Instance.CurentScreenResolution.ToVector2()/(2*GraphicsComponent.scaling)).ToPoint(); + if (myPlayer != null) + GraphicsComponent.CameraPosition = + ((GraphicsComponent.CameraPosition.ToVector2() *0.9f + + (myPlayer.position + myPlayer.graphicsComponent.ObjectDrawRectangle.Size.ToVector2() / 2 - AppManager.Instance.CurentScreenResolution.ToVector2() / (2 * GraphicsComponent.scaling) + ) * 0.1f + ) ) + .ToPoint(); } internal void Draw(SpriteBatch spriteBatch) { @@ -151,47 +155,47 @@ namespace ZoFo.GameCore (update as UpdateStopObjectCreated).Size.GetPoint().ToVector2(), (update as UpdateStopObjectCreated).sourceRectangle.GetRectangle(), (update as UpdateStopObjectCreated).tileSetName, - (update as UpdateStopObjectCreated).collisions.Select(x =>x.GetRectangle()).ToArray() + (update as UpdateStopObjectCreated).collisions.Select(x => x.GetRectangle()).ToArray() )); } else if (update is UpdateGameObjectCreated) { - GameObject created_gameObject; - if ((update as UpdateGameObjectCreated).GameObjectType == "EntittyForAnimationTests") - gameObjects.Add(new EntittyForAnimationTests((update as UpdateGameObjectCreated).position)); - if ((update as UpdateGameObjectCreated).GameObjectType == "Player") + GameObject created_gameObject; + if((update as UpdateGameObjectCreated).GameObjectType == "Player") { created_gameObject = new Player((update as UpdateGameObjectCreated).position); players.Add(created_gameObject as Player); - myPlayer = players[0]; + myPlayer = players[0]; gameObjects.Add(created_gameObject); } - if ((update as UpdateGameObjectCreated).GameObjectType == "Ammo") + else if((update as UpdateGameObjectCreated).GameObjectType == "Ammo") gameObjects.Add(new Ammo((update as UpdateGameObjectCreated).position)); - if ((update as UpdateGameObjectCreated).GameObjectType == "Zombie") + else if((update as UpdateGameObjectCreated).GameObjectType == "Zombie") gameObjects.Add(new Zombie((update as UpdateGameObjectCreated).position)); + else + { + Type t = Type.GetType("ZoFo.GameCore.GameObjects." + (update as UpdateGameObjectCreated).GameObjectType); + GameObject gameObject = Activator.CreateInstance(t, (update as UpdateGameObjectCreated).position) as GameObject; + if (gameObject is Entity) + (gameObject as Entity).SetIdByClient((update as UpdateGameObjectCreated).IdEntity); + gameObjects.Add(gameObject); + } + (gameObjects.Last() as Entity).SetIdByClient((update as UpdateGameObjectCreated).IdEntity); - - (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; + + if (ent != null) + ent.position = (update as UpdatePosition).NewPosition; } else if (update is UpdateAnimation) { var ent = FindEntityById(update.IdEntity); if (ent != null) ((ent as Entity).graphicsComponent as AnimatedGraphicsComponent).StartAnimation((update as UpdateAnimation).animationId); - //DebugHUD.Instance.Log("new Animation " + ent.position); + //DebugHUD.Instance.Log("new Animation " + ent.position); } else if (update is UpdateGameObjectDeleted) { diff --git a/ZoFo/GameCore/GameManagers/AppManager.cs b/ZoFo/GameCore/GameManagers/AppManager.cs index d56d903..bd9ed02 100644 --- a/ZoFo/GameCore/GameManagers/AppManager.cs +++ b/ZoFo/GameCore/GameManagers/AppManager.cs @@ -105,7 +105,7 @@ namespace ZoFo.GameCore.GameManagers protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || - Keyboard.GetState().IsKeyDown(Keys.Escape)) { server.CloseConnection(); Exit(); } + Keyboard.GetState().IsKeyDown(Keys.Escape)) { server?.CloseConnection(); Exit(); } // debugHud.Set("key", "value"); diff --git a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs index 84d4f10..6d5107c 100644 --- a/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs +++ b/ZoFo/GameCore/GameManagers/CollisionManager/CollisionManager.cs @@ -30,9 +30,10 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager /// /// минимальный накоп изменения перед перевдижением /// - const float minimalValueToChange = 4; + const float minimalValueToChange = 0; public void CheckComponentCollision(CollisionComponent componentOfEntity) { + //ADD CHECKSPEED TODO var entity = componentOfEntity.gameObject as LivingEntity; //for (int i = 0; i < ObjectsWithCollisions.Count; i++) //{ @@ -74,7 +75,8 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager } else { - entity.position.X += entity.velocity.X; //update player position + entity.position.X += (int)entity.velocity.X; //update player position + //entity.position.X = (float)Math.Round(entity.position.X, 2); newRect.X = tryingRectX.X;//значение по X для нового РЕК приравниваем к значению испытуемого РЕК } @@ -112,7 +114,8 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager } else { - entity.position.Y += entity.velocity.Y; + entity.position.Y += (int)entity.velocity.Y; + //entity.position.Y = (float)Math.Round(entity.position.Y, 2); newRect.Y = tryingRectY.Y;//значение по X для нового РЕК приравниваем к значению испытуемого РЕК } entity.velocity.Y = 0; diff --git a/ZoFo/GameCore/GameObjects/Entities/EntittyForAnimationTests.cs b/ZoFo/GameCore/GameObjects/Entities/EntittyForAnimationTests.cs index 20e779e..7a9454f 100644 --- a/ZoFo/GameCore/GameObjects/Entities/EntittyForAnimationTests.cs +++ b/ZoFo/GameCore/GameObjects/Entities/EntittyForAnimationTests.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; using ZoFo.GameCore.Graphics; -namespace ZoFo.GameCore.GameObjects.Entities +namespace ZoFo.GameCore.GameObjects { internal class EntittyForAnimationTests : Entity { diff --git a/ZoFo/GameCore/GameObjects/Entities/Entity.cs b/ZoFo/GameCore/GameObjects/Entities/Entity.cs index f0e4ebf..e0d840b 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Entity.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Entity.cs @@ -6,14 +6,14 @@ using Microsoft.Xna.Framework.Graphics; using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.GameManagers.CollisionManager; -namespace ZoFo.GameCore.GameObjects.Entities +namespace ZoFo.GameCore.GameObjects { public abstract class Entity : GameObject { //public override GraphicsComponent graphicsComponent => null; public CollisionComponent collisionComponent { get; protected set; } public int Id { get; set; } - static int totalEntitiesCreated = 0; + static int totalEntitiesCreated = 1; protected Entity(Vector2 position) : base(position) { Id = totalEntitiesCreated; diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Ammo.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Ammo.cs index 8ae256f..81e0e1f 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Ammo.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Ammo.cs @@ -11,7 +11,7 @@ using ZoFo.GameCore.Graphics; using Microsoft.Xna.Framework.Graphics; using ZoFo.GameCore.GUI; -namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables +namespace ZoFo.GameCore.GameObjects { class Ammo:Collectable { diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs index 840a5f4..157fefc 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs @@ -4,7 +4,7 @@ using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.GameManagers.CollisionManager; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; -namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables; +namespace ZoFo.GameCore.GameObjects; public class Collectable : Interactable { protected static readonly string _path = "Textures/icons/Collectables/"; diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs index bc61ff9..59ba21d 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs @@ -5,7 +5,7 @@ using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; using ZoFo.GameCore.Graphics; -namespace ZoFo.GameCore.GameObjects.Entities.Interactables; +namespace ZoFo.GameCore.GameObjects; public class Interactable : Entity { diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Enemy.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Enemy.cs index 61762ae..d602ede 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Enemy.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Enemy.cs @@ -5,7 +5,7 @@ using System.Reflection; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; -namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies; +namespace ZoFo.GameCore.GameObjects; public class Enemy : LivingEntity { protected float speed; diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs index ab008d0..be83fa2 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs @@ -8,7 +8,7 @@ using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.GameManagers.AssetsManager; using ZoFo.GameCore.Graphics; -namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies +namespace ZoFo.GameCore.GameObjects { class Zombie : Enemy { diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs index 36523a8..e0039af 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs @@ -6,7 +6,7 @@ using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.GameManagers.CollisionManager; using ZoFo.GameCore.Graphics; -namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities; +namespace ZoFo.GameCore.GameObjects; public class LivingEntity : Entity { /// diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/LootData.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/LootData.cs index 2d86531..25dd09d 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/LootData.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/LootData.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player +namespace ZoFo.GameCore.GameObjects { class LootData { diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs index 77e30c7..ff4428d 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs @@ -10,7 +10,7 @@ using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using ZoFo.GameCore.Graphics; -namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; +namespace ZoFo.GameCore.GameObjects; public class Player : LivingEntity { @@ -29,7 +29,7 @@ public class Player : LivingEntity { graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30); collisionComponent.stopRectangle = new Rectangle(0, 20, 30, 10); - speed = 10; + speed = 5; //isTryingToInteract = false; //IsTryingToShoot = false; @@ -44,7 +44,7 @@ public class Player : LivingEntity } public void MovementLogic() { - velocity = InputPlayerRotation * speed; + velocity += InputPlayerRotation * speed; } public void HandleNewInput(UpdateInput updateInput) { diff --git a/ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs b/ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs index e55976d..f2a6ac6 100644 --- a/ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs +++ b/ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs @@ -10,7 +10,7 @@ using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using ZoFo.GameCore.Graphics; -namespace ZoFo.GameCore.GameObjects.MapObjects +namespace ZoFo.GameCore.GameObjects { public class MapObject : GameObject { @@ -34,6 +34,25 @@ namespace ZoFo.GameCore.GameObjects.MapObjects (graphicsComponent as StaticGraphicsComponent).LoadContent(); this.sourceRectangle = sourceRectangle; + } + /// + /// Конструктор для объектов с карты с анимациями, REDO + /// + /// + /// + /// + /// + /// + /// + public MapObject(Vector2 position, Vector2 size, Rectangle sourceRectangle, string textureName, Rectangle sourceRectangles, int frameSize) : base(position) + { + //graphicsComponent for source + (graphicsComponent as StaticGraphicsComponent)._textureName = textureName; + (graphicsComponent as StaticGraphicsComponent).BuildComponent(textureName); + (graphicsComponent as StaticGraphicsComponent).ObjectDrawRectangle = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y); + (graphicsComponent as StaticGraphicsComponent).LoadContent(); + this.sourceRectangle = sourceRectangle; + } public override void Draw(SpriteBatch spriteBatch) { diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index baa753a..2e9b1f2 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -16,8 +16,7 @@ using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using ZoFo.GameCore.GameObjects; using ZoFo.GameCore.GameObjects.Entities; -using ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables; -using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies; +using ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables; using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; using ZoFo.GameCore.GameObjects.MapObjects; using ZoFo.GameCore.GameObjects.MapObjects.StopObjects;