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

This commit is contained in:
ThomasCharester committed 2025-10-28 13:49:44 +03:00
1 parent 64aa63f4ed
commit 5e4a7d2874
6 files changed
+61 -1

No files matched your search

@@ -1,4 +1,5 @@
using Code.App.StateMachine; using Code.App.StateMachine;
using Code.Gameplay.Player;
using Code.Input; using Code.Input;
using Code.Scenes; using Code.Scenes;
using Code.StateMachine; using Code.StateMachine;
@@ -9,6 +10,8 @@ namespace Code.App.AppStates
{ {
public class GameplayState : BaseState<AppStateMachineContext> public class GameplayState : BaseState<AppStateMachineContext>
{ {
private PlayerHealthPoints _playerHealthPoints;
public GameplayState(AppStateMachineContext context) : base(context) public GameplayState(AppStateMachineContext context) : base(context)
{ {
} }
@@ -2,9 +2,15 @@ using UnityEngine;
namespace Code.Configs namespace Code.Configs
{ {
[CreateAssetMenu(menuName = "Config/AppConfig", fileName = "AppConfig")] [CreateAssetMenu(menuName = "Config/App", fileName = "AppConfig")]
public class AppConfig : ScriptableObject public class AppConfig : ScriptableObject
{ {
public GameObject infrastructureUnitPrefab; public GameObject infrastructureUnitPrefab;
} }
[CreateAssetMenu(menuName = "Config/Player", fileName = "PlayerConfig")]
public class PlayerConfig : ScriptableObject
{
public Player playerPrefab;
public int maxHealth;
}
} }
@@ -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