first location is playable
enemies and so on
This commit is contained in:
1 parent
6fb38310bc
commit
2c6d4e500f
18 files changed
+2565
-31
No files matched your search
@@ -0,0 +1,99 @@
|
||||
using UnityEngine;
|
||||
using Code.Gameplay.Player;
|
||||
using DG.Tweening;
|
||||
|
||||
namespace Code.Gameplay.Enemies
|
||||
{
|
||||
public class BasicEnemy : MonoBehaviour, IEnemy
|
||||
{
|
||||
[SerializeField] private float _speed = 2f;
|
||||
[SerializeField] private float _patrolDistance = 3f;
|
||||
|
||||
[SerializeField] private int _health = 2;
|
||||
|
||||
[SerializeField] private SpriteRenderer _spriteRenderer;
|
||||
|
||||
[SerializeField] private float _blinkDuration = 0.2f;
|
||||
[SerializeField] private Color _hitColor = Color.red;
|
||||
|
||||
private Color _originalColor;
|
||||
|
||||
private Vector3 _startPosition;
|
||||
private bool _facingRight = true;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_startPosition = transform.position;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Patrol();
|
||||
}
|
||||
|
||||
private void Patrol()
|
||||
{
|
||||
var targetX = _facingRight
|
||||
? _startPosition.x + _patrolDistance
|
||||
: _startPosition.x - _patrolDistance;
|
||||
|
||||
transform.position = Vector3.MoveTowards(
|
||||
transform.position,
|
||||
new Vector3(targetX, transform.position.y, transform.position.z),
|
||||
_speed * Time.deltaTime
|
||||
);
|
||||
|
||||
if (Mathf.Approximately(transform.position.x, targetX))
|
||||
{
|
||||
Flip();
|
||||
}
|
||||
}
|
||||
|
||||
private void Flip()
|
||||
{
|
||||
_facingRight = !_facingRight;
|
||||
transform.localScale = new Vector3(
|
||||
-transform.localScale.x,
|
||||
transform.localScale.y,
|
||||
transform.localScale.z
|
||||
);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (!other.CompareTag("Player")) return;
|
||||
|
||||
var playerHealth = other.GetComponent<PlayerHealth>();
|
||||
playerHealth?.TakeDamage();
|
||||
}
|
||||
|
||||
public void TakeDamage()
|
||||
{
|
||||
_health--;
|
||||
BlinkHit();
|
||||
if (_health <= 0)
|
||||
{
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
private void BlinkHit()
|
||||
{
|
||||
var originalColor = _spriteRenderer.color;
|
||||
var hitColor = new Color(_hitColor.r, _hitColor.g, _hitColor.b, originalColor.a);
|
||||
|
||||
DOTween.Sequence()
|
||||
.Append(_spriteRenderer.DOColor(hitColor, _blinkDuration / 4))
|
||||
.Append(_spriteRenderer.DOColor(originalColor, _blinkDuration / 4))
|
||||
.Append(_spriteRenderer.DOColor(hitColor, _blinkDuration / 4))
|
||||
.Append(_spriteRenderer.DOColor(originalColor, _blinkDuration / 4))
|
||||
.SetEase(Ease.Linear)
|
||||
.SetLink(gameObject);
|
||||
}
|
||||
|
||||
private void Die()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1dd5d179d7dc4551ad044f2f8a8986ae
|
||||
timeCreated: 1770111900
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Code.Gameplay.Enemies
|
||||
{
|
||||
public interface IEnemy
|
||||
{
|
||||
void TakeDamage();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a15b885d0f044bddb4669eb39d19eb8e
|
||||
timeCreated: 1770111890
|
||||
@@ -0,0 +1,19 @@
|
||||
using Code.Gameplay.Player;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Gameplay.Enemies
|
||||
{
|
||||
public class VoidEnemy : MonoBehaviour, IEnemy
|
||||
{
|
||||
public void TakeDamage() { }
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
var playerHealth = other.GetComponent<PlayerHealth>();
|
||||
playerHealth?.TakeDamage(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64a245a9516a4ec6a617ded117483d32
|
||||
timeCreated: 1770112280
|
||||
Reference in new issue
Block a user