diff --git a/Assets/Prefabs/Horizontal Laser Component.prefab b/Assets/Prefabs/Horizontal Laser Component.prefab new file mode 100644 index 0000000..14a2e31 --- /dev/null +++ b/Assets/Prefabs/Horizontal Laser Component.prefab @@ -0,0 +1,284 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &1100909168816574387 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 8955326583210084389} + - component: {fileID: 5264777883947554001} + - component: {fileID: 3148078346103620960} + - component: {fileID: 5818507107946957817} + - component: {fileID: 2782483786211655668} + - component: {fileID: 5589761257115649079} + m_Layer: 0 + m_Name: Horizontal Laser Component + m_TagString: Bar + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &8955326583210084389 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1100909168816574387} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -5.6821003, y: -1.6287959, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!212 &5264777883947554001 +SpriteRenderer: + serializedVersion: 3 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1100909168816574387} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RayTracingAccelStructBuildFlagsOverride: 0 + m_RayTracingAccelStructBuildFlags: 1 + m_SmallMeshCulling: 1 + m_ForceMeshLod: -1 + m_MeshLodSelectionBias: 0 + 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_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_GlobalIlluminationMeshLod: 0 + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 5 + m_MaskInteraction: 0 + m_Sprite: {fileID: -5434643231075287626, guid: 6f76aeb130e49af12ae51852dd184aec, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 0.16, y: 0.08} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_SpriteSortPoint: 0 + m_BlendShapeWeights: [] +--- !u!61 &3148078346103620960 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1100909168816574387} + m_Enabled: 1 + serializedVersion: 3 + m_Density: 1 + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_ForceSendLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_ForceReceiveLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_ContactCaptureLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_CallbackLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_CompositeOperation: 0 + m_CompositeOrder: 0 + m_Offset: {x: 0, y: 0} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0.5, y: 0.5} + oldSize: {x: 0.16, y: 0.08} + newSize: {x: 0.16, y: 0.08} + adaptiveTilingThreshold: 0.5 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + m_Size: {x: 0.16, y: 0.08} + m_EdgeRadius: 0 +--- !u!50 &5818507107946957817 +Rigidbody2D: + serializedVersion: 5 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1100909168816574387} + m_BodyType: 0 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 0 + m_Mass: 1 + m_LinearDamping: 0 + m_AngularDamping: 0.05 + m_GravityScale: 0 + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_Interpolate: 0 + m_SleepingMode: 1 + m_CollisionDetection: 0 + m_Constraints: 0 +--- !u!82 &2782483786211655668 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1100909168816574387} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 0} + m_Resource: {fileID: 0} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 1 + Loop: 0 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 0 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 +--- !u!114 &5589761257115649079 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1100909168816574387} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c66cc5abc472175528412b7935b3ccbd, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::HorizontalLaser + firingSpeed: 0.03 + horizontalLaserPrefab: {fileID: 1100909168816574387} + canFireLeft: 1 + canFireRight: 1 diff --git a/Assets/Prefabs/Horizontal Laser Component.prefab.meta b/Assets/Prefabs/Horizontal Laser Component.prefab.meta new file mode 100644 index 0000000..510981c --- /dev/null +++ b/Assets/Prefabs/Horizontal Laser Component.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: c524a8891dcadd128918f4e1ee24daa5 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Vertical Laser Component.prefab b/Assets/Prefabs/Vertical Laser Component.prefab new file mode 100644 index 0000000..ffa00d8 --- /dev/null +++ b/Assets/Prefabs/Vertical Laser Component.prefab @@ -0,0 +1,284 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &4863424797291892849 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1611701917113157444} + - component: {fileID: 887144296745564073} + - component: {fileID: 6484715931005458452} + - component: {fileID: 5976407052168656452} + - component: {fileID: 1893128873288966346} + - component: {fileID: 5186441004091910896} + m_Layer: 0 + m_Name: Vertical Laser Component + m_TagString: Bar + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1611701917113157444 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4863424797291892849} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -5.617492, y: -2.2102678, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!212 &887144296745564073 +SpriteRenderer: + serializedVersion: 3 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4863424797291892849} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RayTracingAccelStructBuildFlagsOverride: 0 + m_RayTracingAccelStructBuildFlags: 1 + m_SmallMeshCulling: 1 + m_ForceMeshLod: -1 + m_MeshLodSelectionBias: 0 + 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_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_GlobalIlluminationMeshLod: 0 + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 5 + m_MaskInteraction: 0 + m_Sprite: {fileID: 2127326278317954984, guid: 82a99368ab505b3d0a328ecf9cff8a61, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 0.08, y: 0.16} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_SpriteSortPoint: 0 + m_BlendShapeWeights: [] +--- !u!82 &6484715931005458452 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4863424797291892849} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 0} + m_Resource: {fileID: 0} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 1 + Loop: 0 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 0 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 +--- !u!50 &5976407052168656452 +Rigidbody2D: + serializedVersion: 5 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4863424797291892849} + m_BodyType: 0 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 0 + m_Mass: 1 + m_LinearDamping: 0 + m_AngularDamping: 0.05 + m_GravityScale: 0 + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_Interpolate: 0 + m_SleepingMode: 1 + m_CollisionDetection: 0 + m_Constraints: 0 +--- !u!61 &1893128873288966346 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4863424797291892849} + m_Enabled: 1 + serializedVersion: 3 + m_Density: 1 + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_ForceSendLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_ForceReceiveLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_ContactCaptureLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_CallbackLayers: + serializedVersion: 2 + m_Bits: 4294967295 + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_CompositeOperation: 0 + m_CompositeOrder: 0 + m_Offset: {x: 0, y: 0} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0.5, y: 0.5} + oldSize: {x: 0.08, y: 0.16} + newSize: {x: 0.08, y: 0.16} + adaptiveTilingThreshold: 0.5 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + m_Size: {x: 0.08, y: 0.16} + m_EdgeRadius: 0 +--- !u!114 &5186441004091910896 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4863424797291892849} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e6ef48767c03d5b62b0e336a5691a187, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::VerticalLaser + firingSpeed: 0.03 + verticalLaserPrefab: {fileID: 4863424797291892849} + canFireTop: 1 + canFireBottom: 1 diff --git a/Assets/Prefabs/Vertical Laser Component.prefab.meta b/Assets/Prefabs/Vertical Laser Component.prefab.meta new file mode 100644 index 0000000..352518e --- /dev/null +++ b/Assets/Prefabs/Vertical Laser Component.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3a49f672765bc2720add3ea093b32222 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index 660e36c..ccb1f62 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -1523,6 +1523,8 @@ MonoBehaviour: fader: {fileID: 40868033} horizontalBarrierPrefab: {fileID: 6045656660314469869, guid: 8fb281a5d3d9d99a0b13f951411400d9, type: 3} verticalBarrierPrefab: {fileID: 948828080438803601, guid: 8f1d5e2433b831ebabec25f47dcd071b, type: 3} + horizontalLaserPrefab: {fileID: 1100909168816574387, guid: c524a8891dcadd128918f4e1ee24daa5, type: 3} + verticalLaserPrefab: {fileID: 4863424797291892849, guid: 3a49f672765bc2720add3ea093b32222, type: 3} lives: 8 score: 0 bonus: 3100 diff --git a/Assets/Scripts/Game/HorizontalLaser.cs b/Assets/Scripts/Game/HorizontalLaser.cs new file mode 100644 index 0000000..7f921cb --- /dev/null +++ b/Assets/Scripts/Game/HorizontalLaser.cs @@ -0,0 +1,82 @@ +using UnityEngine; + +public class HorizontalLaser : MonoBehaviour +{ + public GameObject horizontalLaserPrefab; + + public bool canFireLeft = true; + + public bool canFireRight = true; + + private Bounds bounds; + + private bool canFire = true; + + // Start is called once before the first execution of Update after the MonoBehaviour is created + void Start() + { + SpriteRenderer spriteRenderer = GetComponent(); + bounds = spriteRenderer.bounds; + + var walls = GameObject.FindGameObjectsWithTag("Wall"); + + if (walls.Length > 0) + { + // Cap the firing ability if the bar is already intersecting with a wall. + foreach (var wall in walls) + { + if (wall.GetComponent().bounds.Intersects(bounds)) + { + canFire = false; + break; + } + } + } + } + + // Update is called once per frame + void FixedUpdate() + { + if (canFire) + { + if (canFireLeft) + { + Vector3 leftSide = new Vector3( + bounds.min.x - (bounds.size.x / 2.0f), + bounds.center.y, + bounds.center.z + ); + + var left = Instantiate(horizontalLaserPrefab, leftSide, Quaternion.identity); + var leftLaserScript = left.GetComponent(); + leftLaserScript.canFireRight = false; + + Physics2D.IgnoreCollision( + left.GetComponent(), + GetComponent(), + true + ); + } + + if (canFireRight) + { + Vector3 rightSide = new Vector3( + bounds.max.x + (bounds.size.x / 2.0f), + bounds.center.y, + bounds.center.z + ); + var right = Instantiate(horizontalLaserPrefab, rightSide, Quaternion.identity); + var rightLaserScript = right.GetComponent(); + rightLaserScript.canFireLeft = false; + + Physics2D.IgnoreCollision( + right.GetComponent(), + GetComponent(), + true + ); + } + + canFire = false; + } + } +} diff --git a/Assets/Scripts/Game/HorizontalLaser.cs.meta b/Assets/Scripts/Game/HorizontalLaser.cs.meta new file mode 100644 index 0000000..c2e8e0d --- /dev/null +++ b/Assets/Scripts/Game/HorizontalLaser.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: c66cc5abc472175528412b7935b3ccbd \ No newline at end of file diff --git a/Assets/Scripts/Game/Player.cs b/Assets/Scripts/Game/Player.cs index fe76840..c9580b7 100644 --- a/Assets/Scripts/Game/Player.cs +++ b/Assets/Scripts/Game/Player.cs @@ -38,6 +38,10 @@ public class Player : MonoBehaviour public GameObject verticalBarrierPrefab; + public GameObject horizontalLaserPrefab; + + public GameObject verticalLaserPrefab; + public int lives = 8; public int score = 0; @@ -109,6 +113,7 @@ public class Player : MonoBehaviour return; } + // TODO: Generalize this to work with subset of the board bounds. // Initialize the magnets. magnetLeft.GetComponent().enabled = false; magnetRight.GetComponent().enabled = false; @@ -367,14 +372,14 @@ public class Player : MonoBehaviour muzzleAnimator.SetTrigger("firing"); laserCount--; - // if (flipped) - // { - // Instantiate(verticalBarrierPrefab, transform.position, Quaternion.identity); - // } - // else - // { - // Instantiate(horizontalBarrierPrefab, transform.position, Quaternion.identity); - // } + if (flipped) + { + Instantiate(verticalLaserPrefab, transform.position, Quaternion.identity); + } + else + { + Instantiate(horizontalLaserPrefab, transform.position, Quaternion.identity); + } DisableLaser(); } diff --git a/Assets/Scripts/Game/VerticalLaser.cs b/Assets/Scripts/Game/VerticalLaser.cs new file mode 100644 index 0000000..ed99fd4 --- /dev/null +++ b/Assets/Scripts/Game/VerticalLaser.cs @@ -0,0 +1,82 @@ +using UnityEngine; + +public class VerticalLaser : MonoBehaviour +{ + public GameObject verticalLaserPrefab; + + public bool canFireTop = true; + + public bool canFireBottom = true; + + private Bounds bounds; + + private bool canFire = true; + + // Start is called once before the first execution of Update after the MonoBehaviour is created + void Start() + { + SpriteRenderer spriteRenderer = GetComponent(); + bounds = spriteRenderer.bounds; + + var walls = GameObject.FindGameObjectsWithTag("Wall"); + + if (walls.Length > 0) + { + // Cap the firing ability if the bar is already intersecting with a wall. + foreach (var wall in walls) + { + if (wall.GetComponent().bounds.Intersects(bounds)) + { + canFire = false; + break; + } + } + } + } + + // Update is called once per frame + void FixedUpdate() + { + if (canFire) + { + if (canFireTop) + { + Vector3 topSide = new Vector3( + bounds.center.x, + bounds.max.y + (bounds.size.y / 2.0f), + bounds.center.z + ); + + var top = Instantiate(verticalLaserPrefab, topSide, Quaternion.identity); + var topLaserScript = top.GetComponent(); + topLaserScript.canFireBottom = false; + + Physics2D.IgnoreCollision( + top.GetComponent(), + GetComponent(), + true + ); + } + + if (canFireBottom) + { + Vector3 bottomSide = new Vector3( + bounds.center.x, + bounds.min.y - (bounds.size.y / 2.0f), + bounds.center.z + ); + var bottom = Instantiate(verticalLaserPrefab, bottomSide, Quaternion.identity); + var bottomLaserScript = bottom.GetComponent(); + bottomLaserScript.canFireTop = false; + + Physics2D.IgnoreCollision( + bottom.GetComponent(), + GetComponent(), + true + ); + } + + canFire = false; + } + } +} diff --git a/Assets/Scripts/Game/VerticalLaser.cs.meta b/Assets/Scripts/Game/VerticalLaser.cs.meta new file mode 100644 index 0000000..2b24a9b --- /dev/null +++ b/Assets/Scripts/Game/VerticalLaser.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: e6ef48767c03d5b62b0e336a5691a187 \ No newline at end of file diff --git a/Assets/Sprites/201.png b/Assets/Sprites/201.png new file mode 100644 index 0000000..9fab049 Binary files /dev/null and b/Assets/Sprites/201.png differ diff --git a/Assets/Sprites/201.png.meta b/Assets/Sprites/201.png.meta new file mode 100644 index 0000000..51bdc28 --- /dev/null +++ b/Assets/Sprites/201.png.meta @@ -0,0 +1,156 @@ +fileFormatVersion: 2 +guid: 6f76aeb130e49af12ae51852dd184aec +TextureImporter: + internalIDToNameTable: + - first: + 213: -5434643231075287626 + second: 201_0 + externalObjects: {} + serializedVersion: 13 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 2 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 4 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 4 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 4 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: + - serializedVersion: 2 + name: 201_0 + rect: + serializedVersion: 2 + x: 0 + y: 0 + width: 16 + height: 8 + alignment: 0 + pivot: {x: 0, y: 0} + border: {x: 0, y: 0, z: 0, w: 0} + customData: + outline: [] + physicsShape: [] + tessellationDetail: -1 + bones: [] + spriteID: 6bdb6ca76c44494b0800000000000000 + internalID: -5434643231075287626 + vertices: [] + indices: + edges: [] + weights: [] + outline: [] + customData: + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spriteCustomMetadata: + entries: [] + nameFileIdTable: + 201_0: -5434643231075287626 + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Sprites/203.png b/Assets/Sprites/203.png new file mode 100644 index 0000000..e485f67 Binary files /dev/null and b/Assets/Sprites/203.png differ diff --git a/Assets/Sprites/203.png.meta b/Assets/Sprites/203.png.meta new file mode 100644 index 0000000..ffca113 --- /dev/null +++ b/Assets/Sprites/203.png.meta @@ -0,0 +1,156 @@ +fileFormatVersion: 2 +guid: 82a99368ab505b3d0a328ecf9cff8a61 +TextureImporter: + internalIDToNameTable: + - first: + 213: 2127326278317954984 + second: 203_0 + externalObjects: {} + serializedVersion: 13 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 2 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 4 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 4 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 4 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: + - serializedVersion: 2 + name: 203_0 + rect: + serializedVersion: 2 + x: 0 + y: 0 + width: 8 + height: 16 + alignment: 0 + pivot: {x: 0, y: 0} + border: {x: 0, y: 0, z: 0, w: 0} + customData: + outline: [] + physicsShape: [] + tessellationDetail: -1 + bones: [] + spriteID: 8a7de74aaf7c58d10800000000000000 + internalID: 2127326278317954984 + vertices: [] + indices: + edges: [] + weights: [] + outline: [] + customData: + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spriteCustomMetadata: + entries: [] + nameFileIdTable: + 203_0: 2127326278317954984 + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: