From 0182f417e238f4671f17978b779b08cc2d41f619 Mon Sep 17 00:00:00 2001 From: misabiko Date: Sun, 28 Jun 2020 19:12:59 -0400 Subject: [PATCH] Implemented explosion --- Assets/Materials/Explosion.mat | 91 ++++++++++++++++++++++++ Assets/Materials/Explosion.mat.meta | 8 +++ Assets/Prefabs/Bomb.prefab | 7 +- Assets/Prefabs/Explosion.prefab | 96 ++++++++++++++++++++++++++ Assets/Prefabs/Explosion.prefab.meta | 7 ++ Assets/Prefabs/Player.prefab | 3 + Assets/Scenes/MainScene Movement.unity | 69 ++++++++++++++++-- Assets/Scripts/Arena.cs | 26 +++++++ Assets/Scripts/Arena.cs.meta | 11 +++ Assets/Scripts/Bomb.cs | 17 ++++- Assets/Scripts/MapData.cs | 5 ++ Assets/Scripts/Player.cs | 11 ++- Assets/Scripts/PlayerMovement.cs | 1 - 13 files changed, 341 insertions(+), 11 deletions(-) create mode 100644 Assets/Materials/Explosion.mat create mode 100644 Assets/Materials/Explosion.mat.meta create mode 100644 Assets/Prefabs/Explosion.prefab create mode 100644 Assets/Prefabs/Explosion.prefab.meta create mode 100644 Assets/Scripts/Arena.cs create mode 100644 Assets/Scripts/Arena.cs.meta diff --git a/Assets/Materials/Explosion.mat b/Assets/Materials/Explosion.mat new file mode 100644 index 0000000..e6f6871 --- /dev/null +++ b/Assets/Materials/Explosion.mat @@ -0,0 +1,91 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &-9186135528214368239 +MonoBehaviour: + m_ObjectHideFlags: 11 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} + m_Name: + m_EditorClassIdentifier: + version: 1 +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Explosion + m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3} + m_ShaderKeywords: _EMISSION _RECEIVE_SHADOWS_OFF + m_LightmapFlags: 2 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: 3050 + stringTagMap: + RenderType: Transparent + disabledShaderPasses: + - SHADOWCASTER + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BaseMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _AlphaClip: 0 + - _Blend: 0 + - _BumpScale: 1 + - _Cull: 2 + - _Cutoff: 0.5 + - _DstBlend: 10 + - _EnvironmentReflections: 1 + - _GlossMapScale: 0 + - _Glossiness: 0 + - _GlossyReflections: 0 + - _Metallic: 0.684 + - _OcclusionStrength: 1 + - _QueueOffset: 0 + - _ReceiveShadows: 0 + - _Smoothness: 0.068 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 5 + - _Surface: 1 + - _WorkflowMode: 1 + - _ZWrite: 0 + m_Colors: + - _BaseColor: {r: 1, g: 0.35671964, b: 0, a: 0.74509805} + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 1.3723974, g: 0.19800758, b: 0, a: 1} + - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} diff --git a/Assets/Materials/Explosion.mat.meta b/Assets/Materials/Explosion.mat.meta new file mode 100644 index 0000000..67f92b4 --- /dev/null +++ b/Assets/Materials/Explosion.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ed48f10b354750a489b056285b06c315 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Bomb.prefab b/Assets/Prefabs/Bomb.prefab index ff3740d..4e8383c 100644 --- a/Assets/Prefabs/Bomb.prefab +++ b/Assets/Prefabs/Bomb.prefab @@ -106,7 +106,7 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3117706498189798980} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: 0.13301453, y: 0.36433798, z: -0.052664176, w: 0.9202127} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: @@ -114,7 +114,7 @@ Transform: - {fileID: 4317797423922707556} m_Father: {fileID: 0} m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_LocalEulerAnglesHint: {x: 16.45, y: 43.2, z: 0} --- !u!114 &7616896404666875622 MonoBehaviour: m_ObjectHideFlags: 0 @@ -127,6 +127,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 67d51956e2b8eb549838087bab514763, type: 3} m_Name: m_EditorClassIdentifier: + delay: 3 --- !u!33 &2024134631421199345 MeshFilter: m_ObjectHideFlags: 0 @@ -182,7 +183,7 @@ SphereCollider: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3117706498189798980} m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_Enabled: 1 serializedVersion: 2 m_Radius: 0.5 diff --git a/Assets/Prefabs/Explosion.prefab b/Assets/Prefabs/Explosion.prefab new file mode 100644 index 0000000..b1398a8 --- /dev/null +++ b/Assets/Prefabs/Explosion.prefab @@ -0,0 +1,96 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &7698221246229025840 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 7698221246229025836} + - component: {fileID: 7698221246229025839} + - component: {fileID: 7698221246229025838} + - component: {fileID: 7698221246229025841} + m_Layer: 0 + m_Name: Explosion + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &7698221246229025836 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7698221246229025840} + m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1.2, y: 1.72, z: 1.2} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} +--- !u!33 &7698221246229025839 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7698221246229025840} + m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &7698221246229025838 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7698221246229025840} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: ed48f10b354750a489b056285b06c315, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!136 &7698221246229025841 +CapsuleCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7698221246229025840} + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_Enabled: 1 + m_Radius: 0.5 + m_Height: 2 + m_Direction: 1 + m_Center: {x: 0, y: 0, z: 0} diff --git a/Assets/Prefabs/Explosion.prefab.meta b/Assets/Prefabs/Explosion.prefab.meta new file mode 100644 index 0000000..6b5568e --- /dev/null +++ b/Assets/Prefabs/Explosion.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 993c1f90960508046a88c6cffe541e87 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index 8fd2ade..8b7d897 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -145,6 +145,9 @@ MonoBehaviour: m_EditorClassIdentifier: labelPrefab: {fileID: 4329401000662665630, guid: 9dde3a77288c79b48bc20480f86418f1, type: 3} + bombPrefab: {fileID: 3117706498189798980, guid: a43946458f796064fb840e21926c557b, + type: 3} + arena: {fileID: 0} --- !u!114 &8085068997774988276 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/MainScene Movement.unity b/Assets/Scenes/MainScene Movement.unity index 5beb887..2a04ee0 100644 --- a/Assets/Scenes/MainScene Movement.unity +++ b/Assets/Scenes/MainScene Movement.unity @@ -333,7 +333,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 549526511} m_LocalRotation: {x: 0.24577199, y: -0.04637042, z: 0.011766266, w: 0.96814644} - m_LocalPosition: {x: 1.97, y: 5.58, z: -13.645} + m_LocalPosition: {x: 1.97, y: 5.58, z: -11.895} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 1552615380} @@ -498,7 +498,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 672854589} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 1.97, y: 1, z: -3.645} + m_LocalPosition: {x: 1.97, y: 1, z: -1.895} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1752689709} @@ -736,6 +736,11 @@ PrefabInstance: propertyPath: m_Name value: Player (2) objectReference: {fileID: 0} + - target: {fileID: 8085068997774988275, guid: c432013b1f3140b40809ac8429d44961, + type: 3} + propertyPath: arena + value: + objectReference: {fileID: 2090411360} - target: {fileID: 8085068997774988277, guid: c432013b1f3140b40809ac8429d44961, type: 3} propertyPath: m_LocalPosition.x @@ -821,6 +826,11 @@ PrefabInstance: propertyPath: m_Name value: Player (1) objectReference: {fileID: 0} + - target: {fileID: 8085068997774988275, guid: c432013b1f3140b40809ac8429d44961, + type: 3} + propertyPath: arena + value: + objectReference: {fileID: 2090411360} - target: {fileID: 8085068997774988277, guid: c432013b1f3140b40809ac8429d44961, type: 3} propertyPath: m_LocalPosition.x @@ -995,7 +1005,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1930866305} m_LocalRotation: {x: 0.24577199, y: -0.04637042, z: 0.011766266, w: 0.96814644} - m_LocalPosition: {x: 1.97, y: 5.58, z: -13.645} + m_LocalPosition: {x: 1.97, y: 5.58, z: -11.895} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1752689709} @@ -1072,6 +1082,52 @@ Transform: type: 3} m_PrefabInstance: {fileID: 8085068998021310727} m_PrefabAsset: {fileID: 0} +--- !u!1 &2090411359 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2090411361} + - component: {fileID: 2090411360} + m_Layer: 0 + m_Name: Arena + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &2090411360 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2090411359} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fd57a24b0f54221479c194d63800c3b6, type: 3} + m_Name: + m_EditorClassIdentifier: + data: {fileID: 11400000, guid: a0c83aa9643298148a6956d2f0c1c57e, type: 2} + explosionPrefab: {fileID: 7698221246229025840, guid: 993c1f90960508046a88c6cffe541e87, + type: 3} +--- !u!4 &2090411361 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2090411359} + 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: 6 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &8085068998021310727 PrefabInstance: m_ObjectHideFlags: 0 @@ -1084,6 +1140,11 @@ PrefabInstance: propertyPath: m_Name value: Player objectReference: {fileID: 0} + - target: {fileID: 8085068997774988275, guid: c432013b1f3140b40809ac8429d44961, + type: 3} + propertyPath: arena + value: + objectReference: {fileID: 2090411360} - target: {fileID: 8085068997774988277, guid: c432013b1f3140b40809ac8429d44961, type: 3} propertyPath: m_LocalPosition.x @@ -1097,7 +1158,7 @@ PrefabInstance: - target: {fileID: 8085068997774988277, guid: c432013b1f3140b40809ac8429d44961, type: 3} propertyPath: m_LocalPosition.z - value: 0 + value: 3.5 objectReference: {fileID: 0} - target: {fileID: 8085068997774988277, guid: c432013b1f3140b40809ac8429d44961, type: 3} diff --git a/Assets/Scripts/Arena.cs b/Assets/Scripts/Arena.cs new file mode 100644 index 0000000..9f144a0 --- /dev/null +++ b/Assets/Scripts/Arena.cs @@ -0,0 +1,26 @@ +using System; +using UnityEngine; + +public class Arena : MonoBehaviour { + public MapData data; + public GameObject explosionPrefab; + + public void Explode(Vector3 position, int strength) { + if (strength <= 0) + throw new ArgumentException("Explosion strength must be positive."); + + Vector3 explosionPos = data.GetClosestTilePos(position); + + for (int i = 0; i < 3; i++) { + var rotation = explosionPrefab.transform.rotation; + var newRotation = Quaternion.Euler(rotation.eulerAngles + Vector3.up * i * 60f); + + var explosion = Instantiate(explosionPrefab, explosionPos, newRotation); + //TODO multiply explosion.transform.scale.y by strength + + Destroy(explosion, 1f); + } + } + + public Vector3 GetClosestTilePos(Vector3 pos) => data.GetClosestTilePos(pos); +} \ No newline at end of file diff --git a/Assets/Scripts/Arena.cs.meta b/Assets/Scripts/Arena.cs.meta new file mode 100644 index 0000000..0bff60c --- /dev/null +++ b/Assets/Scripts/Arena.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fd57a24b0f54221479c194d63800c3b6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Bomb.cs b/Assets/Scripts/Bomb.cs index 55667b9..6c788ee 100644 --- a/Assets/Scripts/Bomb.cs +++ b/Assets/Scripts/Bomb.cs @@ -1,7 +1,20 @@ using UnityEngine; public class Bomb : MonoBehaviour { - void Start() {} + public float delay = 3f; - void Update() {} + int strength; + Arena arena; + + public void Init(int strength, Arena arena) { + this.strength = strength; + this.arena = arena; + + Invoke(nameof(Explode), delay); + } + + void Explode() { + arena.Explode(transform.position, strength); + Destroy(gameObject); + } } \ No newline at end of file diff --git a/Assets/Scripts/MapData.cs b/Assets/Scripts/MapData.cs index 8e2244f..c290a59 100644 --- a/Assets/Scripts/MapData.cs +++ b/Assets/Scripts/MapData.cs @@ -83,4 +83,9 @@ public class MapData : ScriptableObject { public static Vector2 GetNeighbor(Vector2 axial, Direction direction) => axial + AxialDirections[(int) direction]; + + public Vector3 GetClosestTilePos(Vector3 worldPos) { + Vector2 coords = WorldToAxial(worldPos); + return AxialToWorld(coords) + Vector3.up * worldPos.y; + } } \ No newline at end of file diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs index 7e836df..350fd1e 100644 --- a/Assets/Scripts/Player.cs +++ b/Assets/Scripts/Player.cs @@ -4,7 +4,9 @@ using UnityEngine.InputSystem; [RequireComponent(typeof(PlayerInput))] public class Player : MonoBehaviour { public GameObject labelPrefab; - + public GameObject bombPrefab; + public Arena arena; + void Start() { Transform canvas = GameObject.Find("Canvas").transform; PlayerLabel label = Instantiate(labelPrefab, canvas).GetComponent(); @@ -14,5 +16,12 @@ public class Player : MonoBehaviour { label.player = transform; label.SetName(gameObject.name); label.SetController(playerInput.currentControlScheme); + + playerInput.actions["Place"].performed += OnPlace; + } + + void OnPlace(InputAction.CallbackContext ctx) { + var bomb = Instantiate(bombPrefab, arena.GetClosestTilePos(transform.position) - Vector3.up * 0.5f, bombPrefab.transform.rotation); + bomb.GetComponent().Init(1, arena); } } \ No newline at end of file diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index 81c0804..28b1ab3 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -40,7 +40,6 @@ public class PlayerMovement : MonoBehaviour { Vector3 direction = camForward * moveInput.y + camTransform.right * moveInput.x; lastDirection = GetDirection(direction); - if (tiledDirection) { Vector2 coords = mapData.WorldToAxial(transform.position); Vector2 neighborCoords = MapData.GetNeighbor(coords, lastDirection);