Improve bomb usage
This commit is contained in:
parent
9251f1e84b
commit
1273981a38
13 changed files with 309 additions and 47 deletions
47
Assets/Prefabs/BombSpawner.prefab
Normal file
47
Assets/Prefabs/BombSpawner.prefab
Normal file
|
@ -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}
|
|
@ -1,7 +1,6 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2361f073d46134fe9acb71dd87d720e8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
guid: c9b7903151183144dbf30c9b2ab371b2
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
|
@ -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}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<IExplosable>();
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
23
Assets/Scripts/src/Managers/BombsSpawner.cs
Normal file
23
Assets/Scripts/src/Managers/BombsSpawner.cs
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/src/Managers/BombsSpawner.cs.meta
Normal file
11
Assets/Scripts/src/Managers/BombsSpawner.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cd3bf3610d18aa14e805185b5e3f2d4b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
68
Assets/Scripts/src/Managers/BombsUtilManager.cs
Normal file
68
Assets/Scripts/src/Managers/BombsUtilManager.cs
Normal file
|
@ -0,0 +1,68 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace src.Managers
|
||||
{
|
||||
public sealed class BombsUtilManager
|
||||
{
|
||||
private HashSet<Vector3> _usedPosition = new HashSet<Vector3>();
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<BombsSpawner>().PlaceBomb(transform);
|
||||
}
|
||||
|
||||
private void HandleBomb()
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue