initial second level
This commit is contained in:
1 parent
be3defc280
commit
e51b34784c
18 files changed
+24668
-13
No files matched your search
@@ -0,0 +1,20 @@
|
||||
using Code.DI;
|
||||
using Code.Gameplay.Player;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Code.Gameplay
|
||||
{
|
||||
public class EndBorderFirst : MonoBehaviour
|
||||
{
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (!other.CompareTag("Player")) return;
|
||||
|
||||
FindFirstObjectByType<DIContainer>().Resolve<IHealthContainer>().Health =
|
||||
FindFirstObjectByType<PlayerHealth>().CurrentHealth;
|
||||
|
||||
SceneManager.LoadScene("Gameplay2");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d78d79ff3c71439eb0f24218bd1edd49
|
||||
timeCreated: 1770221691
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Code.Gameplay
|
||||
{
|
||||
public class HealthContainer : IHealthContainer
|
||||
{
|
||||
public int Health { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba1f9eb7fbba49feb5a1ac2eac5633b3
|
||||
timeCreated: 1770221820
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Code.Gameplay
|
||||
{
|
||||
public interface IHealthContainer
|
||||
{
|
||||
int Health { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43789dc1ca97410ab11a2eab43addae9
|
||||
timeCreated: 1770221847
|
||||
@@ -1,6 +1,8 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using Code.DI;
|
||||
using Code.Gameplay.Enemies;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Code.Gameplay.Player
|
||||
@@ -20,7 +22,8 @@ namespace Code.Gameplay.Player
|
||||
|
||||
[SerializeField] private AudioSource audioSource;
|
||||
|
||||
private int _currentHealth;
|
||||
public int CurrentHealth { get; private set; }
|
||||
|
||||
private bool _isInvincible;
|
||||
private float _invincibilityTimer;
|
||||
private float _lastAttackTime;
|
||||
@@ -34,21 +37,21 @@ namespace Code.Gameplay.Player
|
||||
public event Action OnTookDamage;
|
||||
public event Action OnAttacked;
|
||||
|
||||
public bool IsAlive => _currentHealth > 0;
|
||||
public bool IsAlive => CurrentHealth > 0;
|
||||
public bool CanTakeDamage => !_isInvincible && IsAlive;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_attackClip = Resources.Load<AudioClip>("Audio/SFX/AttackSFX");
|
||||
_damageClip = Resources.Load<AudioClip>("Audio/SFX/DamageSFX");
|
||||
_currentHealth = _maxHealth;
|
||||
OnHealthChanged?.Invoke(_currentHealth);
|
||||
CurrentHealth = SceneManager.GetActiveScene().name != "Gameplay2" ? _maxHealth : FindFirstObjectByType<DIContainer>().Resolve<IHealthContainer>().Health;
|
||||
OnHealthChanged?.Invoke(CurrentHealth);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateInvincibility();
|
||||
_healthBar.value = (float)_currentHealth / _maxHealth;
|
||||
_healthBar.value = (float)CurrentHealth / _maxHealth;
|
||||
}
|
||||
|
||||
public void TakeDamage(bool fatal = false)
|
||||
@@ -56,14 +59,14 @@ namespace Code.Gameplay.Player
|
||||
if (!CanTakeDamage) return;
|
||||
|
||||
if (fatal)
|
||||
_currentHealth = 0;
|
||||
CurrentHealth = 0;
|
||||
else
|
||||
_currentHealth -= _damageFromEnemy;
|
||||
OnHealthChanged?.Invoke(_currentHealth);
|
||||
CurrentHealth -= _damageFromEnemy;
|
||||
OnHealthChanged?.Invoke(CurrentHealth);
|
||||
OnTookDamage?.Invoke();
|
||||
audioSource.PlayOneShot(_damageClip);
|
||||
|
||||
if (_currentHealth <= 0)
|
||||
if (CurrentHealth <= 0)
|
||||
{
|
||||
Die();
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user