player's health can decrease
This commit is contained in:
parent
d819caeee2
commit
b246532a6e
17 changed files with 127 additions and 111 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) { }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) { }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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) { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) { }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) { }
|
||||
}
|
|
@ -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)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -13,12 +13,10 @@ public class LivingEntity : Entity
|
|||
/// Переменная для заявки на передвижения, т.е. то, на сколько вы хотите, чтобы в этом кадре переместился объект
|
||||
/// </summary>
|
||||
public Vector2 velocity;
|
||||
|
||||
private InputManager inputManager;
|
||||
|
||||
|
||||
public LivingEntity(Vector2 position) : base(position)
|
||||
{
|
||||
inputManager = new InputManager();
|
||||
{
|
||||
collisionComponent.hasCollision = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue