diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index f2a85de..761b799 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -233,6 +233,49 @@ namespace ZoFo.GameCore DeleteObject(ent); } + else if (update is UpdatePlayerParametrs) + { + UpdatePlayerHealth(update as UpdatePlayerParametrs); + } + + } + public void UpdatePlayerHealth(UpdatePlayerParametrs update) + { + + //check on player hp lowered + + if (myPlayer != null) + { + float hpMyPlayerHp = myPlayer.health; + + + var entity = FindEntityById(update.IdEntity); + + if (entity != null) + { + (entity as Player).health = (update as UpdatePlayerParametrs).health; + (entity as Player).rad = (update as UpdatePlayerParametrs).radiatoin; + } + if (entity.Equals(myPlayer)) + { + if (hpMyPlayerHp > myPlayer.health) + { + AppManager.Instance.client.AddShaking((hpMyPlayerHp - myPlayer.health)); + + } + } + + return; + } + + + var ent = FindEntityById(update.IdEntity); + + if (ent != null) + { + (ent as Player).health = (update as UpdatePlayerParametrs).health; + (ent as Player).rad = (update as UpdatePlayerParametrs).radiatoin; + } } diff --git a/ZoFo/GameCore/GUI/HUD.cs b/ZoFo/GameCore/GUI/HUD.cs index 9a88a71..ecacb8d 100644 --- a/ZoFo/GameCore/GUI/HUD.cs +++ b/ZoFo/GameCore/GUI/HUD.cs @@ -68,7 +68,12 @@ public class HUD : AbstractGUI overlayGUI?.Update(gameTime); //hpBar.Update(gameTime, AppManager.Instance.client.myPlayer.health / 100f); //radBar.Update(gameTime, AppManager.Instance.client.myPlayer.rad / 100f); - radBar.Update(gameTime, gameTime.TotalGameTime.Seconds / 100f); + if (AppManager.Instance.client.myPlayer != null) + { + radBar.Update(gameTime, AppManager.Instance.client.myPlayer.rad / AppManager.Instance.client.myPlayer.MaxRad); + hpBar.Update(gameTime, AppManager.Instance.client.myPlayer.health / AppManager.Instance.client.myPlayer.MaxHealth); + + } base.Update(gameTime); } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePlayerParametrs.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePlayerParametrs.cs index 100c8d0..9d4e196 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePlayerParametrs.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdatePlayerParametrs.cs @@ -12,5 +12,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient public class UpdatePlayerParametrs : UpdateData { public UpdatePlayerParametrs() { UpdateType = "UpdatePlayerParametrs"; } + public float radiatoin; + public float health; } } diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Ammo.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Ammo.cs index 25eddf3..ccd9585 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Ammo.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Ammo.cs @@ -16,31 +16,7 @@ namespace ZoFo.GameCore.GameObjects class Ammo : Collectable { public override StaticGraphicsComponent graphicsComponent { get; } = new(_path + "Ammo"); - public Ammo(Vector2 position) : base(position) - { - graphicsComponent.ObjectDrawRectangle.Width = 20; - graphicsComponent.ObjectDrawRectangle.Height = 20; - - collisionComponent.triggerRectangle = new Rectangle(0, 0, 20, 20); - } - public override void OnInteraction(GameObject sender) - { - DebugHUD.DebugLog("collected"); - if (AppManager.Instance.client.myPlayer.lootData.loots.Keys.Contains("Ammo")) - { - AppManager.Instance.client.myPlayer.lootData.loots["Ammo"] += 1; - } - else - { - AppManager.Instance.client.myPlayer.lootData.loots.Add("Ammo", 1); - } - AppManager.Instance.server.AddData(new UpdateLoot("Ammo")); - AppManager.Instance.server.DeleteObject(this); - } - public override void Draw(SpriteBatch spriteBatch) - { - DrawDebugRectangle(spriteBatch, collisionComponent.triggerRectangle.SetOrigin(position), Color.Blue); - base.Draw(spriteBatch); - } + public Ammo(Vector2 position) : base(position) { } + } } diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Antiradine.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Antiradine.cs index b8f2bcb..ebba1fd 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Antiradine.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Antiradine.cs @@ -11,17 +11,9 @@ using ZoFo.GameCore.Graphics; namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables { - class Antiradine:Collectable + class Antiradine : Collectable { public override StaticGraphicsComponent graphicsComponent { get; } = new("Antiradine"); - public Antiradine(Vector2 position) : base(position) - { - - } - public override void OnInteraction(GameObject sender) - { - AppManager.Instance.server.AddData(new UpdateLoot("Antiradine")); - AppManager.Instance.server.DeleteObject(this); - } + public Antiradine(Vector2 position) : base(position) { } } } diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/BottleOfWater.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/BottleOfWater.cs index 2e48992..79c7342 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/BottleOfWater.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/BottleOfWater.cs @@ -15,15 +15,7 @@ namespace ZoFo.GameCore.GameObjects public class BottleOfWater : Collectable { public override StaticGraphicsComponent graphicsComponent { get; } = new(_path + "BottleOfWater"); - public BottleOfWater(Vector2 position) : base(position) - { - graphicsComponent.ObjectDrawRectangle.Width = 20; - graphicsComponent.ObjectDrawRectangle.Height = 20; - } - public override void OnInteraction(GameObject sender) - { - AppManager.Instance.server.AddData(new UpdateLoot("BottleOfWater")); - AppManager.Instance.server.DeleteObject(this); - } + public BottleOfWater(Vector2 position) : base(position) { } + } } diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs index 157fefc..6aea4c1 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Collectable.cs @@ -1,21 +1,44 @@ using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using System; using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.GameManagers.CollisionManager; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; +using ZoFo.GameCore.GUI; namespace ZoFo.GameCore.GameObjects; public class Collectable : Interactable { protected static readonly string _path = "Textures/icons/Collectables/"; - public Collectable(Vector2 position) : base(position) - { + public Collectable(Vector2 position) : base(position) { + + graphicsComponent.ObjectDrawRectangle.Width = 20; + graphicsComponent.ObjectDrawRectangle.Height = 20; + + collisionComponent.triggerRectangle.Width = 20; + collisionComponent.triggerRectangle.Height = 20; + + + int size = 10; + collisionComponent.triggerRectangle.X -= size; + collisionComponent.triggerRectangle.Y -= size; + collisionComponent.triggerRectangle.Width += 2*size; + collisionComponent.triggerRectangle.Height += 2*size; } public override void OnInteraction(GameObject sender) { - // - AppManager.Instance.server.AddData(new UpdateLoot()); + DebugHUD.DebugLog("collected"); + string lootname = this.GetType().ToString().ToLower(); + (sender as Player).lootData.AddLoot(lootname, 1); + AppManager.Instance.server.AddData(new UpdateLoot(lootname)); AppManager.Instance.server.DeleteObject(this); + base.OnInteraction(sender); } + public override void Draw(SpriteBatch spriteBatch) + { + DrawDebugRectangle(spriteBatch, collisionComponent.triggerRectangle.SetOrigin(position), Color.Blue); + base.Draw(spriteBatch); + } + } diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Peeble.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Peeble.cs index b031bdd..b2c36e6 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Peeble.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Peeble.cs @@ -16,15 +16,6 @@ namespace ZoFo.GameCore.GameObjects { public override StaticGraphicsComponent graphicsComponent { get; } = new(_path + "Peeble"); - public Peeble(Vector2 position) : base(position) - { - graphicsComponent.ObjectDrawRectangle.Width = 20; - graphicsComponent.ObjectDrawRectangle.Height = 20; - } - public override void OnInteraction(GameObject sender) - { - AppManager.Instance.server.AddData(new UpdateLoot("Peeble")); - AppManager.Instance.server.DeleteObject(this); - } + public Peeble(Vector2 position) : base(position) { } } } diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/PureBottleOfWater.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/PureBottleOfWater.cs index f32d070..045db23 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/PureBottleOfWater.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/PureBottleOfWater.cs @@ -15,15 +15,6 @@ namespace ZoFo.GameCore.GameObjects { public override StaticGraphicsComponent graphicsComponent { get; } = new(_path + "PureBottleOfWater"); - public PureBottleOfWater(Vector2 position) : base(position) - { - graphicsComponent.ObjectDrawRectangle.Width = 20; - graphicsComponent.ObjectDrawRectangle.Height = 20; - } - public override void OnInteraction(GameObject sender) - { - AppManager.Instance.server.AddData(new UpdateLoot("PureBottleOfWater")); - AppManager.Instance.server.DeleteObject(this); - } + public PureBottleOfWater(Vector2 position) : base(position) { } } } diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/RottenFlesh.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/RottenFlesh.cs index 68a7a0a..71223b9 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/RottenFlesh.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/RottenFlesh.cs @@ -14,15 +14,6 @@ namespace ZoFo.GameCore.GameObjects class RottenFlesh:Collectable { public override StaticGraphicsComponent graphicsComponent { get; } = new(_path + "RottenFlesh"); - public RottenFlesh(Vector2 position) : base(position) - { - graphicsComponent.ObjectDrawRectangle.Width = 20; - graphicsComponent.ObjectDrawRectangle.Height = 20; - } - public override void OnInteraction(GameObject sender) - { - AppManager.Instance.server.AddData(new UpdateLoot("RottenFlesh")); - AppManager.Instance.server.DeleteObject(this); - } + public RottenFlesh(Vector2 position) : base(position) { } } } diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Steel.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Steel.cs index 21f5311..40a3c5c 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Steel.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Steel.cs @@ -15,15 +15,7 @@ namespace ZoFo.GameCore.GameObjects { public override StaticGraphicsComponent graphicsComponent { get; } = new(_path + "Steel"); - public Steel(Vector2 position) : base(position) - { - graphicsComponent.ObjectDrawRectangle.Width = 20; - graphicsComponent.ObjectDrawRectangle.Height = 20; - } - public override void OnInteraction(GameObject sender) - { - AppManager.Instance.server.AddData(new UpdateLoot("Steel")); - AppManager.Instance.server.DeleteObject(this); - } + public Steel(Vector2 position) : base(position) { } + } } diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Wood.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Wood.cs index 7cfad32..6c2a945 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Wood.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Wood.cs @@ -11,14 +11,5 @@ public class Wood : Collectable { public override StaticGraphicsComponent graphicsComponent { get; } = new(_path + "Wood"); - public Wood(Vector2 position) : base(position) - { - graphicsComponent.ObjectDrawRectangle.Width = 20; - graphicsComponent.ObjectDrawRectangle.Height = 20; - } - public override void OnInteraction(GameObject sender) - { - AppManager.Instance.server.AddData(new UpdateLoot("Wood")); - AppManager.Instance.server.DeleteObject(this); - } + public Wood(Vector2 position) : base(position) { } } \ No newline at end of file diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs index 59ba21d..6ce7d6d 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs @@ -4,6 +4,7 @@ using ZoFo.GameCore.GameManagers.CollisionManager; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; using ZoFo.GameCore.Graphics; +using ZoFo.GameCore.GUI; namespace ZoFo.GameCore.GameObjects; @@ -27,6 +28,6 @@ public class Interactable : Entity public virtual void OnInteraction(GameObject sender) { - + } } \ No newline at end of file diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs index c19c41c..e95aec4 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs @@ -29,7 +29,10 @@ namespace ZoFo.GameCore.GameObjects StartAnimation("zombie_walk"); collisionComponent.isTrigger = true; collisionComponent.hasCollision = true; - (graphicsComponent as AnimatedGraphicsComponent).actionOfAnimationEnd += EndAttack; + (graphicsComponent as AnimatedGraphicsComponent).actionOfAnimationEnd += (animationIdEnded)=>{ + if (animationIdEnded == "zombie_attack") + EndAttack(animationIdEnded); + }; collisionComponent.OnTriggerZone += OnPlayerClose; collisionComponent.triggerRectangle = new Rectangle(-5, -5, 40, 40); (graphicsComponent as AnimatedGraphicsComponent).actionOfAnimationEnd += (str) => @@ -70,7 +73,8 @@ namespace ZoFo.GameCore.GameObjects var damagedPlayers=AppManager.Instance.server.collisionManager.GetPlayersInZone(collisionComponent.triggerRectangle.SetOrigin(position)); //TODO ДАМАЖИТЬ ИГРОКОВ В ЗОНЕ if (damagedPlayers.Length>0) { DebugHUD.DebugLog("End of" + a); - AppManager.Instance.client.AddShaking(2); + foreach (var item in damagedPlayers) + item.TakeDamage(5); } isAttacking = false; } diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs index e66a2a8..4637b81 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs @@ -13,12 +13,10 @@ public class LivingEntity : Entity /// Переменная для заявки на передвижения, т.е. то, на сколько вы хотите, чтобы в этом кадре переместился объект /// public Vector2 velocity; - - private InputManager inputManager; + public LivingEntity(Vector2 position) : base(position) - { - inputManager = new InputManager(); + { collisionComponent.hasCollision = true; } diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/LootData.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/LootData.cs index 8180247..00e6b38 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/LootData.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/LootData.cs @@ -12,7 +12,10 @@ namespace ZoFo.GameCore.GameObjects public void AddLoot(string lootName, int quantity) { - loots.Add(lootName, quantity); + if (loots.ContainsKey(lootName)) + loots[lootName] +=quantity; + else + loots.Add(lootName, quantity); } } } diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs index 2687e08..864a263 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs @@ -21,8 +21,11 @@ public class Player : LivingEntity private float speed; public int reloading; - public int health = 100; - public int rad = 0; + public float health= 100; + public float MaxHealth = 100; + + public float rad = 0; + public float MaxRad = 100; public LootData lootData; @@ -99,6 +102,24 @@ public class Player : LivingEntity { IsTryingToInteract = true; } + + #region MyRegion + + public bool isDying; + public virtual void TakeDamage(float damage) + { + if (isDying) return; + health -= damage; + AppManager.Instance.server.AddData(new UpdatePlayerParametrs() { health = health, radiatoin = rad, IdEntity = Id }); + if (health < 0) + Die(); + } + public override void Die() + { + base.Die(); + } + + #endregion public void HandleShoot(UpdateInputShoot updateInputShoot) { if (reloading > 0)