From d6ffb9b0952ced3f2d67c7d4154bfa172bf5b1ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nu=C8=9Biu?= Date: Sat, 24 Aug 2019 19:11:14 +0300 Subject: [PATCH 1/6] Refactored Player and deleted BombSpawner --- Assets/Resources/Ammo/BombSpawner.prefab | 47 ------ Assets/Resources/Ammo/BombSpawner.prefab.meta | 7 - Assets/Resources/Ammo/Explosion.prefab | 13 ++ Assets/Resources/Player.prefab | 1 + Assets/Scenes/GameScene.unity | 87 ++--------- Assets/Scripts/src/Ammo/BombCameraShake.cs | 2 +- Assets/Scripts/src/Ammo/BombController.cs | 10 +- .../Ammo/{Explosion.cs => BombExplosion.cs} | 5 +- ...xplosion.cs.meta => BombExplosion.cs.meta} | 0 Assets/Scripts/src/Ammo/BombsSpawner.cs | 32 ---- Assets/Scripts/src/Ammo/BombsSpawner.cs.meta | 11 -- Assets/Scripts/src/Helpers/PrefabAtlas.cs | 4 + .../Scripts/src/Managers/BombsUtilManager.cs | 40 +++-- Assets/Scripts/src/Player/PlayerController.cs | 137 ++++++++++++------ 14 files changed, 143 insertions(+), 253 deletions(-) delete mode 100644 Assets/Resources/Ammo/BombSpawner.prefab delete mode 100644 Assets/Resources/Ammo/BombSpawner.prefab.meta rename Assets/Scripts/src/Ammo/{Explosion.cs => BombExplosion.cs} (60%) rename Assets/Scripts/src/Ammo/{Explosion.cs.meta => BombExplosion.cs.meta} (100%) delete mode 100644 Assets/Scripts/src/Ammo/BombsSpawner.cs delete mode 100644 Assets/Scripts/src/Ammo/BombsSpawner.cs.meta diff --git a/Assets/Resources/Ammo/BombSpawner.prefab b/Assets/Resources/Ammo/BombSpawner.prefab deleted file mode 100644 index cc9ca6c..0000000 --- a/Assets/Resources/Ammo/BombSpawner.prefab +++ /dev/null @@ -1,47 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1 &1896072655702505677 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1896072655702505676} - - component: {fileID: 5279176810039195611} - m_Layer: 0 - m_Name: BombSpawner - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &1896072655702505676 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1896072655702505677} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 7.8192964, y: -2.0062397, z: 8.0234375} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &5279176810039195611 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1896072655702505677} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: cd3bf3610d18aa14e805185b5e3f2d4b, type: 3} - m_Name: - m_EditorClassIdentifier: - bombPrefab: {fileID: 5909392949477884267, guid: 28467e0d65b5d3844bf1862ac0c49ad9, - type: 3} diff --git a/Assets/Resources/Ammo/BombSpawner.prefab.meta b/Assets/Resources/Ammo/BombSpawner.prefab.meta deleted file mode 100644 index 1bc735f..0000000 --- a/Assets/Resources/Ammo/BombSpawner.prefab.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: c9b7903151183144dbf30c9b2ab371b2 -PrefabImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Resources/Ammo/Explosion.prefab b/Assets/Resources/Ammo/Explosion.prefab index aa53f6d..95993d6 100644 --- a/Assets/Resources/Ammo/Explosion.prefab +++ b/Assets/Resources/Ammo/Explosion.prefab @@ -11,6 +11,7 @@ GameObject: - component: {fileID: 2219719956326328737} - component: {fileID: 2976769454423190410} - component: {fileID: 5317321277803550577} + - component: {fileID: 5518668270798060090} m_Layer: 0 m_Name: Explosion m_TagString: Explosion @@ -71,6 +72,18 @@ BoxCollider2D: serializedVersion: 2 m_Size: {x: 0.5, y: 0.5} m_EdgeRadius: 0 +--- !u!114 &5518668270798060090 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2086996798441195857} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 00b7acc459217644283ce8202cadcded, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &5120645164323341697 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Resources/Player.prefab b/Assets/Resources/Player.prefab index e325539..baf366d 100644 --- a/Assets/Resources/Player.prefab +++ b/Assets/Resources/Player.prefab @@ -145,6 +145,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e3cc05deb3d6e44128ad7bc8610cedac, type: 3} m_Name: m_EditorClassIdentifier: + godMode: 0 movementSpeed: 4 --- !u!50 &6843575828445418653 Rigidbody2D: diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index ad67fe2..0171dc5 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -136,75 +136,6 @@ Transform: type: 3} m_PrefabInstance: {fileID: 6843575829779162303} m_PrefabAsset: {fileID: 0} ---- !u!1001 &2013742123 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 1896072655702505677, guid: c9b7903151183144dbf30c9b2ab371b2, - type: 3} - propertyPath: m_Name - value: BombSpawner - objectReference: {fileID: 0} - - target: {fileID: 1896072655702505676, guid: c9b7903151183144dbf30c9b2ab371b2, - type: 3} - propertyPath: m_LocalPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1896072655702505676, guid: c9b7903151183144dbf30c9b2ab371b2, - type: 3} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1896072655702505676, guid: c9b7903151183144dbf30c9b2ab371b2, - type: 3} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1896072655702505676, guid: c9b7903151183144dbf30c9b2ab371b2, - type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1896072655702505676, guid: c9b7903151183144dbf30c9b2ab371b2, - type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1896072655702505676, guid: c9b7903151183144dbf30c9b2ab371b2, - type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1896072655702505676, guid: c9b7903151183144dbf30c9b2ab371b2, - type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 1896072655702505676, guid: c9b7903151183144dbf30c9b2ab371b2, - type: 3} - propertyPath: m_RootOrder - value: 7 - objectReference: {fileID: 0} - - target: {fileID: 1896072655702505676, guid: c9b7903151183144dbf30c9b2ab371b2, - type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1896072655702505676, guid: c9b7903151183144dbf30c9b2ab371b2, - type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 1896072655702505676, guid: c9b7903151183144dbf30c9b2ab371b2, - type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: c9b7903151183144dbf30c9b2ab371b2, type: 3} --- !u!1001 &158905819792232859 PrefabInstance: m_ObjectHideFlags: 0 @@ -212,6 +143,14 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 0} + propertyPath: boardHolder + value: + objectReference: {fileID: 585332173} + - target: {fileID: 0} + propertyPath: startPosition + value: + objectReference: {fileID: 185746015} - target: {fileID: 158905820630581597, guid: fdaa7451ab31b477b930076bbc888bab, type: 3} propertyPath: m_Name @@ -272,14 +211,6 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 0} - propertyPath: boardHolder - value: - objectReference: {fileID: 585332173} - - target: {fileID: 0} - propertyPath: startPosition - value: - objectReference: {fileID: 185746015} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: fdaa7451ab31b477b930076bbc888bab, type: 3} --- !u!1001 &485484359436847253 @@ -401,7 +332,7 @@ PrefabInstance: - target: {fileID: 2219516564235934920, guid: 4ca131020414f4b1597dac2e1d292d7f, type: 3} propertyPath: m_RootOrder - value: 8 + value: 7 objectReference: {fileID: 0} - target: {fileID: 2219516564235934920, guid: 4ca131020414f4b1597dac2e1d292d7f, type: 3} diff --git a/Assets/Scripts/src/Ammo/BombCameraShake.cs b/Assets/Scripts/src/Ammo/BombCameraShake.cs index 49430fc..79e3a51 100644 --- a/Assets/Scripts/src/Ammo/BombCameraShake.cs +++ b/Assets/Scripts/src/Ammo/BombCameraShake.cs @@ -30,7 +30,7 @@ namespace src.Ammo private IEnumerator _startCameraShake() { SetCameraNoise(amplitudeGain, frequencyGain); - yield return new WaitForSeconds(_bombsUtilManager.ExplosionDuration); + yield return new WaitForSeconds(_bombsUtilManager.explosionDuration); SetCameraNoise(0, 0); } diff --git a/Assets/Scripts/src/Ammo/BombController.cs b/Assets/Scripts/src/Ammo/BombController.cs index c527978..8f4efa3 100644 --- a/Assets/Scripts/src/Ammo/BombController.cs +++ b/Assets/Scripts/src/Ammo/BombController.cs @@ -18,7 +18,7 @@ namespace src.Ammo void Start() { _cameraShake = GameObject.Find("VCAM1").GetComponent(); - Invoke(nameof(Explode), _bombsUtil.Timer); + Invoke(nameof(Explode), _bombsUtil.timer); } void Explode() @@ -42,7 +42,7 @@ namespace src.Ammo private IEnumerator CreateExplosions(Vector3 direction) { var currentPosition = transform.position; - for (var i = 1; i < _bombsUtil.Power; i++) + for (var i = 1; i < _bombsUtil.power; i++) { var hit = Physics2D.Raycast(new Vector2(currentPosition.x + 0.5f, currentPosition.y + 0.5f), direction, i, 1 << 8); @@ -54,7 +54,6 @@ namespace src.Ammo } else { - Debug.Log("Hit something"); var key = hit.collider.GetComponent(); key?.OnExplosion(); break; @@ -79,8 +78,9 @@ namespace src.Ammo } public void OnDestroy() - { - _bombsUtil.RemoveBomb(transform.position); + { + DebugHelper.LogError("UNREGISTERED BOMB"); + _bombsUtil.UnregisterBomb(transform.position); } } } \ No newline at end of file diff --git a/Assets/Scripts/src/Ammo/Explosion.cs b/Assets/Scripts/src/Ammo/BombExplosion.cs similarity index 60% rename from Assets/Scripts/src/Ammo/Explosion.cs rename to Assets/Scripts/src/Ammo/BombExplosion.cs index 3d379a8..f4d0f8d 100644 --- a/Assets/Scripts/src/Ammo/Explosion.cs +++ b/Assets/Scripts/src/Ammo/BombExplosion.cs @@ -1,15 +1,16 @@ using src.Base; +using src.Helpers; using src.Managers; namespace src.Ammo { - public class Explosion : GameplayComponent + public class BombExplosion : GameplayComponent { private readonly BombsUtilManager _bombUtil = BombsUtilManager.instance; public void Start() { - Destroy(gameObject, _bombUtil.ExplosionDuration); + Destroy(gameObject, _bombUtil.explosionDuration); } } } diff --git a/Assets/Scripts/src/Ammo/Explosion.cs.meta b/Assets/Scripts/src/Ammo/BombExplosion.cs.meta similarity index 100% rename from Assets/Scripts/src/Ammo/Explosion.cs.meta rename to Assets/Scripts/src/Ammo/BombExplosion.cs.meta diff --git a/Assets/Scripts/src/Ammo/BombsSpawner.cs b/Assets/Scripts/src/Ammo/BombsSpawner.cs deleted file mode 100644 index 64e62c0..0000000 --- a/Assets/Scripts/src/Ammo/BombsSpawner.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using src.Base; -using src.Managers; -using UnityEngine; - -namespace src.Ammo -{ - public class BombsSpawner : GameplayComponent - { - public GameObject bombPrefab; - - private BombsUtilManager _bombsUtil; - - public void Start() - { - _bombsUtil = BombsUtilManager.instance; - } - - public void PlaceBomb(Transform location) - { - var position1 = location.position; - var absX = Mathf.RoundToInt(position1.x); - var absY = Mathf.RoundToInt(position1.y); - var position = new Vector2(absX, absY); - if (_bombsUtil.CanPlaceBomb(position)) - { - Instantiate(bombPrefab, position, Quaternion.identity); - _bombsUtil.PlaceBomb(position); - } - } - } -} diff --git a/Assets/Scripts/src/Ammo/BombsSpawner.cs.meta b/Assets/Scripts/src/Ammo/BombsSpawner.cs.meta deleted file mode 100644 index f5f935f..0000000 --- a/Assets/Scripts/src/Ammo/BombsSpawner.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: cd3bf3610d18aa14e805185b5e3f2d4b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/src/Helpers/PrefabAtlas.cs b/Assets/Scripts/src/Helpers/PrefabAtlas.cs index e77e429..e398034 100644 --- a/Assets/Scripts/src/Helpers/PrefabAtlas.cs +++ b/Assets/Scripts/src/Helpers/PrefabAtlas.cs @@ -25,6 +25,10 @@ namespace src.Helpers Resources.Load("Ammo/FlameUpgrade"); public static readonly GameObject GoldenBombUpgrade = Resources.Load("GoldenBombUpgrade/FlameUpgrade"); + + /* Items */ + public static readonly GameObject PlayerBomb = + Resources.Load("Ammo/Bomb"); /* Enemies */ public static readonly GameObject GreenEnemy = Resources.Load("Enemies/SnowEnemyRandom"); diff --git a/Assets/Scripts/src/Managers/BombsUtilManager.cs b/Assets/Scripts/src/Managers/BombsUtilManager.cs index 2820176..9a9cc37 100644 --- a/Assets/Scripts/src/Managers/BombsUtilManager.cs +++ b/Assets/Scripts/src/Managers/BombsUtilManager.cs @@ -6,22 +6,18 @@ namespace src.Managers { public sealed class BombsUtilManager : GameplayComponent { - private readonly HashSet _usedPosition = new HashSet(); + public static BombsUtilManager instance; + + public int power = 3; + public int allowedBombs = 2; + public int placedBombs = 0; + public float timer = 3.0f; + public float explosionDuration = 0.55f; + + private readonly HashSet _usedPosition = new HashSet(); private const int MaxPower = 7; private const int MaxAllowedBombs = 10; - - public int Power { get; private set; } = 3; - - public int AllowedBombs { get; private set; } = 2; - - public int PlacedBombs { get; private set; } = 0; - - public float Timer { get; } = 3.0f; - - public float ExplosionDuration { get; } = 0.55f; - - public static BombsUtilManager instance; public void Awake() { @@ -37,41 +33,41 @@ namespace src.Managers public void IncreasePower() { - if (Power <= MaxPower) + if (power <= MaxPower) { - Power++; + power++; } } public void IncreaseAllowedBombs() { - if (AllowedBombs <= MaxAllowedBombs) + if (allowedBombs <= MaxAllowedBombs) { - AllowedBombs++; + allowedBombs++; } } - public void PlaceBomb(Vector3 position) + public void RegisterBomb(Vector3 position) { if (CanPlaceBomb(position)) { - PlacedBombs++; + placedBombs++; _usedPosition.Add(position); } } - public void RemoveBomb(Vector3 position) + public void UnregisterBomb(Vector3 position) { if (_usedPosition.Contains(position)) { - PlacedBombs--; + placedBombs--; _usedPosition.Remove(position); } } public bool CanPlaceBomb(Vector3 position) { - return (!_usedPosition.Contains(position) && (PlacedBombs < AllowedBombs)); + return (!_usedPosition.Contains(position) && (placedBombs < allowedBombs)); } } } \ No newline at end of file diff --git a/Assets/Scripts/src/Player/PlayerController.cs b/Assets/Scripts/src/Player/PlayerController.cs index e3e4bbb..ce6e9a4 100644 --- a/Assets/Scripts/src/Player/PlayerController.cs +++ b/Assets/Scripts/src/Player/PlayerController.cs @@ -1,39 +1,47 @@ -using src.Ammo; +using System; +using System.ComponentModel; +using src.Ammo; using src.Base; using src.Helpers; using src.Managers; using UnityEngine; +using UnityStandardAssets.CrossPlatformInput; namespace src.Player { public class PlayerController : GameplayComponent, IExplosable { + public bool godMode; + public float movementSpeed = 4f; + + /* Components */ private GameStateManager _gameStateManager; private Rigidbody2D _rigidbody2d; private Collider2D _collider2D; private Transform _respawnPosition; - private BombsSpawner _bombsSpawner; + private BombsUtilManager _bombsUtil; private Animator _animator; private PlayerUpgrade _playerUpgrade; + + /* Variables */ + private bool _isDead; + + /* Animator Variables*/ private static readonly int AnimHorizontal = Animator.StringToHash("AnimHorizontal"); private static readonly int AnimVertical = Animator.StringToHash("AnimVertical"); private static readonly int AnimDeath = Animator.StringToHash("AnimDeath"); - - - public bool godMode; - public float movementSpeed = 4f; - private bool _isDead; + protected void Start() { _gameStateManager = GameStateManager.instance; _playerUpgrade = PlayerUpgrade.instance; + _bombsUtil = BombsUtilManager.instance; _rigidbody2d = GetComponent(); _collider2D = GetComponent(); _animator = GetComponentInChildren(); _respawnPosition = GameObject.Find("RespawnPosition").transform; - _bombsSpawner = GameObject.Find("BombSpawner").GetComponent(); movementSpeed = _playerUpgrade.GetMovementSpeed(); _playerUpgrade.PlayerSpeed += OnSpeedUpgrade; @@ -53,15 +61,50 @@ namespace src.Player private void Update() { if (_gameStateManager.IsGamePaused || _gameStateManager.IsPlayerMovementForbidden || _isDead) {return;} - HandleBombInput(); + HandleItemsInput(); } private void HandleMovementInput() { #if UNITY_STANDALONE || UNITY_WEBGL || UNITY_EDITOR + HandleKeyboardMovement(); +#elif UNITY_IOS || UNITY_ANDROID + HandleTouchMovement(); +#elif UNITY_PS4 || UNITY_XBOXONE + HandlerControllerMovement(); +#endif + } + + private void HandleItemsInput() + { +#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL + if (Input.GetKeyDown(KeyCode.Space)) + { + PlaceBomb(); + } +#elif UNITY_IOS || UNITY_ANDROID + if (CrossPlatformInputManager.GetButton("PlaceBomb")) + { + PlaceBomb(); + } +#elif UNITY_PS4 || UNITY_XBOXONE + // Console bomb placement is not supported yet. +#endif + } + +#if UNITY_STANDALONE || UNITY_WEBGL || UNITY_EDITOR + private void HandleKeyboardMovement() + { var horizontal = Input.GetAxisRaw("Horizontal"); var vertical = Input.GetAxisRaw("Vertical"); -#elif UNITY_IOS || UNITY_ANDROID + var movementVector = new Vector2(horizontal, vertical); + MovePosition(movementVector); + } +#endif + +#if UNITY_IOS || UNITY_ANDROID + private void HandleTouchMovement() + { var horizontal = 0; var vertical = 0; if (CrossPlatformInputManager.GetButton("MoveUp")) @@ -80,50 +123,60 @@ namespace src.Player { horizontal = -1; } -#elif UNITY_PS4 || UNITY_XBOXONE -// // Console movement is not supported yet. + var movementVector = new Vector2(horizontal, vertical); + MovePosition(movementVector); + } #endif - var movementVector = new Vector2(horizontal, vertical).NormalizeToCross(); - +#if UNITY_PS4 || UNITY_XBOXONE + private void HandlerControllerMovement() + { + throw new NotImplementedException(); + } +#endif + + private void MovePosition(Vector2 movementVector) + { + movementVector = movementVector.NormalizeToCross(); _animator.SetFloat(AnimHorizontal, movementVector.x); _animator.SetFloat(AnimVertical, movementVector.y); - - _rigidbody2d.MovePosition(_rigidbody2d.position + movementSpeed * Time.deltaTime * movementVector); } private void PlaceBomb() { - _bombsSpawner.PlaceBomb(transform); + var position = transform.position; + var absX = Mathf.RoundToInt(position.x); + var absY = Mathf.RoundToInt(position.y); + var newPosition = new Vector2(absX, absY); + if (!_bombsUtil.CanPlaceBomb(newPosition)) return; + + Instantiate(PrefabAtlas.PlayerBomb, newPosition, Quaternion.identity); + _bombsUtil.RegisterBomb(newPosition); } - - private void HandleBombInput() - { -#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL - if (Input.GetKeyDown(KeyCode.Space)) - { - PlaceBomb(); - } -#elif UNITY_IOS || UNITY_ANDROID - if (CrossPlatformInputManager.GetButton("PlaceBomb")) - { - PlaceBomb(); - } -#elif UNITY_PS4 || UNITY_XBOXONE - // Console bomb placement is not supported yet. -#endif - } - + public void Respawn() { - DebugHelper.LogInfo("Player is respawning!"); + DebugHelper.LogInfo("Player is re-spawning!"); transform.SetPositionAndRotation(_respawnPosition.position, Quaternion.identity); _animator.Play("IdleDown"); } + + private void Die() + { + if (godMode) + { + return; + } + _isDead = true; + _collider2D.enabled = false; + _animator.SetBool(AnimDeath, true); + Destroy(gameObject, 0.7f); + } public void OnTriggerExit2D(Collider2D other) { + /* Turn off bomb trigger making it so you can't pass through. */ if (other.CompareTag("Bomb")) { other.isTrigger = false; @@ -142,18 +195,6 @@ namespace src.Player } } - private void Die() - { - if (godMode) - { - return; - } - _isDead = true; - _collider2D.enabled = false; - _animator.SetBool(AnimDeath, true); - Destroy(gameObject, 0.7f); - } - public void OnExplosion() { DebugHelper.LogInfo("Player hit by explosion"); From 13ab2ddb9c96dc187ff5600774e75c0696f0405a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nu=C8=9Biu?= Date: Sat, 24 Aug 2019 19:19:44 +0300 Subject: [PATCH 2/6] Renamed Resources/Ammo to Resources/Items and Explosion to BombExplosion --- Assets/Resources/{Ammo.meta => Items.meta} | 2 +- Assets/Resources/{Ammo => Items}/Bomb.prefab | 0 .../{Ammo => Items}/Bomb.prefab.meta | 0 .../BombExplosion.prefab} | 0 .../BombExplosion.prefab.meta} | 0 .../{Ammo => Items}/BombUpgrade.prefab | 0 .../{Ammo => Items}/BombUpgrade.prefab.meta | 0 .../{Ammo => Items}/FlameUpgrade.prefab | 0 .../{Ammo => Items}/FlameUpgrade.prefab.meta | 0 .../{Ammo => Items}/GoldenBombUpgrade.prefab | 0 .../GoldenBombUpgrade.prefab.meta | 0 .../{Ammo => Items}/SpeedUpgrade.prefab | 0 .../{Ammo => Items}/SpeedUpgrade.prefab.meta | 0 Assets/Scripts/src/Ammo/BombController.cs | 20 +++++++++---------- Assets/Scripts/src/Helpers/PrefabAtlas.cs | 12 ++++++----- 15 files changed, 17 insertions(+), 17 deletions(-) rename Assets/Resources/{Ammo.meta => Items.meta} (77%) rename Assets/Resources/{Ammo => Items}/Bomb.prefab (100%) rename Assets/Resources/{Ammo => Items}/Bomb.prefab.meta (100%) rename Assets/Resources/{Ammo/Explosion.prefab => Items/BombExplosion.prefab} (100%) rename Assets/Resources/{Ammo/Explosion.prefab.meta => Items/BombExplosion.prefab.meta} (100%) rename Assets/Resources/{Ammo => Items}/BombUpgrade.prefab (100%) rename Assets/Resources/{Ammo => Items}/BombUpgrade.prefab.meta (100%) rename Assets/Resources/{Ammo => Items}/FlameUpgrade.prefab (100%) rename Assets/Resources/{Ammo => Items}/FlameUpgrade.prefab.meta (100%) rename Assets/Resources/{Ammo => Items}/GoldenBombUpgrade.prefab (100%) rename Assets/Resources/{Ammo => Items}/GoldenBombUpgrade.prefab.meta (100%) rename Assets/Resources/{Ammo => Items}/SpeedUpgrade.prefab (100%) rename Assets/Resources/{Ammo => Items}/SpeedUpgrade.prefab.meta (100%) diff --git a/Assets/Resources/Ammo.meta b/Assets/Resources/Items.meta similarity index 77% rename from Assets/Resources/Ammo.meta rename to Assets/Resources/Items.meta index 13b3734..336f9d9 100644 --- a/Assets/Resources/Ammo.meta +++ b/Assets/Resources/Items.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: bf3e6294c377ca84d82651fe870a56dc +guid: 142c20937b0ba4d1b9a77c8504dda487 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Resources/Ammo/Bomb.prefab b/Assets/Resources/Items/Bomb.prefab similarity index 100% rename from Assets/Resources/Ammo/Bomb.prefab rename to Assets/Resources/Items/Bomb.prefab diff --git a/Assets/Resources/Ammo/Bomb.prefab.meta b/Assets/Resources/Items/Bomb.prefab.meta similarity index 100% rename from Assets/Resources/Ammo/Bomb.prefab.meta rename to Assets/Resources/Items/Bomb.prefab.meta diff --git a/Assets/Resources/Ammo/Explosion.prefab b/Assets/Resources/Items/BombExplosion.prefab similarity index 100% rename from Assets/Resources/Ammo/Explosion.prefab rename to Assets/Resources/Items/BombExplosion.prefab diff --git a/Assets/Resources/Ammo/Explosion.prefab.meta b/Assets/Resources/Items/BombExplosion.prefab.meta similarity index 100% rename from Assets/Resources/Ammo/Explosion.prefab.meta rename to Assets/Resources/Items/BombExplosion.prefab.meta diff --git a/Assets/Resources/Ammo/BombUpgrade.prefab b/Assets/Resources/Items/BombUpgrade.prefab similarity index 100% rename from Assets/Resources/Ammo/BombUpgrade.prefab rename to Assets/Resources/Items/BombUpgrade.prefab diff --git a/Assets/Resources/Ammo/BombUpgrade.prefab.meta b/Assets/Resources/Items/BombUpgrade.prefab.meta similarity index 100% rename from Assets/Resources/Ammo/BombUpgrade.prefab.meta rename to Assets/Resources/Items/BombUpgrade.prefab.meta diff --git a/Assets/Resources/Ammo/FlameUpgrade.prefab b/Assets/Resources/Items/FlameUpgrade.prefab similarity index 100% rename from Assets/Resources/Ammo/FlameUpgrade.prefab rename to Assets/Resources/Items/FlameUpgrade.prefab diff --git a/Assets/Resources/Ammo/FlameUpgrade.prefab.meta b/Assets/Resources/Items/FlameUpgrade.prefab.meta similarity index 100% rename from Assets/Resources/Ammo/FlameUpgrade.prefab.meta rename to Assets/Resources/Items/FlameUpgrade.prefab.meta diff --git a/Assets/Resources/Ammo/GoldenBombUpgrade.prefab b/Assets/Resources/Items/GoldenBombUpgrade.prefab similarity index 100% rename from Assets/Resources/Ammo/GoldenBombUpgrade.prefab rename to Assets/Resources/Items/GoldenBombUpgrade.prefab diff --git a/Assets/Resources/Ammo/GoldenBombUpgrade.prefab.meta b/Assets/Resources/Items/GoldenBombUpgrade.prefab.meta similarity index 100% rename from Assets/Resources/Ammo/GoldenBombUpgrade.prefab.meta rename to Assets/Resources/Items/GoldenBombUpgrade.prefab.meta diff --git a/Assets/Resources/Ammo/SpeedUpgrade.prefab b/Assets/Resources/Items/SpeedUpgrade.prefab similarity index 100% rename from Assets/Resources/Ammo/SpeedUpgrade.prefab rename to Assets/Resources/Items/SpeedUpgrade.prefab diff --git a/Assets/Resources/Ammo/SpeedUpgrade.prefab.meta b/Assets/Resources/Items/SpeedUpgrade.prefab.meta similarity index 100% rename from Assets/Resources/Ammo/SpeedUpgrade.prefab.meta rename to Assets/Resources/Items/SpeedUpgrade.prefab.meta diff --git a/Assets/Scripts/src/Ammo/BombController.cs b/Assets/Scripts/src/Ammo/BombController.cs index 8f4efa3..2dec22b 100644 --- a/Assets/Scripts/src/Ammo/BombController.cs +++ b/Assets/Scripts/src/Ammo/BombController.cs @@ -8,25 +8,24 @@ namespace src.Ammo { public class BombController : GameplayComponent, IExplosable { - public GameObject explosionPrefab; - - private BombCameraShake _cameraShake; private readonly BombsUtilManager _bombsUtil = BombsUtilManager.instance; + private BombCameraShake _cameraShake; + private SpriteRenderer _spriteRenderer; private bool _exploded; // Start is called before the first frame update - void Start() + private void Start() { _cameraShake = GameObject.Find("VCAM1").GetComponent(); + _spriteRenderer = GetComponentInChildren(); Invoke(nameof(Explode), _bombsUtil.timer); } - void Explode() + private void Explode() { - Instantiate(explosionPrefab, transform.position, Quaternion.identity); - - GetComponentInChildren().enabled = false; + Instantiate(PrefabAtlas.BombExplosion, transform.position, Quaternion.identity); + _spriteRenderer.enabled = false; _cameraShake.StartCameraShakeCoro(); StartCoroutine(CreateExplosions(Vector3.down)); StartCoroutine(CreateExplosions(Vector3.left)); @@ -49,8 +48,8 @@ namespace src.Ammo if (!hit.collider) { - Instantiate(explosionPrefab, transform.position + i * direction, - explosionPrefab.transform.rotation); + Instantiate(PrefabAtlas.BombExplosion, transform.position + i * direction, + PrefabAtlas.BombExplosion.transform.rotation); } else { @@ -79,7 +78,6 @@ namespace src.Ammo public void OnDestroy() { - DebugHelper.LogError("UNREGISTERED BOMB"); _bombsUtil.UnregisterBomb(transform.position); } } diff --git a/Assets/Scripts/src/Helpers/PrefabAtlas.cs b/Assets/Scripts/src/Helpers/PrefabAtlas.cs index e398034..9aa7a7c 100644 --- a/Assets/Scripts/src/Helpers/PrefabAtlas.cs +++ b/Assets/Scripts/src/Helpers/PrefabAtlas.cs @@ -18,17 +18,19 @@ namespace src.Helpers /* Upgrades */ public static readonly GameObject SpeedIncreaseUpgrade = - Resources.Load("Ammo/SpeedUpgrade"); + Resources.Load("Items/SpeedUpgrade"); public static readonly GameObject BombsIncreaseUpgrade = - Resources.Load("Ammo/BombUpgrade"); + Resources.Load("Items/BombUpgrade"); public static readonly GameObject FlamesIncreaseUpgrade = - Resources.Load("Ammo/FlameUpgrade"); + Resources.Load("Items/FlameUpgrade"); public static readonly GameObject GoldenBombUpgrade = - Resources.Load("GoldenBombUpgrade/FlameUpgrade"); + Resources.Load("Items/GoldenBombUpgrade"); /* Items */ public static readonly GameObject PlayerBomb = - Resources.Load("Ammo/Bomb"); + Resources.Load("Items/Bomb"); + public static readonly GameObject BombExplosion = + Resources.Load("Items/BombExplosion"); /* Enemies */ public static readonly GameObject GreenEnemy = Resources.Load("Enemies/SnowEnemyRandom"); From 22af655678c0234c713b600ab089720625818e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nu=C8=9Biu?= Date: Sat, 24 Aug 2019 19:23:36 +0300 Subject: [PATCH 3/6] Renamed Ammo to Bomb --- Assets/Animations/{Ammo.meta => Bomb.meta} | 0 Assets/Animations/{Ammo => Bomb}/Bomb.anim | 0 Assets/Animations/{Ammo => Bomb}/Bomb.anim.meta | 0 Assets/Animations/{Ammo => Bomb}/Bomb.controller | 0 Assets/Animations/{Ammo => Bomb}/Bomb.controller.meta | 0 Assets/Animations/{Ammo => Bomb}/Explosion.anim | 0 Assets/Animations/{Ammo => Bomb}/Explosion.anim.meta | 0 Assets/Animations/{Ammo => Bomb}/Explosion.controller | 0 Assets/Animations/{Ammo => Bomb}/Explosion.controller.meta | 0 Assets/Scripts/src/{Ammo.meta => Bomb.meta} | 0 Assets/Scripts/src/{Ammo => Bomb}/BombCameraShake.cs | 2 +- Assets/Scripts/src/{Ammo => Bomb}/BombCameraShake.cs.meta | 0 Assets/Scripts/src/{Ammo => Bomb}/BombController.cs | 2 +- Assets/Scripts/src/{Ammo => Bomb}/BombController.cs.meta | 0 Assets/Scripts/src/{Ammo => Bomb}/BombExplosion.cs | 3 +-- Assets/Scripts/src/{Ammo => Bomb}/BombExplosion.cs.meta | 0 Assets/Scripts/src/Helpers/PrefabAtlas.cs | 2 +- Assets/Scripts/src/Player/PlayerController.cs | 3 +-- 18 files changed, 5 insertions(+), 7 deletions(-) rename Assets/Animations/{Ammo.meta => Bomb.meta} (100%) rename Assets/Animations/{Ammo => Bomb}/Bomb.anim (100%) rename Assets/Animations/{Ammo => Bomb}/Bomb.anim.meta (100%) rename Assets/Animations/{Ammo => Bomb}/Bomb.controller (100%) rename Assets/Animations/{Ammo => Bomb}/Bomb.controller.meta (100%) rename Assets/Animations/{Ammo => Bomb}/Explosion.anim (100%) rename Assets/Animations/{Ammo => Bomb}/Explosion.anim.meta (100%) rename Assets/Animations/{Ammo => Bomb}/Explosion.controller (100%) rename Assets/Animations/{Ammo => Bomb}/Explosion.controller.meta (100%) rename Assets/Scripts/src/{Ammo.meta => Bomb.meta} (100%) rename Assets/Scripts/src/{Ammo => Bomb}/BombCameraShake.cs (96%) rename Assets/Scripts/src/{Ammo => Bomb}/BombCameraShake.cs.meta (100%) rename Assets/Scripts/src/{Ammo => Bomb}/BombController.cs (99%) rename Assets/Scripts/src/{Ammo => Bomb}/BombController.cs.meta (100%) rename Assets/Scripts/src/{Ammo => Bomb}/BombExplosion.cs (88%) rename Assets/Scripts/src/{Ammo => Bomb}/BombExplosion.cs.meta (100%) diff --git a/Assets/Animations/Ammo.meta b/Assets/Animations/Bomb.meta similarity index 100% rename from Assets/Animations/Ammo.meta rename to Assets/Animations/Bomb.meta diff --git a/Assets/Animations/Ammo/Bomb.anim b/Assets/Animations/Bomb/Bomb.anim similarity index 100% rename from Assets/Animations/Ammo/Bomb.anim rename to Assets/Animations/Bomb/Bomb.anim diff --git a/Assets/Animations/Ammo/Bomb.anim.meta b/Assets/Animations/Bomb/Bomb.anim.meta similarity index 100% rename from Assets/Animations/Ammo/Bomb.anim.meta rename to Assets/Animations/Bomb/Bomb.anim.meta diff --git a/Assets/Animations/Ammo/Bomb.controller b/Assets/Animations/Bomb/Bomb.controller similarity index 100% rename from Assets/Animations/Ammo/Bomb.controller rename to Assets/Animations/Bomb/Bomb.controller diff --git a/Assets/Animations/Ammo/Bomb.controller.meta b/Assets/Animations/Bomb/Bomb.controller.meta similarity index 100% rename from Assets/Animations/Ammo/Bomb.controller.meta rename to Assets/Animations/Bomb/Bomb.controller.meta diff --git a/Assets/Animations/Ammo/Explosion.anim b/Assets/Animations/Bomb/Explosion.anim similarity index 100% rename from Assets/Animations/Ammo/Explosion.anim rename to Assets/Animations/Bomb/Explosion.anim diff --git a/Assets/Animations/Ammo/Explosion.anim.meta b/Assets/Animations/Bomb/Explosion.anim.meta similarity index 100% rename from Assets/Animations/Ammo/Explosion.anim.meta rename to Assets/Animations/Bomb/Explosion.anim.meta diff --git a/Assets/Animations/Ammo/Explosion.controller b/Assets/Animations/Bomb/Explosion.controller similarity index 100% rename from Assets/Animations/Ammo/Explosion.controller rename to Assets/Animations/Bomb/Explosion.controller diff --git a/Assets/Animations/Ammo/Explosion.controller.meta b/Assets/Animations/Bomb/Explosion.controller.meta similarity index 100% rename from Assets/Animations/Ammo/Explosion.controller.meta rename to Assets/Animations/Bomb/Explosion.controller.meta diff --git a/Assets/Scripts/src/Ammo.meta b/Assets/Scripts/src/Bomb.meta similarity index 100% rename from Assets/Scripts/src/Ammo.meta rename to Assets/Scripts/src/Bomb.meta diff --git a/Assets/Scripts/src/Ammo/BombCameraShake.cs b/Assets/Scripts/src/Bomb/BombCameraShake.cs similarity index 96% rename from Assets/Scripts/src/Ammo/BombCameraShake.cs rename to Assets/Scripts/src/Bomb/BombCameraShake.cs index 79e3a51..25025cd 100644 --- a/Assets/Scripts/src/Ammo/BombCameraShake.cs +++ b/Assets/Scripts/src/Bomb/BombCameraShake.cs @@ -4,7 +4,7 @@ using src.Base; using src.Managers; using UnityEngine; -namespace src.Ammo +namespace src.Bomb { public class BombCameraShake : GameplayComponent { diff --git a/Assets/Scripts/src/Ammo/BombCameraShake.cs.meta b/Assets/Scripts/src/Bomb/BombCameraShake.cs.meta similarity index 100% rename from Assets/Scripts/src/Ammo/BombCameraShake.cs.meta rename to Assets/Scripts/src/Bomb/BombCameraShake.cs.meta diff --git a/Assets/Scripts/src/Ammo/BombController.cs b/Assets/Scripts/src/Bomb/BombController.cs similarity index 99% rename from Assets/Scripts/src/Ammo/BombController.cs rename to Assets/Scripts/src/Bomb/BombController.cs index 2dec22b..3229bac 100644 --- a/Assets/Scripts/src/Ammo/BombController.cs +++ b/Assets/Scripts/src/Bomb/BombController.cs @@ -4,7 +4,7 @@ using src.Helpers; using src.Managers; using UnityEngine; -namespace src.Ammo +namespace src.Bomb { public class BombController : GameplayComponent, IExplosable { diff --git a/Assets/Scripts/src/Ammo/BombController.cs.meta b/Assets/Scripts/src/Bomb/BombController.cs.meta similarity index 100% rename from Assets/Scripts/src/Ammo/BombController.cs.meta rename to Assets/Scripts/src/Bomb/BombController.cs.meta diff --git a/Assets/Scripts/src/Ammo/BombExplosion.cs b/Assets/Scripts/src/Bomb/BombExplosion.cs similarity index 88% rename from Assets/Scripts/src/Ammo/BombExplosion.cs rename to Assets/Scripts/src/Bomb/BombExplosion.cs index f4d0f8d..395aaa1 100644 --- a/Assets/Scripts/src/Ammo/BombExplosion.cs +++ b/Assets/Scripts/src/Bomb/BombExplosion.cs @@ -1,8 +1,7 @@ using src.Base; -using src.Helpers; using src.Managers; -namespace src.Ammo +namespace src.Bomb { public class BombExplosion : GameplayComponent { diff --git a/Assets/Scripts/src/Ammo/BombExplosion.cs.meta b/Assets/Scripts/src/Bomb/BombExplosion.cs.meta similarity index 100% rename from Assets/Scripts/src/Ammo/BombExplosion.cs.meta rename to Assets/Scripts/src/Bomb/BombExplosion.cs.meta diff --git a/Assets/Scripts/src/Helpers/PrefabAtlas.cs b/Assets/Scripts/src/Helpers/PrefabAtlas.cs index 9aa7a7c..64ad272 100644 --- a/Assets/Scripts/src/Helpers/PrefabAtlas.cs +++ b/Assets/Scripts/src/Helpers/PrefabAtlas.cs @@ -27,7 +27,7 @@ namespace src.Helpers Resources.Load("Items/GoldenBombUpgrade"); /* Items */ - public static readonly GameObject PlayerBomb = + public static readonly GameObject Bomb = Resources.Load("Items/Bomb"); public static readonly GameObject BombExplosion = Resources.Load("Items/BombExplosion"); diff --git a/Assets/Scripts/src/Player/PlayerController.cs b/Assets/Scripts/src/Player/PlayerController.cs index ce6e9a4..83ec1fd 100644 --- a/Assets/Scripts/src/Player/PlayerController.cs +++ b/Assets/Scripts/src/Player/PlayerController.cs @@ -1,6 +1,5 @@ using System; using System.ComponentModel; -using src.Ammo; using src.Base; using src.Helpers; using src.Managers; @@ -151,7 +150,7 @@ namespace src.Player var newPosition = new Vector2(absX, absY); if (!_bombsUtil.CanPlaceBomb(newPosition)) return; - Instantiate(PrefabAtlas.PlayerBomb, newPosition, Quaternion.identity); + Instantiate(PrefabAtlas.Bomb, newPosition, Quaternion.identity); _bombsUtil.RegisterBomb(newPosition); } From 52a7a536c840b9bb5ff3ec2d7a41b3fc56a8bbc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nu=C8=9Biu?= Date: Sat, 24 Aug 2019 19:27:32 +0300 Subject: [PATCH 4/6] Cleanup BombUtilManager --- .../Scripts/src/Managers/BombsUtilManager.cs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Assets/Scripts/src/Managers/BombsUtilManager.cs b/Assets/Scripts/src/Managers/BombsUtilManager.cs index 9a9cc37..4f45c86 100644 --- a/Assets/Scripts/src/Managers/BombsUtilManager.cs +++ b/Assets/Scripts/src/Managers/BombsUtilManager.cs @@ -49,25 +49,21 @@ namespace src.Managers public void RegisterBomb(Vector3 position) { - if (CanPlaceBomb(position)) - { - placedBombs++; - _usedPosition.Add(position); - } + if (!CanPlaceBomb(position)) return; + placedBombs++; + _usedPosition.Add(position); } public void UnregisterBomb(Vector3 position) { - if (_usedPosition.Contains(position)) - { - placedBombs--; - _usedPosition.Remove(position); - } + if (!_usedPosition.Contains(position)) return; + placedBombs--; + _usedPosition.Remove(position); } public bool CanPlaceBomb(Vector3 position) { - return (!_usedPosition.Contains(position) && (placedBombs < allowedBombs)); + return !_usedPosition.Contains(position) && placedBombs < allowedBombs; } } } \ No newline at end of file From 712965e5ad10f872d41a66f8be3c9483ab12e566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nu=C8=9Biu?= Date: Sun, 25 Aug 2019 22:38:20 +0300 Subject: [PATCH 5/6] Couple PlayerUpgrade with Player --- Assets/Scripts/src/Base/EnemyBase.cs | 2 +- Assets/Scripts/src/Base/UpgradeBase.cs | 4 ++++ Assets/Scripts/src/Managers/GameManager.cs | 1 - Assets/Scripts/src/Player/PlayerController.cs | 10 +++++++--- Assets/Scripts/src/Player/PlayerUpgrade.cs | 16 +++------------- Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs | 2 +- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Assets/Scripts/src/Base/EnemyBase.cs b/Assets/Scripts/src/Base/EnemyBase.cs index 4db57b5..eede5d5 100644 --- a/Assets/Scripts/src/Base/EnemyBase.cs +++ b/Assets/Scripts/src/Base/EnemyBase.cs @@ -65,7 +65,7 @@ namespace src.Base Collider2D.enabled = false; _isDead = true; Animator.SetTrigger(AnimExplode); - Destroy(gameObject, 1); + Destroy(gameObject, 0.7f); } public void OnCollisionEnter2D(Collision2D col) diff --git a/Assets/Scripts/src/Base/UpgradeBase.cs b/Assets/Scripts/src/Base/UpgradeBase.cs index 75f74c2..3bb7281 100644 --- a/Assets/Scripts/src/Base/UpgradeBase.cs +++ b/Assets/Scripts/src/Base/UpgradeBase.cs @@ -1,5 +1,7 @@ using src.Interfaces; using src.Managers; +using src.Player; +using src.Upgrade; using UnityEngine; namespace src.Base @@ -8,6 +10,7 @@ namespace src.Base { protected GameManager gameManager; private UpgradeManager _upgradeManager; + protected PlayerController _playerToUpgrade; public void Start() { @@ -23,6 +26,7 @@ namespace src.Base public void OnTriggerEnter2D(Collider2D other) { if (!other.CompareTag("Player")) return; + _playerToUpgrade = other.GetComponent(); PerformUpgrade(); _upgradeManager.ClaimUpgrade(gameObject); Destroy(gameObject); diff --git a/Assets/Scripts/src/Managers/GameManager.cs b/Assets/Scripts/src/Managers/GameManager.cs index a925a9b..6243c7c 100644 --- a/Assets/Scripts/src/Managers/GameManager.cs +++ b/Assets/Scripts/src/Managers/GameManager.cs @@ -37,7 +37,6 @@ namespace src.Managers _gameStateManager = gameObject.AddComponent(); _levelManager = gameObject.AddComponent(); _upgradeManager = gameObject.AddComponent(); - gameObject.AddComponent(); // Load external components _playerController = GameObject.Find("Player").GetComponent(); diff --git a/Assets/Scripts/src/Player/PlayerController.cs b/Assets/Scripts/src/Player/PlayerController.cs index 83ec1fd..e1c5429 100644 --- a/Assets/Scripts/src/Player/PlayerController.cs +++ b/Assets/Scripts/src/Player/PlayerController.cs @@ -29,14 +29,18 @@ namespace src.Player private static readonly int AnimHorizontal = Animator.StringToHash("AnimHorizontal"); private static readonly int AnimVertical = Animator.StringToHash("AnimVertical"); private static readonly int AnimDeath = Animator.StringToHash("AnimDeath"); - + + + protected void Awake() + { + _playerUpgrade = gameObject.AddComponent(); + } protected void Start() { _gameStateManager = GameStateManager.instance; - _playerUpgrade = PlayerUpgrade.instance; _bombsUtil = BombsUtilManager.instance; - + _rigidbody2d = GetComponent(); _collider2D = GetComponent(); _animator = GetComponentInChildren(); diff --git a/Assets/Scripts/src/Player/PlayerUpgrade.cs b/Assets/Scripts/src/Player/PlayerUpgrade.cs index a98ae1e..290c1c4 100644 --- a/Assets/Scripts/src/Player/PlayerUpgrade.cs +++ b/Assets/Scripts/src/Player/PlayerUpgrade.cs @@ -4,24 +4,14 @@ namespace src.Player { public class PlayerUpgrade : GameplayComponent { + /* Events & Delegates */ public delegate void IncreaseSpeedDelegate(float speed); - public static PlayerUpgrade instance; public event IncreaseSpeedDelegate PlayerSpeed; + + /* Variables */ public const float MaxPlayerSpeed = 8f; private float _movementSpeed = 4f; - public void Awake() - { - if (instance == null) - { - instance = this; - } - else if (instance != null) - { - Destroy(gameObject); - } - } - public float GetMovementSpeed() { return _movementSpeed; diff --git a/Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs b/Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs index 94558e0..76fc482 100644 --- a/Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs +++ b/Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs @@ -7,7 +7,7 @@ namespace src.Upgrade { public override void PerformUpgrade() { - var player = PlayerUpgrade.instance; + var player = _playerToUpgrade.GetComponent(); player.IncreaseSpeed(.5f); } } From 9f3423890c88ee1c6f040b6b6b3a6bca717fc642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nu=C8=9Biu?= Date: Sun, 25 Aug 2019 22:42:25 +0300 Subject: [PATCH 6/6] Create a Sprite sub-gameobject for each upgrade --- Assets/Resources/Items/BombUpgrade.prefab | 53 ++++++-- Assets/Resources/Items/FlameUpgrade.prefab | 57 +++++++-- .../Resources/Items/GoldenBombUpgrade.prefab | 57 +++++++-- Assets/Resources/Items/SpeedUpgrade.prefab | 115 +++++++++++------- 4 files changed, 203 insertions(+), 79 deletions(-) diff --git a/Assets/Resources/Items/BombUpgrade.prefab b/Assets/Resources/Items/BombUpgrade.prefab index 738e79a..f5e93b4 100644 --- a/Assets/Resources/Items/BombUpgrade.prefab +++ b/Assets/Resources/Items/BombUpgrade.prefab @@ -1,6 +1,6 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: ---- !u!1 &2377911311221568072 +--- !u!1 &1566036887972620463 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -8,38 +8,36 @@ GameObject: m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component: - - component: {fileID: 7980903176349258245} - - component: {fileID: 6699440875015304414} - - component: {fileID: 7875732231624854186} - - component: {fileID: 5909025813549437813} + - component: {fileID: 8259350758463922881} + - component: {fileID: 3408177363536354565} m_Layer: 0 - m_Name: BombUpgrade + m_Name: Sprite m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!4 &7980903176349258245 +--- !u!4 &8259350758463922881 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2377911311221568072} + m_GameObject: {fileID: 1566036887972620463} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] - m_Father: {fileID: 0} + m_Father: {fileID: 7980903176349258245} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!212 &6699440875015304414 +--- !u!212 &3408177363536354565 SpriteRenderer: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2377911311221568072} + m_GameObject: {fileID: 1566036887972620463} m_Enabled: 1 m_CastShadows: 0 m_ReceiveShadows: 0 @@ -81,6 +79,39 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 +--- !u!1 &2377911311221568072 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 7980903176349258245} + - component: {fileID: 7875732231624854186} + - component: {fileID: 5909025813549437813} + m_Layer: 0 + m_Name: BombUpgrade + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &7980903176349258245 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2377911311221568072} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 8259350758463922881} + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!61 &7875732231624854186 BoxCollider2D: m_ObjectHideFlags: 0 diff --git a/Assets/Resources/Items/FlameUpgrade.prefab b/Assets/Resources/Items/FlameUpgrade.prefab index 69b44f0..e97fed1 100644 --- a/Assets/Resources/Items/FlameUpgrade.prefab +++ b/Assets/Resources/Items/FlameUpgrade.prefab @@ -1,6 +1,6 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: ---- !u!1 &7385886653159515755 +--- !u!1 &687830553201031435 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -8,38 +8,36 @@ GameObject: m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component: - - component: {fileID: 685382037628668327} - - component: {fileID: 7037551310800415105} - - component: {fileID: 7958292204112110464} - - component: {fileID: 5334633105760309190} + - component: {fileID: 7203846401108240184} + - component: {fileID: 734903871276958427} m_Layer: 0 - m_Name: FlameUpgrade + m_Name: Sprite m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!4 &685382037628668327 +--- !u!4 &7203846401108240184 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7385886653159515755} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_GameObject: {fileID: 687830553201031435} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0.5, y: 0.5, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] - m_Father: {fileID: 0} + m_Father: {fileID: 685382037628668327} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!212 &7037551310800415105 +--- !u!212 &734903871276958427 SpriteRenderer: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7385886653159515755} + m_GameObject: {fileID: 687830553201031435} m_Enabled: 1 m_CastShadows: 0 m_ReceiveShadows: 0 @@ -81,6 +79,39 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 +--- !u!1 &7385886653159515755 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 685382037628668327} + - component: {fileID: 7958292204112110464} + - component: {fileID: 5334633105760309190} + m_Layer: 0 + m_Name: FlameUpgrade + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &685382037628668327 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7385886653159515755} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 7203846401108240184} + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!61 &7958292204112110464 BoxCollider2D: m_ObjectHideFlags: 0 diff --git a/Assets/Resources/Items/GoldenBombUpgrade.prefab b/Assets/Resources/Items/GoldenBombUpgrade.prefab index 29bcb8d..0ec599f 100644 --- a/Assets/Resources/Items/GoldenBombUpgrade.prefab +++ b/Assets/Resources/Items/GoldenBombUpgrade.prefab @@ -1,6 +1,6 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: ---- !u!1 &4467162782262204990 +--- !u!1 &1820949686450855695 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -8,38 +8,36 @@ GameObject: m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component: - - component: {fileID: 5103883358052461890} - - component: {fileID: 3057588250431493961} - - component: {fileID: 234472779121130071} - - component: {fileID: 5391029322786980951} + - component: {fileID: 5028610574346420729} + - component: {fileID: 7106954491075610430} m_Layer: 0 - m_Name: GoldenBombUpgrade + m_Name: Sprite m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!4 &5103883358052461890 +--- !u!4 &5028610574346420729 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 4467162782262204990} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 226.39688, y: 753.2948, z: -16.29858} + m_GameObject: {fileID: 1820949686450855695} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0.5, y: 0.5, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] - m_Father: {fileID: 0} + m_Father: {fileID: 5103883358052461890} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!212 &3057588250431493961 +--- !u!212 &7106954491075610430 SpriteRenderer: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 4467162782262204990} + m_GameObject: {fileID: 1820949686450855695} m_Enabled: 1 m_CastShadows: 0 m_ReceiveShadows: 0 @@ -81,6 +79,39 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 +--- !u!1 &4467162782262204990 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 5103883358052461890} + - component: {fileID: 234472779121130071} + - component: {fileID: 5391029322786980951} + m_Layer: 0 + m_Name: GoldenBombUpgrade + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &5103883358052461890 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4467162782262204990} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 226.39688, y: 753.2948, z: -16.29858} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 5028610574346420729} + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &234472779121130071 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Resources/Items/SpeedUpgrade.prefab b/Assets/Resources/Items/SpeedUpgrade.prefab index c9c2996..a77b238 100644 --- a/Assets/Resources/Items/SpeedUpgrade.prefab +++ b/Assets/Resources/Items/SpeedUpgrade.prefab @@ -9,7 +9,6 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 5958400204756161002} - - component: {fileID: 7382262205660184478} - component: {fileID: 2747432428292150867} - component: {fileID: 6291791717356696744} m_Layer: 0 @@ -29,18 +28,88 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] + m_Children: + - {fileID: 3765005714787864007} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!212 &7382262205660184478 -SpriteRenderer: +--- !u!61 &2747432428292150867 +BoxCollider2D: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4242909486338491383} m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0.5, y: 0.5} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0, y: 0} + oldSize: {x: 1, y: 1} + newSize: {x: 1, y: 1} + adaptiveTilingThreshold: 0.5 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 1, y: 1} + m_EdgeRadius: 0 +--- !u!114 &6291791717356696744 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4242909486338491383} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0b8c723aa8c7476789cbee67fcadfbef, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!1 &8860579196177115379 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 3765005714787864007} + - component: {fileID: 2705328157713901762} + m_Layer: 0 + m_Name: Sprite + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &3765005714787864007 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8860579196177115379} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 5958400204756161002} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!212 &2705328157713901762 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8860579196177115379} + m_Enabled: 1 m_CastShadows: 0 m_ReceiveShadows: 0 m_DynamicOccludee: 1 @@ -81,41 +150,3 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 ---- !u!61 &2747432428292150867 -BoxCollider2D: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 4242909486338491383} - m_Enabled: 1 - m_Density: 1 - m_Material: {fileID: 0} - m_IsTrigger: 1 - m_UsedByEffector: 0 - m_UsedByComposite: 0 - m_Offset: {x: 0.5, y: 0.5} - m_SpriteTilingProperty: - border: {x: 0, y: 0, z: 0, w: 0} - pivot: {x: 0, y: 0} - oldSize: {x: 1, y: 1} - newSize: {x: 1, y: 1} - adaptiveTilingThreshold: 0.5 - drawMode: 0 - adaptiveTiling: 0 - m_AutoTiling: 0 - serializedVersion: 2 - m_Size: {x: 1, y: 1} - m_EdgeRadius: 0 ---- !u!114 &6291791717356696744 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 4242909486338491383} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 0b8c723aa8c7476789cbee67fcadfbef, type: 3} - m_Name: - m_EditorClassIdentifier: