diff --git a/Game/CourierOld/Assets/Code/App/AppStates/GameplayState.cs b/Game/CourierOld/Assets/Code/App/AppStates/GameplayState.cs index ca8d14b..60b078c 100644 --- a/Game/CourierOld/Assets/Code/App/AppStates/GameplayState.cs +++ b/Game/CourierOld/Assets/Code/App/AppStates/GameplayState.cs @@ -1,4 +1,5 @@ using Code.App.StateMachine; +using Code.Gameplay.Player; using Code.Input; using Code.Scenes; using Code.StateMachine; @@ -9,6 +10,8 @@ namespace Code.App.AppStates { public class GameplayState : BaseState { + private PlayerHealthPoints _playerHealthPoints; + public GameplayState(AppStateMachineContext context) : base(context) { } diff --git a/Game/CourierOld/Assets/Code/Configs/AppConfig.cs b/Game/CourierOld/Assets/Code/Configs/AppConfig.cs index 9332e41..9dfef08 100644 --- a/Game/CourierOld/Assets/Code/Configs/AppConfig.cs +++ b/Game/CourierOld/Assets/Code/Configs/AppConfig.cs @@ -2,9 +2,15 @@ using UnityEngine; namespace Code.Configs { - [CreateAssetMenu(menuName = "Config/AppConfig", fileName = "AppConfig")] + [CreateAssetMenu(menuName = "Config/App", fileName = "AppConfig")] public class AppConfig : ScriptableObject { public GameObject infrastructureUnitPrefab; } + [CreateAssetMenu(menuName = "Config/Player", fileName = "PlayerConfig")] + public class PlayerConfig : ScriptableObject + { + public Player playerPrefab; + public int maxHealth; + } } \ No newline at end of file diff --git a/Game/CourierOld/Assets/Code/Gameplay/Player/PlayerFactory.cs b/Game/CourierOld/Assets/Code/Gameplay/Player/PlayerFactory.cs new file mode 100644 index 0000000..b38f512 --- /dev/null +++ b/Game/CourierOld/Assets/Code/Gameplay/Player/PlayerFactory.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/Game/CourierOld/Assets/Code/Gameplay/Player/PlayerFactory.cs.meta b/Game/CourierOld/Assets/Code/Gameplay/Player/PlayerFactory.cs.meta new file mode 100644 index 0000000..5b8db75 --- /dev/null +++ b/Game/CourierOld/Assets/Code/Gameplay/Player/PlayerFactory.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 77dd77e7e8714974a7c8bc83772e52fa +timeCreated: 1761060390 \ No newline at end of file diff --git a/Game/CourierOld/Assets/Code/Gameplay/Player/PlayerHP.cs b/Game/CourierOld/Assets/Code/Gameplay/Player/PlayerHP.cs new file mode 100644 index 0000000..0add76f --- /dev/null +++ b/Game/CourierOld/Assets/Code/Gameplay/Player/PlayerHP.cs @@ -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; + } +} \ No newline at end of file diff --git a/Game/CourierOld/Assets/Code/Gameplay/Player/PlayerHP.cs.meta b/Game/CourierOld/Assets/Code/Gameplay/Player/PlayerHP.cs.meta new file mode 100644 index 0000000..ca0c2a0 --- /dev/null +++ b/Game/CourierOld/Assets/Code/Gameplay/Player/PlayerHP.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 105512e4d3af4b36932a0d569b87c68e +timeCreated: 1761059874 \ No newline at end of file