initial second level
This commit is contained in:
1 parent
be3defc280
commit
e51b34784c
18 files changed
+24668
-13
No files matched your search
@@ -1,3 +1,4 @@
|
||||
using Code.Gameplay;
|
||||
using Code.Input;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
@@ -13,6 +14,7 @@ namespace Code.DI
|
||||
var container = new GameObject("DIContainer").AddComponent<DIContainer>();
|
||||
|
||||
container.Register<IInputService>(new InputService(inputActionAsset));
|
||||
container.Register<IHealthContainer>(new HealthContainer());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Code.DI;
|
||||
using Code.Gameplay.Enemies;
|
||||
using Code.Gameplay.Player;
|
||||
using Code.Input;
|
||||
using TMPro;
|
||||
@@ -10,14 +11,14 @@ using Unity.VisualScripting;
|
||||
|
||||
namespace Code.UI
|
||||
{
|
||||
public class GameplayController : MonoBehaviour
|
||||
public class GameplayControllerFirst : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image deathScreen;
|
||||
[SerializeField] private TMP_Text deathText;
|
||||
[SerializeField] private Button exitButton;
|
||||
[SerializeField] private PlayerHealth playerHealth;
|
||||
[SerializeField] private AudioSource audioSource;
|
||||
|
||||
[SerializeField] private BoxCollider2D blockBorder;
|
||||
private IInputService _inputService;
|
||||
|
||||
private void Start()
|
||||
@@ -62,5 +63,13 @@ namespace Code.UI
|
||||
exitButton.onClick.RemoveAllListeners();
|
||||
SceneManager.LoadScene("MainMenu");
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!FindAnyObjectByType<BasicEnemy>())
|
||||
{
|
||||
blockBorder.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -0,0 +1,75 @@
|
||||
using Code.DI;
|
||||
using Code.Gameplay.Enemies;
|
||||
using Code.Gameplay.Player;
|
||||
using Code.Input;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
using Unity.VisualScripting;
|
||||
|
||||
namespace Code.UI
|
||||
{
|
||||
public class GameplayControllerSecond : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image deathScreen;
|
||||
[SerializeField] private TMP_Text deathText;
|
||||
[SerializeField] private Button exitButton;
|
||||
[SerializeField] private PlayerHealth playerHealth;
|
||||
[SerializeField] private AudioSource audioSource;
|
||||
[SerializeField] private BoxCollider2D blockBorder;
|
||||
private IInputService _inputService;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_inputService = FindFirstObjectByType<DIContainer>().Resolve<IInputService>();
|
||||
_inputService.EnableMap(ActionMapping.Gameplay);
|
||||
|
||||
FindFirstObjectByType<PlayerMovement>().Construct(_inputService);
|
||||
|
||||
exitButton.onClick.AddListener(OnExitButtonPressed);
|
||||
playerHealth.OnDied += HandleDeath;
|
||||
|
||||
deathScreen.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void HandleDeath()
|
||||
{
|
||||
var clip = Resources.Load<AudioClip>("Audio/SFX/DeathSFX");
|
||||
audioSource.PlayOneShot(clip);
|
||||
_inputService.DisableMap(ActionMapping.Gameplay);
|
||||
deathScreen.gameObject.SetActive(true);
|
||||
|
||||
deathScreen.rectTransform.localScale = Vector3.zero;
|
||||
deathScreen.rectTransform.DOScale(1f, 0.3f)
|
||||
.SetEase(Ease.OutBack);
|
||||
|
||||
deathText.color = deathText.color.WithAlpha(0f);
|
||||
deathText.DOFade(1f, 0.6f)
|
||||
.OnComplete(() =>
|
||||
{
|
||||
deathText.DOFade(0.8f, 0.5f)
|
||||
.SetLoops(-1, LoopType.Yoyo)
|
||||
.SetEase(Ease.InOutSine);
|
||||
});
|
||||
}
|
||||
|
||||
private void OnExitButtonPressed()
|
||||
{
|
||||
DOTween.Kill(deathScreen.rectTransform);
|
||||
DOTween.Kill(deathText);
|
||||
|
||||
exitButton.onClick.RemoveAllListeners();
|
||||
SceneManager.LoadScene("MainMenu");
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!FindAnyObjectByType<BasicEnemy>())
|
||||
{
|
||||
blockBorder.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 383ec75bd05d4b5fae1493d1d7265015
|
||||
timeCreated: 1770222045
|
||||
@@ -121,7 +121,7 @@ namespace Code.UI
|
||||
parallaxRoot.localPosition = _currentParallaxOffset;
|
||||
}
|
||||
|
||||
private void OnStartGameClicked() => FadeOutAndLoad("Gameplay");
|
||||
private void OnStartGameClicked() => FadeOutAndLoad("Gameplay1");
|
||||
|
||||
private void OnExitButtonClicked() => FadeOutAndQuit();
|
||||
|
||||
|
||||
Reference in new issue
Block a user