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,8 @@
using System;
using Code.Infrastructure.Audio;
using Code.Infrastructure.Configs;
using Cysharp.Threading.Tasks;
using Reflex.Attributes;
using UnityEngine;
namespace Code.Example.Platformer.Entity.Enemies
@@ -11,11 +15,42 @@ namespace Code.Example.Platformer.Entity.Enemies
private float _acceleration = 3f;
[SerializeField] private EntityHealth health;
[Inject] private IAudioService _audioService;
private void Start()
{
health.OnEntityDamage = OnEntityDamage;
health.OnEntityDeath = OnEntityDeath;
}
private void OnEntityDeath()
{
animator.SetBool(Died, true);
animator.SetTrigger(OnDeath);
Die().Forget();
}
private async UniTaskVoid Die()
{
await UniTask.WaitForSeconds(1);
_audioService.PlayOneShot(AudioNames.Platformer, 3 );
Destroy(gameObject);
}
private void OnEntityDamage(int obj)
{
_audioService.PlayOneShot(AudioNames.Platformer, 2);
UnityEngine.Debug.Log(gameObject.name + " damaged");
animator.SetTrigger(OnHit);
}
protected override void Move()
{
if (health.IsDead) return;
if (_target)
{
_directionRight = ((_target.position - transform.position)).x > float.Epsilon;
TryAttack();
_directionRight = (_target.position - transform.position).x > float.Epsilon;
UnityEngine.Debug.DrawLine(transform.position, (transform.position + (_target.position - transform.position)), Color.salmon);
CheckupDirection();
@@ -30,7 +65,7 @@ namespace Code.Example.Platformer.Entity.Enemies
rigidbody2D.linearVelocityX = _directionRight ? 0.5f : -0.5f;
}
}
protected override void HandleFlipX() => spriteRenderer.flipX = rigidbody2D.linearVelocity.x > -0.01f;
private void CheckupDirection()
@@ -45,9 +80,15 @@ namespace Code.Example.Platformer.Entity.Enemies
LayerMasks.Masks[LayerMaskType.PlatformerGround]))
_directionRight = true;
}
private void TryAttack()
{
if ((transform.position - _target.position).magnitude < attackThreshold) _target.GetComponent<EntityHealth>().GiveDamage(1);
}
private Transform _target;
private float attackThreshold = 0.5f;
public void GotTarget(Transform target)
{
_target = target;