From 00065089dd2a39dc0d17cb7395a3d4d6f339e538 Mon Sep 17 00:00:00 2001 From: Andrei Gavra Date: Sat, 22 Jun 2019 11:53:01 +0300 Subject: [PATCH] Partial Dumb & dumber enemies --- Assets/DevMocks/Dumb.prefab | 143 ++ Assets/DevMocks/Dumb.prefab.meta | 7 + Assets/DevMocks/Dumber.prefab | 143 ++ Assets/DevMocks/Dumber.prefab.meta | 7 + Assets/DevMocks/enemy1.png | Bin 0 -> 515 bytes Assets/DevMocks/enemy1.png.meta | 99 + Assets/Prefabs/Managers/GameManager.prefab | 3 + Assets/Scenes/BombScene.unity | 2247 +++++++++++++++-- Assets/Scenes/SampleScene.unity | 150 +- Assets/Scripts/src/Ammo/BombController.cs | 11 +- Assets/Scripts/src/Base/EnemyBase.cs | 62 + Assets/Scripts/src/Base/EnemyBase.cs.meta | 11 + Assets/Scripts/src/Base/PlayerBase.cs | 9 + Assets/Scripts/src/Enemy.meta | 8 + Assets/Scripts/src/Enemy/DumbEnemy.cs | 45 + Assets/Scripts/src/Enemy/DumbEnemy.cs.meta | 11 + Assets/Scripts/src/Enemy/DumberEnemy.cs | 16 + Assets/Scripts/src/Enemy/DumberEnemy.cs.meta | 11 + Assets/Scripts/src/Helpers/ArrayExtensions.cs | 25 + Assets/Scripts/src/Managers/LevelManager.cs | 43 +- ProjectSettings/Physics2DSettings.asset | 2 +- ProjectSettings/TagManager.asset | 3 +- 22 files changed, 2757 insertions(+), 299 deletions(-) create mode 100644 Assets/DevMocks/Dumb.prefab create mode 100644 Assets/DevMocks/Dumb.prefab.meta create mode 100644 Assets/DevMocks/Dumber.prefab create mode 100644 Assets/DevMocks/Dumber.prefab.meta create mode 100644 Assets/DevMocks/enemy1.png create mode 100644 Assets/DevMocks/enemy1.png.meta create mode 100644 Assets/Scripts/src/Base/EnemyBase.cs create mode 100644 Assets/Scripts/src/Base/EnemyBase.cs.meta create mode 100644 Assets/Scripts/src/Enemy.meta create mode 100644 Assets/Scripts/src/Enemy/DumbEnemy.cs create mode 100644 Assets/Scripts/src/Enemy/DumbEnemy.cs.meta create mode 100644 Assets/Scripts/src/Enemy/DumberEnemy.cs create mode 100644 Assets/Scripts/src/Enemy/DumberEnemy.cs.meta diff --git a/Assets/DevMocks/Dumb.prefab b/Assets/DevMocks/Dumb.prefab new file mode 100644 index 0000000..fcf65dd --- /dev/null +++ b/Assets/DevMocks/Dumb.prefab @@ -0,0 +1,143 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &7795087027144463245 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 3746656334748574901} + - component: {fileID: 8735042184812970439} + - component: {fileID: 1330784298487411849} + - component: {fileID: 3670963333241729696} + - component: {fileID: 7110750718968962680} + m_Layer: 14 + m_Name: Dumb + m_TagString: Enemy + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &3746656334748574901 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7795087027144463245} + 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_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!212 &8735042184812970439 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7795087027144463245} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 0 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_Sprite: {fileID: 21300000, guid: 55fee6a02b8d5bc4e993261a717e89cc, type: 3} + m_Color: {r: 1, g: 0.14877324, b: 0, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 1, y: 1} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_MaskInteraction: 0 + m_SpriteSortPoint: 0 +--- !u!114 &1330784298487411849 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7795087027144463245} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1ec64748dfd5f8948996e97a49538538, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!50 &3670963333241729696 +Rigidbody2D: + serializedVersion: 4 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7795087027144463245} + m_BodyType: 0 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 0 + m_Mass: 1 + m_LinearDrag: 0 + m_AngularDrag: 0.05 + m_GravityScale: 0 + m_Material: {fileID: 0} + m_Interpolate: 0 + m_SleepingMode: 1 + m_CollisionDetection: 0 + m_Constraints: 4 +--- !u!61 &7110750718968962680 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7795087027144463245} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 0 + 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: 0.9, y: 0.9} + m_EdgeRadius: 0 diff --git a/Assets/DevMocks/Dumb.prefab.meta b/Assets/DevMocks/Dumb.prefab.meta new file mode 100644 index 0000000..f25cb3f --- /dev/null +++ b/Assets/DevMocks/Dumb.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: fe8fb4e4a7e127648b306469b723d81e +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/DevMocks/Dumber.prefab b/Assets/DevMocks/Dumber.prefab new file mode 100644 index 0000000..021da26 --- /dev/null +++ b/Assets/DevMocks/Dumber.prefab @@ -0,0 +1,143 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &4346602752014574748 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 644191348100887617} + - component: {fileID: 2013141934724497034} + - component: {fileID: 2122485943191788385} + - component: {fileID: 3292464784200894759} + - component: {fileID: 2823282795561844331} + m_Layer: 14 + m_Name: Dumber + m_TagString: Enemy + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &644191348100887617 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4346602752014574748} + 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_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!212 &2013141934724497034 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4346602752014574748} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 0 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_Sprite: {fileID: 21300000, guid: 55fee6a02b8d5bc4e993261a717e89cc, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 1, y: 1} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_MaskInteraction: 0 + m_SpriteSortPoint: 0 +--- !u!114 &2122485943191788385 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4346602752014574748} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f2a42cb28de7d67479c1c852ea36e205, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!50 &3292464784200894759 +Rigidbody2D: + serializedVersion: 4 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4346602752014574748} + m_BodyType: 0 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 0 + m_Mass: 1 + m_LinearDrag: 0 + m_AngularDrag: 0.05 + m_GravityScale: 0 + m_Material: {fileID: 0} + m_Interpolate: 0 + m_SleepingMode: 1 + m_CollisionDetection: 0 + m_Constraints: 4 +--- !u!61 &2823282795561844331 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4346602752014574748} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 0 + 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: 0.9, y: 0.9} + m_EdgeRadius: 0 diff --git a/Assets/DevMocks/Dumber.prefab.meta b/Assets/DevMocks/Dumber.prefab.meta new file mode 100644 index 0000000..80e553b --- /dev/null +++ b/Assets/DevMocks/Dumber.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e719de70e335f4e49ae40cc6731309d4 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/DevMocks/enemy1.png b/Assets/DevMocks/enemy1.png new file mode 100644 index 0000000000000000000000000000000000000000..dd302f3115fe67c1cd7659da9ab4a6a5ddb5590a GIT binary patch literal 515 zcmV+e0{s1nP)Px$y-7qtR9J=Wma%HWP!xuLi;LAk5Lyb+rQjf#SI8vYy7>;iMe!~24&B_OQ(hs0 zL%~IZB~l@S+D$v?3CYbpCpXpN;t!&jlly%+NlpUXa^;kY?$GQs4tX_;>DqW*qrxP# z*KZ?S?eO?;&whWre;Uh(8wuR&x8wiv;NfbQTEq7OQG^v}b{Yp2d`^5X&`M|pE)AC? zG6Ec&T1l}TO9XK>szgdag1@}|q!t!8K2iy4f_fkKPNK~y?(|WE0z(L!AWNgR6cvy*{ z^!Xaq*bA{c*rGewvXTH$w`u@R9RTDbw;c<VbNn0$Db#`aEK1LTyd8n;L@X+hZ2w}q zE|u9z0h~96xlv4TYCoVE#oW}&1Lw&m;qzIP9mRPP=Y)f61^z>VTCT!bflEqAa8ZCH z0P}ONLJ17~;gw7$0>lpyF$9&sg#(); + } + + // Update is called once per frame + protected void Update() + { + Rigidbody2d.MovePosition(Rigidbody2d.position + Direction * Speed * Time.deltaTime); + } + + public void OnTriggerEnter2D(Collider2D other) + { + if (other.CompareTag("Explosion")) + { + onExplosion(); + } + } + + public void onExplosion() + { + Destroy(gameObject); + } + + public void OnCollisionEnter2D(Collision2D col) + { + MoveToCenterOfTheCell(); + Direction = _directions.ChoseRandomExcept(Direction); + } + + protected void MoveToCenterOfTheCell() + { + var absX = Mathf.RoundToInt(transform.position.x); + var absY = Mathf.RoundToInt(transform.position.y); + Vector2 position = new Vector2(absX, absY); + transform.SetPositionAndRotation(position, Quaternion.identity); + } + + protected Vector2 ChooseRandomDirection() + { + return _directions.ChoseRandom(); + } + + protected Vector2 ChooseRandomExceptCertainDirection(Vector2 direction) + { + return _directions.ChoseRandomExcept(direction); + } +} diff --git a/Assets/Scripts/src/Base/EnemyBase.cs.meta b/Assets/Scripts/src/Base/EnemyBase.cs.meta new file mode 100644 index 0000000..7ad6d82 --- /dev/null +++ b/Assets/Scripts/src/Base/EnemyBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f835db3c857aad342bb88b11d1108097 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/src/Base/PlayerBase.cs b/Assets/Scripts/src/Base/PlayerBase.cs index 57fb9cf..02823a1 100644 --- a/Assets/Scripts/src/Base/PlayerBase.cs +++ b/Assets/Scripts/src/Base/PlayerBase.cs @@ -22,11 +22,20 @@ namespace src.Base { onExplosion(); } + if (other.CompareTag("Enemy")) + { + OnContactWithEnemy(); + } } public void onExplosion() { DebugHelper.LogInfo("Player hit by explosion"); } + + private void OnContactWithEnemy() + { + DebugHelper.LogInfo("Player hit by enemy"); + } } } \ No newline at end of file diff --git a/Assets/Scripts/src/Enemy.meta b/Assets/Scripts/src/Enemy.meta new file mode 100644 index 0000000..9e6bea8 --- /dev/null +++ b/Assets/Scripts/src/Enemy.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ad56f70da0be56f42b941505cb11af6f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/src/Enemy/DumbEnemy.cs b/Assets/Scripts/src/Enemy/DumbEnemy.cs new file mode 100644 index 0000000..49c7036 --- /dev/null +++ b/Assets/Scripts/src/Enemy/DumbEnemy.cs @@ -0,0 +1,45 @@ +using UnityEngine; +using src.Helpers; + +public class DumbEnemy : EnemyBase +{ + protected new void Start() + { + Speed = 4f; + base.Start(); + } + + protected new void Update() + { + if (transform.position.x == Mathf.Floor(transform.position.x) && transform.position.y == Mathf.Floor(transform.position.y)) + { + if (RandomChange()) + { + HandleChangeDirection(); + } + else + { + Rigidbody2d.MovePosition(Rigidbody2d.position + Direction * Speed * Time.deltaTime); + } + } + else + { + Rigidbody2d.MovePosition(Rigidbody2d.position + Direction * Speed * Time.deltaTime); + } + } + + private bool RandomChange() + { + System.Random random = new System.Random(); + int randomNumber = random.Next(0, 100); + return randomNumber <= 25; + } + + private void HandleChangeDirection() + { + DebugHelper.LogInfo("Direction randomly changed"); + Direction = ChooseRandomExceptCertainDirection(Direction); + MoveToCenterOfTheCell(); + Rigidbody2d.MovePosition(Rigidbody2d.position + Direction * Speed * Time.deltaTime); + } +} diff --git a/Assets/Scripts/src/Enemy/DumbEnemy.cs.meta b/Assets/Scripts/src/Enemy/DumbEnemy.cs.meta new file mode 100644 index 0000000..7300fad --- /dev/null +++ b/Assets/Scripts/src/Enemy/DumbEnemy.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1ec64748dfd5f8948996e97a49538538 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/src/Enemy/DumberEnemy.cs b/Assets/Scripts/src/Enemy/DumberEnemy.cs new file mode 100644 index 0000000..88b7446 --- /dev/null +++ b/Assets/Scripts/src/Enemy/DumberEnemy.cs @@ -0,0 +1,16 @@ +public class DumberEnemy : EnemyBase +{ + + //Momentan lasam asa, o sa difere probabil la animatii and stats, nu stiu sigur + protected new void Start() + { + Speed = 4f; + base.Start(); + } + + protected new void Update() + { + base.Update(); + } + +} diff --git a/Assets/Scripts/src/Enemy/DumberEnemy.cs.meta b/Assets/Scripts/src/Enemy/DumberEnemy.cs.meta new file mode 100644 index 0000000..5752ce9 --- /dev/null +++ b/Assets/Scripts/src/Enemy/DumberEnemy.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f2a42cb28de7d67479c1c852ea36e205 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/src/Helpers/ArrayExtensions.cs b/Assets/Scripts/src/Helpers/ArrayExtensions.cs index 3de4912..4ee1c47 100644 --- a/Assets/Scripts/src/Helpers/ArrayExtensions.cs +++ b/Assets/Scripts/src/Helpers/ArrayExtensions.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using UnityEngine; using Random = UnityEngine.Random; @@ -10,5 +11,29 @@ namespace src.Helpers var randomIndex = Mathf.FloorToInt(Random.Range(0, arr.Length)); return arr[randomIndex]; } + + public static T ChoseRandomExcept(this T[] arr, T exceptValue) + { + T value; + do + { + var randomIndex = Mathf.FloorToInt(Random.Range(0, arr.Length)); + value = arr[randomIndex]; + + } while (exceptValue.Equals(value)); + return value; + } + + public static T ChoseRandomExcept(this T[] arr, List exceptValue) + { + T value; + do + { + var randomIndex = Mathf.FloorToInt(Random.Range(0, arr.Length)); + value = arr[randomIndex]; + + } while (exceptValue.Contains(value)); + return value; + } } } \ No newline at end of file diff --git a/Assets/Scripts/src/Managers/LevelManager.cs b/Assets/Scripts/src/Managers/LevelManager.cs index fefab6d..b50f212 100644 --- a/Assets/Scripts/src/Managers/LevelManager.cs +++ b/Assets/Scripts/src/Managers/LevelManager.cs @@ -51,6 +51,7 @@ namespace src.Managers public Transform startPosition; public GameObject indestructibleWallPrefab; public GameObject[] destructibleWallPrefabs; + public GameObject[] enemiesPrefab; /* Specifies how many objects we want per level. */ private Count _destructibleWallCount = new Count(150, 350); @@ -64,6 +65,7 @@ namespace src.Managers /* Holds the available positions */ private readonly List _freeGridPositions = new List(); private readonly List _destructibleWalls = new List(); + private readonly List _enemies = new List(); private void SetupUpgrades() { @@ -142,7 +144,7 @@ namespace src.Managers private void SetupLevelDestructibleWalls() { var numberOfDestructilbeWallsToPlace = _destructibleWallCount.RandomIntRange(); - + List usedPositions = new List(); _freeGridPositions.ShuffleList(); foreach (var nextPosition in _freeGridPositions) { @@ -150,10 +152,14 @@ namespace src.Managers { break; } - + usedPositions.Add(nextPosition); PlaceDestructibleTile(nextPosition); numberOfDestructilbeWallsToPlace -= 1; } + foreach (var usedPosition in usedPositions) + { + _freeGridPositions.Remove(usedPosition); + } } private void PlaceDestructibleTile(Vector3 position) @@ -171,7 +177,10 @@ namespace src.Managers var absX = Mathf.RoundToInt(x); var absY = Mathf.RoundToInt(y); - if (absX % 2 == 0 || absY % 2 == 0) return false; + if (absX % 2 == 0 || absY % 2 == 0) + { + return false; + } var instance = Instantiate(indestructibleWallPrefab, new Vector3(x, y, 0f), Quaternion.identity); @@ -179,11 +188,39 @@ namespace src.Managers return true; } + private void SetupLevelEnemies() + { + var numberOfEnemiesToPlace = _enemyCount.RandomIntRange(); + + _freeGridPositions.ShuffleList(); + foreach (var nextPosition in _freeGridPositions) + { + if (numberOfEnemiesToPlace == 0) + { + break; + } + + PlaceEnemy(nextPosition); + numberOfEnemiesToPlace -= 1; + } + } + + private bool PlaceEnemy(Vector3 position) + { + DebugHelper.LogInfo($"PlaceEnemy: x:{position.x} y:{position.y}"); + var randomEnemy = enemiesPrefab.ChoseRandom(); + var instance = Instantiate(randomEnemy, position, Quaternion.identity); + _enemies.Add(instance); + instance.transform.SetParent(boardHolder); + return true; + } + /* Initializes the level. */ public void InitLevel() { InitBoard(); SetupLevelDestructibleWalls(); + SetupLevelEnemies(); SetupExit(); SetupUpgrades(); } diff --git a/ProjectSettings/Physics2DSettings.asset b/ProjectSettings/Physics2DSettings.asset index 30eede9..f4abec4 100644 --- a/ProjectSettings/Physics2DSettings.asset +++ b/ProjectSettings/Physics2DSettings.asset @@ -53,4 +53,4 @@ Physics2DSettings: m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} - m_LayerCollisionMatrix: fffbffffff7bffffff7bffffffffffffff7bfffffffbfffffffffffffffffffffffbffffffffffffc87affffffffffffffffffffffffffffffffffffe9fbffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + m_LayerCollisionMatrix: fffbffffff3bffffff3bffffffffffffff3bfffffffbfffffffffffffffffffffffbffffffffffffc83affffffffffffffffffffffffffffe93bffffe9bbffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index c1f14aa..1de7f28 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -6,6 +6,7 @@ TagManager: tags: - Explosion - Bomb + - Enemy layers: - Default - TransparentFX @@ -21,7 +22,7 @@ TagManager: - - - - - + - Enemy - Player - -