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();
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File renamed without changes.
@@ -2165,6 +2165,7 @@ MonoBehaviour:
|
||||
exitButton: {fileID: 254654570}
|
||||
playerHealth: {fileID: 1616841237}
|
||||
audioSource: {fileID: 519420034}
|
||||
blockBorder: {fileID: 302015869}
|
||||
--- !u!1 &294403282
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -2256,6 +2257,84 @@ SpriteRenderer:
|
||||
m_SpriteTileMode: 0
|
||||
m_WasSpriteAssigned: 1
|
||||
m_SpriteSortPoint: 0
|
||||
--- !u!1 &302015867
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 302015868}
|
||||
- component: {fileID: 302015869}
|
||||
m_Layer: 0
|
||||
m_Name: BlockBorder
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &302015868
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 302015867}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 323, y: 7, z: 0}
|
||||
m_LocalScale: {x: 1, y: 40, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1132724089}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!61 &302015869
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 302015867}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 3
|
||||
m_Density: 1
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_LayerOverridePriority: 0
|
||||
m_ForceSendLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_ForceReceiveLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_ContactCaptureLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_IsTrigger: 0
|
||||
m_UsedByEffector: 0
|
||||
m_CompositeOperation: 0
|
||||
m_CompositeOrder: 0
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_SpriteTilingProperty:
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
pivot: {x: 0.5, y: 0.5}
|
||||
oldSize: {x: 1, y: 1}
|
||||
newSize: {x: 1, y: 1}
|
||||
adaptiveTilingThreshold: 0.5
|
||||
drawMode: 0
|
||||
adaptiveTiling: 0
|
||||
m_AutoTiling: 0
|
||||
m_Size: {x: 1, y: 1}
|
||||
m_EdgeRadius: 0
|
||||
--- !u!1 &303465637
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -8443,6 +8522,7 @@ Transform:
|
||||
- {fileID: 1815554476}
|
||||
- {fileID: 851247032}
|
||||
- {fileID: 96529930}
|
||||
- {fileID: 302015868}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &1150054930
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9558759dda1039d72973ff781424cfb3
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -9,8 +9,11 @@ EditorBuildSettings:
|
||||
path: Assets/Resources/Scenes/MainMenu.unity
|
||||
guid: 8c9cfa26abfee488c85f1582747f6a02
|
||||
- enabled: 1
|
||||
path: Assets/Resources/Scenes/Gameplay.unity
|
||||
path: Assets/Resources/Scenes/Gameplay1.unity
|
||||
guid: f1cd135c65a79ce41b92ef8babb59d1a
|
||||
- enabled: 1
|
||||
path: Assets/Resources/Scenes/Gameplay2.unity
|
||||
guid: 9558759dda1039d72973ff781424cfb3
|
||||
m_configObjects:
|
||||
com.unity.input.settings.actions: {fileID: -944628639613478452, guid: 2bcd2660ca9b64942af0de543d8d7100, type: 3}
|
||||
m_UseUCBPForAssetBundles: 0
|
||||
Reference in new issue
Block a user