Система здоровья
This commit is contained in:
1 parent
f612ee14d3
commit
159f530b51
7 files changed
+69
-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;
|
||||||
@@ -8,6 +9,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,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e4901b413afd4d7da914edf2a1e51f8f
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -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