Система здоровья
This commit is contained in:
1 parent
2335908a90
commit
ab9d444072
6 files changed
+60
-1
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
using Code.App.StateMachine;
|
using Code.App.StateMachine;
|
||||||
using Code.Gameplay.Camera;
|
using Code.Gameplay.Camera;
|
||||||
|
using Code.Gameplay.Player;
|
||||||
using Code.Input;
|
using Code.Input;
|
||||||
using Code.Scenes;
|
using Code.Scenes;
|
||||||
using Code.StateMachine;
|
using Code.StateMachine;
|
||||||
@@ -10,6 +11,7 @@ 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
|
||||||
Reference in new issue
Block a user