From 4300d43f920ce7aabf1e2f75373c156eeb2ea9a4 Mon Sep 17 00:00:00 2001 From: dart Date: Sun, 3 Apr 2022 01:47:57 +0300 Subject: [PATCH] create mob death mehanics --- ldjam50/Assets/Prefabs/character.prefab | 28 +++++++- ldjam50/Assets/Prefabs/mob.prefab | 8 ++- ldjam50/Assets/Scenes/SampleScene.unity | 18 ++++-- ldjam50/Assets/Scripts/Mob.cs | 12 ++-- ldjam50/Assets/Scripts/OverMind.cs | 85 +++++++++++++++++++++---- 5 files changed, 126 insertions(+), 25 deletions(-) diff --git a/ldjam50/Assets/Prefabs/character.prefab b/ldjam50/Assets/Prefabs/character.prefab index e828595..bc0c19f 100644 --- a/ldjam50/Assets/Prefabs/character.prefab +++ b/ldjam50/Assets/Prefabs/character.prefab @@ -25,7 +25,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1199223373439478175} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0.0704} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1137981222306597008} @@ -93,6 +93,7 @@ GameObject: - component: {fileID: 1137981222306597008} - component: {fileID: 8044390793844211544} - component: {fileID: 4520856288189812233} + - component: {fileID: 3826968412464473223} m_Layer: 0 m_Name: character m_TagString: Untagged @@ -108,7 +109,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8275013663521780488} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -1.9470656, y: 1.0665642, z: -0.07037996} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 8006084803627600395} @@ -125,7 +126,7 @@ BoxCollider2D: m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: -0.020021677, y: 0.0039904118} @@ -156,3 +157,24 @@ MonoBehaviour: health: 250 damage: 10 moveSpeed: 0.02 +--- !u!50 &3826968412464473223 +Rigidbody2D: + serializedVersion: 4 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8275013663521780488} + m_BodyType: 0 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 0 + m_Mass: 0.0001 + m_LinearDrag: 0 + m_AngularDrag: 0 + m_GravityScale: 0 + m_Material: {fileID: 0} + m_Interpolate: 0 + m_SleepingMode: 1 + m_CollisionDetection: 0 + m_Constraints: 0 diff --git a/ldjam50/Assets/Prefabs/mob.prefab b/ldjam50/Assets/Prefabs/mob.prefab index b786583..4f8ef6d 100644 --- a/ldjam50/Assets/Prefabs/mob.prefab +++ b/ldjam50/Assets/Prefabs/mob.prefab @@ -43,7 +43,7 @@ BoxCollider2D: m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: -0.0049001575, y: -0.026252389} @@ -71,6 +71,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 7dc89d6f20b8bd496a76c3dad9b1b832, type: 3} m_Name: m_EditorClassIdentifier: + characterObject: {fileID: 0} + moveSpeed: 0 + minDist: 0 + maxDist: 0 --- !u!1 &6540482753690656168 GameObject: m_ObjectHideFlags: 0 @@ -96,7 +100,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6540482753690656168} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0.0704} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 5020074052172004519} diff --git a/ldjam50/Assets/Scenes/SampleScene.unity b/ldjam50/Assets/Scenes/SampleScene.unity index 9703519..177a98d 100644 --- a/ldjam50/Assets/Scenes/SampleScene.unity +++ b/ldjam50/Assets/Scenes/SampleScene.unity @@ -567,15 +567,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1137981222306597008, guid: d58051113365413fe9782fa6b28125fc, type: 3} propertyPath: m_LocalPosition.x - value: -0.38 + value: 0 objectReference: {fileID: 0} - target: {fileID: 1137981222306597008, guid: d58051113365413fe9782fa6b28125fc, type: 3} propertyPath: m_LocalPosition.y - value: 0.49 + value: 0 objectReference: {fileID: 0} - target: {fileID: 1137981222306597008, guid: d58051113365413fe9782fa6b28125fc, type: 3} propertyPath: m_LocalPosition.z - value: -0.07037996 + value: 0 objectReference: {fileID: 0} - target: {fileID: 1137981222306597008, guid: d58051113365413fe9782fa6b28125fc, type: 3} propertyPath: m_LocalRotation.w @@ -619,11 +619,19 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 8006084803627600395, guid: d58051113365413fe9782fa6b28125fc, type: 3} propertyPath: m_LocalPosition.x - value: 0.34 + value: 0 objectReference: {fileID: 0} - target: {fileID: 8006084803627600395, guid: d58051113365413fe9782fa6b28125fc, type: 3} propertyPath: m_LocalPosition.y - value: 0.28 + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8044390793844211544, guid: d58051113365413fe9782fa6b28125fc, type: 3} + propertyPath: m_Offset.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8044390793844211544, guid: d58051113365413fe9782fa6b28125fc, type: 3} + propertyPath: m_Offset.y + value: 0 objectReference: {fileID: 0} - target: {fileID: 8275013663521780488, guid: d58051113365413fe9782fa6b28125fc, type: 3} propertyPath: m_Name diff --git a/ldjam50/Assets/Scripts/Mob.cs b/ldjam50/Assets/Scripts/Mob.cs index 2c059ac..acfa702 100644 --- a/ldjam50/Assets/Scripts/Mob.cs +++ b/ldjam50/Assets/Scripts/Mob.cs @@ -6,6 +6,7 @@ public class Mob : MonoBehaviour { [SerializeField] private GameObject characterObject; + [SerializeField] private OverMind overMind; [SerializeField] private float moveSpeed; @@ -66,16 +67,19 @@ void Update() } } } - - private void OnTriggerEnter2D(Collider2D col) + void OnTriggerEnter2D(Collider2D col) { - print("Detect"); - gameObject.SetActive(false); + Debug.Log("PIZDAAAAAA"); + overMind.DeathGoToPull(gameObject); } + private void Death() + { + } public void SetupMob(OverMind.MobParameters mobParameters) { characterObject = mobParameters.Character; moveSpeed = mobParameters.MoveSpeed; + overMind = mobParameters.OverMind; } } diff --git a/ldjam50/Assets/Scripts/OverMind.cs b/ldjam50/Assets/Scripts/OverMind.cs index af4ddc6..774a4c2 100644 --- a/ldjam50/Assets/Scripts/OverMind.cs +++ b/ldjam50/Assets/Scripts/OverMind.cs @@ -16,18 +16,79 @@ public class OverMind : MonoBehaviour private List _pullEnemies; + + public struct SpawnRegions + { + public Vector4 TopRegion; + public Vector4 BottomRegion; + public Vector4 LeftRegion; + public Vector4 RightRegion; + } + + private SpawnRegions generatedSpawnRegions; + public struct MobParameters { public float MoveSpeed; public GameObject Character; + public OverMind OverMind; } void Start() { PreHeaterSpawn(); - StartCoroutine (spawnMobsCourutine()); - } + StartCoroutine (spawnMobsCourutine()); + print(GenerateSpawnRegions().TopRegion); + generatedSpawnRegions = GenerateSpawnRegions(); + } + + + public SpawnRegions GenerateSpawnRegions() + { + const float spawnBorder = 2f; + var stageDimensions = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height,0)); + print(stageDimensions); + + var generatedSpawnRegions = new SpawnRegions(); + generatedSpawnRegions.TopRegion = new Vector4( + -stageDimensions.x, stageDimensions.x, + stageDimensions.y, stageDimensions.y + spawnBorder); + generatedSpawnRegions.BottomRegion = new Vector4( + -stageDimensions.x, stageDimensions.x, + -stageDimensions.y, -stageDimensions.y - spawnBorder); + generatedSpawnRegions.LeftRegion = new Vector4( + -stageDimensions.x, -stageDimensions.x - spawnBorder, + stageDimensions.y, -stageDimensions.y); + generatedSpawnRegions.RightRegion = new Vector4( + stageDimensions.x, -stageDimensions.x + spawnBorder, + stageDimensions.y, -stageDimensions.y); + + + return generatedSpawnRegions; + } + + private Vector4 PickRandomSpawnBorder() + { + var randomIndex = Random.Range(1, 4); + var _randomSpawnBorder = new Vector4(); + switch (randomIndex) + { + case 1: + _randomSpawnBorder = generatedSpawnRegions.TopRegion; + break; + case 2: + _randomSpawnBorder = generatedSpawnRegions.BottomRegion; + break; + case 3: + _randomSpawnBorder = generatedSpawnRegions.LeftRegion; + break; + case 4: + _randomSpawnBorder = generatedSpawnRegions.RightRegion; + break; + } + return _randomSpawnBorder; + } private void PreHeaterSpawn() { for (var i = 0; i < pullSize; i++) @@ -39,7 +100,8 @@ private void PreHeaterSpawn() var newMobParameters = new MobParameters { MoveSpeed = mobMoveSpeed, - Character = characterObject + Character = characterObject, + OverMind = this }; newMob.GetComponent().SetupMob(newMobParameters); @@ -48,15 +110,10 @@ private void PreHeaterSpawn() Vector3 GenerateRandomSpawnMobPoint() { - var spawnBorder = 2f; - Vector3 stageDimensions = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height,0)); - print(stageDimensions); - var xCoords = new Vector3(stageDimensions.x, stageDimensions.x + spawnBorder); - var yCoords = new Vector3(stageDimensions.y, stageDimensions.y + spawnBorder); - + var _randomSpawnRegion = PickRandomSpawnBorder(); var spawnPoint = new Vector3( - Random.Range(xCoords.x, xCoords.y), - Random.Range(xCoords.x, xCoords.y), + Random.Range(_randomSpawnRegion.x,_randomSpawnRegion.y), + Random.Range(_randomSpawnRegion.z,_randomSpawnRegion.w), 0 ); @@ -80,6 +137,12 @@ IEnumerator spawnMobsCourutine() } } + + public void DeathGoToPull(GameObject mob) + { + mob.SetActive(false); + mob.transform.parent = mobPull.transform; + } // Update is called once per frame void Update() {