diff --git a/Assets/Prefabs/BombSpawner.prefab b/Assets/Prefabs/BombSpawner.prefab new file mode 100644 index 0000000..cc9ca6c --- /dev/null +++ b/Assets/Prefabs/BombSpawner.prefab @@ -0,0 +1,47 @@ +%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/Plugins/Editor.meta b/Assets/Prefabs/BombSpawner.prefab.meta similarity index 57% rename from Assets/Plugins/Editor.meta rename to Assets/Prefabs/BombSpawner.prefab.meta index a183d1d..1bc735f 100644 --- a/Assets/Plugins/Editor.meta +++ b/Assets/Prefabs/BombSpawner.prefab.meta @@ -1,7 +1,6 @@ fileFormatVersion: 2 -guid: 2361f073d46134fe9acb71dd87d720e8 -folderAsset: yes -DefaultImporter: +guid: c9b7903151183144dbf30c9b2ab371b2 +PrefabImporter: externalObjects: {} userData: assetBundleName: diff --git a/Assets/Scenes/BombScene.unity b/Assets/Scenes/BombScene.unity index c817d22..21a6bcd 100644 --- a/Assets/Scenes/BombScene.unity +++ b/Assets/Scenes/BombScene.unity @@ -428,7 +428,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 519420028} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 7.7645655, y: -4.0430503, z: -2.7893844} + m_LocalPosition: {x: 7.777341, y: -4.0430503, z: -2.7893844} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -8304,8 +8304,6 @@ MonoBehaviour: m_EditorClassIdentifier: movementSpeed: 4 respawnPosition: {fileID: 185746015} - bombPrefab: {fileID: 5909392949477884267, guid: 28467e0d65b5d3844bf1862ac0c49ad9, - type: 3} --- !u!212 &1352658976 SpriteRenderer: m_ObjectHideFlags: 0 @@ -8415,3 +8413,72 @@ BoxCollider2D: serializedVersion: 2 m_Size: {x: 0.913409, y: 0.88454485} m_EdgeRadius: 0 +--- !u!1001 &1896072654971306985 +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: 7.8192964 + objectReference: {fileID: 0} + - target: {fileID: 1896072655702505676, guid: c9b7903151183144dbf30c9b2ab371b2, + type: 3} + propertyPath: m_LocalPosition.y + value: -2.0062397 + objectReference: {fileID: 0} + - target: {fileID: 1896072655702505676, guid: c9b7903151183144dbf30c9b2ab371b2, + type: 3} + propertyPath: m_LocalPosition.z + value: 8.0234375 + 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: 6 + 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} diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 8ce728d..a5e96cb 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -8156,7 +8156,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 519420028} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 10.581639, y: -4.0430503, z: -2.7893844} + m_LocalPosition: {x: 7.7645655, y: -4.0430503, z: -2.7893844} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -8339,6 +8339,75 @@ 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: 7.8192964 + objectReference: {fileID: 0} + - target: {fileID: 1896072655702505676, guid: c9b7903151183144dbf30c9b2ab371b2, + type: 3} + propertyPath: m_LocalPosition.y + value: -2.0062397 + objectReference: {fileID: 0} + - target: {fileID: 1896072655702505676, guid: c9b7903151183144dbf30c9b2ab371b2, + type: 3} + propertyPath: m_LocalPosition.z + value: 8.0234375 + 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 &6843575829779162303 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/src/Ammo/BombController.cs b/Assets/Scripts/src/Ammo/BombController.cs index b59cb9e..ef93df9 100644 --- a/Assets/Scripts/src/Ammo/BombController.cs +++ b/Assets/Scripts/src/Ammo/BombController.cs @@ -8,13 +8,13 @@ namespace src.Ammo { public GameObject explosionPrefab; - private readonly BombStatsManager _bombStatsUtil = BombStatsManager.Instance; + private readonly BombsUtilManager _bombsUtil = BombsUtilManager.Instance; private bool _exploded; // Start is called before the first frame update void Start() { - Invoke(nameof(Explode), _bombStatsUtil.Timer); + Invoke(nameof(Explode), _bombsUtil.Timer); } void Explode() @@ -31,11 +31,12 @@ namespace src.Ammo _exploded = true; Destroy(gameObject, 0.3f); + _bombsUtil.RemoveBomb(transform.position); } private IEnumerator CreateExplosions(Vector3 direction) { - for (int i = 1; i < _bombStatsUtil.Power; i++) + for (int i = 1; i < _bombsUtil.Power; i++) { RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, i, 1 << 8); @@ -46,6 +47,8 @@ namespace src.Ammo } else { + var key = hit.collider.GetComponent(); + key.onExplosion(); break; } } @@ -63,8 +66,6 @@ namespace src.Ammo public void onExplosion() { - // In caz ca o bomba loveste bomba, dam cancel la explozie - // sa nu explodeze twice si o explodam automagic CancelInvoke(nameof(Explode)); Explode(); } diff --git a/Assets/Scripts/src/Ammo/Explosion.cs b/Assets/Scripts/src/Ammo/Explosion.cs index b453fd1..431eec7 100644 --- a/Assets/Scripts/src/Ammo/Explosion.cs +++ b/Assets/Scripts/src/Ammo/Explosion.cs @@ -5,7 +5,7 @@ using UnityEngine; public class Explosion : MonoBehaviour { - private readonly BombStatsManager _bombUtil = BombStatsManager.Instance; + private readonly BombsUtilManager _bombUtil = BombsUtilManager.Instance; public void Start() { diff --git a/Assets/Scripts/src/Managers/BombStatsManager.cs b/Assets/Scripts/src/Managers/BombStatsManager.cs deleted file mode 100644 index d30f1ee..0000000 --- a/Assets/Scripts/src/Managers/BombStatsManager.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace src.Managers -{ - public sealed class BombStatsManager - { - private const int MaxPower = 7; - - public int Power { get; private set; } = 3; - - public float Timer { get; } = 3.0f; - - public float ExplosionDuration { get; } = 0.55f; - - private BombStatsManager() - { - } - - public static BombStatsManager Instance { get; } = new BombStatsManager(); - - public void IncreasePower() - { - if (Power <= MaxPower) - { - Power++; - } - } - } -} \ No newline at end of file diff --git a/Assets/Scripts/src/Managers/BombsSpawner.cs b/Assets/Scripts/src/Managers/BombsSpawner.cs new file mode 100644 index 0000000..13ccb0d --- /dev/null +++ b/Assets/Scripts/src/Managers/BombsSpawner.cs @@ -0,0 +1,23 @@ +using src.Managers; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class BombsSpawner : MonoBehaviour +{ + public GameObject bombPrefab; + + private BombsUtilManager _bombsUtil = BombsUtilManager.Instance; + + public void PlaceBomb(Transform transform) + { + var absX = Mathf.RoundToInt(transform.position.x); + var absY = Mathf.RoundToInt(transform.position.y); + Vector3 position = new Vector3(absX, absY, 0); + if (_bombsUtil.CanPlaceBomb(position)) + { + Instantiate(bombPrefab, position, Quaternion.identity); + _bombsUtil.PlaceBomb(position); + } + } +} diff --git a/Assets/Scripts/src/Managers/BombsSpawner.cs.meta b/Assets/Scripts/src/Managers/BombsSpawner.cs.meta new file mode 100644 index 0000000..f5f935f --- /dev/null +++ b/Assets/Scripts/src/Managers/BombsSpawner.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cd3bf3610d18aa14e805185b5e3f2d4b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/src/Managers/BombsUtilManager.cs b/Assets/Scripts/src/Managers/BombsUtilManager.cs new file mode 100644 index 0000000..5ef931b --- /dev/null +++ b/Assets/Scripts/src/Managers/BombsUtilManager.cs @@ -0,0 +1,68 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace src.Managers +{ + public sealed class BombsUtilManager + { + private 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; + + private BombsUtilManager() + { + } + + public static BombsUtilManager Instance { get; } = new BombsUtilManager(); + + public void IncreasePower() + { + if (Power <= MaxPower) + { + Power++; + } + } + + public void IncreaseAllowedBombs() + { + if(AllowedBombs <= MaxAllowedBombs) + { + AllowedBombs++; + } + } + + public void PlaceBomb(Vector3 position) + { + if(CanPlaceBomb(position)) + { + PlacedBombs++; + _usedPosition.Add(position); + } + } + + public void RemoveBomb(Vector3 position) + { + if(_usedPosition.Contains(position)) + { + PlacedBombs--; + _usedPosition.Remove(position); + } + } + + public bool CanPlaceBomb(Vector3 position) + { + return (!_usedPosition.Contains(position) && (PlacedBombs < AllowedBombs)); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/src/Managers/BombStatsManager.cs.meta b/Assets/Scripts/src/Managers/BombsUtilManager.cs.meta similarity index 100% rename from Assets/Scripts/src/Managers/BombStatsManager.cs.meta rename to Assets/Scripts/src/Managers/BombsUtilManager.cs.meta diff --git a/Assets/Scripts/src/Player/PlayerController.cs b/Assets/Scripts/src/Player/PlayerController.cs index 171bb2a..0193fbd 100644 --- a/Assets/Scripts/src/Player/PlayerController.cs +++ b/Assets/Scripts/src/Player/PlayerController.cs @@ -9,8 +9,6 @@ namespace src.Player { public Transform respawnPosition; - public GameObject bombPrefab; - protected new void Start() { base.Start(); @@ -56,10 +54,9 @@ namespace src.Player } private void PlaceBomb() - { - var absX = Mathf.RoundToInt(transform.position.x); - var absY = Mathf.RoundToInt(transform.position.y); - Instantiate(bombPrefab, new Vector3(absX, absY, 0), Quaternion.identity); + { + GameObject bombsSpawnerObject = GameObject.Find("BombSpawner"); + bombsSpawnerObject.GetComponent().PlaceBomb(transform); } private void HandleBomb() diff --git a/Assets/Scripts/src/Wall/DestructibleWall.cs b/Assets/Scripts/src/Wall/DestructibleWall.cs index 733801e..0422379 100644 --- a/Assets/Scripts/src/Wall/DestructibleWall.cs +++ b/Assets/Scripts/src/Wall/DestructibleWall.cs @@ -1,8 +1,10 @@ +using UnityEngine; + using src.Base; namespace src.Wall { - public class DestructibleWall : GameplayComponent + public class DestructibleWall : GameplayComponent, IExplosable { private bool _spawnExit; private bool _spawnUpgrade; @@ -32,5 +34,10 @@ namespace src.Wall // to get random / desired upgrade } } + + public void onExplosion() + { + Debug.Log("Destructible wall hitted by explosion"); + } } } \ No newline at end of file