Система здоровья

This commit is contained in:
ThomasCharester committed 2025-10-25 09:56:55 +03:00
1 parent f612ee14d3
commit 159f530b51
7 files changed
+69 -1

No files matched your search

@@ -0,0 +1,18 @@
using UnityEngine;
using Code.Configs;
using Reflex.Attributes;
namespace Code.Gameplay.Player
{
public class PlayerFactory
{
[Inject] PlayerConfig _playerConfig;
public PlayerHealthPoints CreatePlayerHP(int count = -1)
{
if (count < 0) count = _playerConfig.maxHealth;
return new PlayerHealthPoints(count);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 77dd77e7e8714974a7c8bc83772e52fa
timeCreated: 1761060390
@@ -0,0 +1,27 @@
namespace Code.Gameplay.Player
{
public class PlayerHealthPoints
{
public delegate void OnDeathDelegate();
public event OnDeathDelegate OnDeath;
public delegate void OnDamageDelegate(int damage);
public event OnDamageDelegate OnDamage;
private int _healthPoints;
public int HealthPoints => _healthPoints;
public void GetDamage(int count)
{
_healthPoints -= count;
OnDamage?.Invoke(count);
if (_healthPoints <= 0) OnDeath?.Invoke();
}
public PlayerHealthPoints(int healthPoints = 1) => _healthPoints = healthPoints;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 105512e4d3af4b36932a0d569b87c68e
timeCreated: 1761059874