Platformer level management

This commit is contained in:
ThomasCharester committed 2026-03-23 12:01:33 +03:00
1 parent 72070901ec
commit 1aceea1b79
94 files changed
+3656 -197

No files matched your search

@@ -1,4 +1,6 @@
using System;
using Code.Infrastructure.EventBus;
using Cysharp.Threading.Tasks;
using Reflex.Attributes;
using UnityEngine;
@@ -8,19 +10,47 @@ namespace Code.Example.Platformer.Entity
{
private int _health;
private int _maxHealth;
public void SetMaxHealth(int maxHealth) => _maxHealth = maxHealth;
private float _damageThreshold;
public void Setup(int maxHealth, float damageThreshold)
{
_maxHealth = maxHealth;
_health = maxHealth;
_damageThreshold = damageThreshold;
}
public bool IsDead { get; private set; }
private bool _isDamageable = true;
[Inject] private EventBus _eventBus;
[SerializeField] private Entity entity;
[Inject] private EventBus _eventBus;
public Action<int> OnEntityHeal;
public Action<int> OnEntityDamage;
public Action OnEntityDeath;
private async UniTaskVoid WaitThreshold()
{
await UniTask.WaitForSeconds(_damageThreshold);
_isDamageable = true;
}
public void GiveDamage(int damage)
{
if (!_isDamageable) return;
_health -= damage;
if(_health <= 0) IsDead = true;
_isDamageable = false;
OnEntityDamage?.Invoke(_health);
if(_health <= 0)
{
IsDead = true;
OnEntityDeath?.Invoke();
}
_eventBus.RaiseEvent<IEntityDamagedHandler>(x=> x.EntityDamaged(gameObject, damage, IsDead));
WaitThreshold().Forget();
}
public void Heal(int heal)
@@ -29,6 +59,8 @@ namespace Code.Example.Platformer.Entity
if (_health + heal > _maxHealth) _health = _maxHealth;
else _health += heal;
OnEntityHeal?.Invoke(_health);
_eventBus.RaiseEvent<IEntityHealedHandler>(x=> x.EntityHealed(gameObject, heal));
}
}