diff --git a/Assets/Prefabs/Barrel.prefab b/Assets/Prefabs/Barrel.prefab new file mode 100644 index 0000000..08b7c88 --- /dev/null +++ b/Assets/Prefabs/Barrel.prefab @@ -0,0 +1,207 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &424114502350994919 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 8746823443980265568} + - component: {fileID: 1866938550730718414} + - component: {fileID: 1412464023054947666} + - component: {fileID: 1017275022680165955} + - component: {fileID: 7944145363570086424} + m_Layer: 0 + m_Name: Barrel + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &8746823443980265568 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 424114502350994919} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -16.38031, y: 5.175766, z: -6.0566406} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 6622279062642803414} + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!50 &1866938550730718414 +Rigidbody2D: + serializedVersion: 4 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 424114502350994919} + m_BodyType: 2 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 0 + m_Mass: 1 + m_LinearDrag: 0 + m_AngularDrag: 0.05 + m_GravityScale: 1 + m_Material: {fileID: 0} + m_Interpolate: 0 + m_SleepingMode: 1 + m_CollisionDetection: 0 + m_Constraints: 0 +--- !u!61 &1412464023054947666 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 424114502350994919} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: -0.001390934} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0, y: 0} + oldSize: {x: 0, y: 0} + newSize: {x: 0, y: 0} + adaptiveTilingThreshold: 0 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 0.50437164, y: 0.5076113} + m_EdgeRadius: 0 +--- !u!114 &1017275022680165955 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 424114502350994919} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a2110188365a59e4cb31d0e84789fbbd, type: 3} + m_Name: + m_EditorClassIdentifier: + BodypartPrefabs: + - {fileID: 3847767376140256459, guid: b3bfb4ae89e38244dad2c4396ec48ba3, type: 3} + - {fileID: 3847767376140256459, guid: 7194f42d640f6cc4b8ff71eff6a9b85b, type: 3} + - {fileID: 3847767376140256459, guid: 16e2e783575dcf147bd67039283f1c17, type: 3} + DebugExplode: 0 + ParticlesPerBodypart: 70 + BodypartMinCount: 1 + BodypartMaxCount: 3 + DebrisType: 2 +--- !u!114 &7944145363570086424 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 424114502350994919} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7a80c0c53597a834e9decbeebcb08434, type: 3} + m_Name: + m_EditorClassIdentifier: + GunLaunchForceMultiplier: 1 + HoleTransform: {fileID: 6622279062642803414} + Explodable: {fileID: 1017275022680165955} + ExplodeOnEmpty: 1 + GunsLeft: 1 + PossibleGuns: + - {fileID: 4462327694118370270, guid: 7b3529c1a7d22d143a060281857bbca5, type: 3} + - {fileID: 2523517584660005062, guid: 15e91d59183ba524bb3bc46b402b722d, type: 3} + SpriteChanger: {fileID: 0} + DebugExpelGun: 0 +--- !u!1 &2707968752687241717 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6622279062642803414} + - component: {fileID: 2042706909563280659} + m_Layer: 0 + m_Name: Placeholder + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6622279062642803414 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2707968752687241717} + 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: 8746823443980265568} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!212 &2042706909563280659 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2707968752687241717} + 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_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_SortingLayerID: -947994997 + m_SortingLayer: 4 + m_SortingOrder: 0 + m_Sprite: {fileID: 21300000, guid: 472874229c563e241bddc073ec2dbb90, 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.5, y: 0.5} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_MaskInteraction: 0 + m_SpriteSortPoint: 0 diff --git a/Assets/Prefabs/Barrel.prefab.meta b/Assets/Prefabs/Barrel.prefab.meta new file mode 100644 index 0000000..49c2510 --- /dev/null +++ b/Assets/Prefabs/Barrel.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: f2ea86881596cfa4b980184bde6a13be +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Vending Machine.prefab b/Assets/Prefabs/Vending Machine.prefab index 9b34d6b..3cf7a3c 100644 --- a/Assets/Prefabs/Vending Machine.prefab +++ b/Assets/Prefabs/Vending Machine.prefab @@ -12,7 +12,7 @@ GameObject: - component: {fileID: 11699643643052996} - component: {fileID: 7530413041674808940} m_Layer: 0 - m_Name: Placeholder + m_Name: Sprite m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -114,6 +114,7 @@ GameObject: - component: {fileID: 11699643827672084} - component: {fileID: 11699643827672083} - component: {fileID: 11699643827672086} + - component: {fileID: 4165805474229086665} m_Layer: 0 m_Name: Vending Machine m_TagString: Environment @@ -151,17 +152,12 @@ MonoBehaviour: m_EditorClassIdentifier: GunLaunchForceMultiplier: 3.5 HoleTransform: {fileID: 11699643844798483} + Explodable: {fileID: 11699643827672086} + ExplodeOnEmpty: 0 GunsLeft: 3 PossibleGuns: - {fileID: 4462327694118370270, guid: 7b3529c1a7d22d143a060281857bbca5, type: 3} - Sprite: {fileID: 11699643643052996} - Sprites: - - {fileID: 2570391356933361261, guid: 0aa113ac73f3394448b77e6c4c712232, type: 3} - - {fileID: 881297774068237510, guid: 0aa113ac73f3394448b77e6c4c712232, type: 3} - - {fileID: 6754790859930108749, guid: 0aa113ac73f3394448b77e6c4c712232, type: 3} - - {fileID: -5872275606889041824, guid: 0aa113ac73f3394448b77e6c4c712232, type: 3} - - {fileID: -7095097463981226713, guid: 0aa113ac73f3394448b77e6c4c712232, type: 3} - - {fileID: 8265045834036228682, guid: 0aa113ac73f3394448b77e6c4c712232, type: 3} + SpriteChanger: {fileID: 4165805474229086665} DebugExpelGun: 0 --- !u!50 &11699643827672084 Rigidbody2D: @@ -234,6 +230,27 @@ MonoBehaviour: BodypartMinCount: 4 BodypartMaxCount: 6 DebrisType: 1 +--- !u!114 &4165805474229086665 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 11699643827672081} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 963ee06ef5f5e0d4a841d0d4a16f0edc, type: 3} + m_Name: + m_EditorClassIdentifier: + Sprite: {fileID: 11699643643052996} + Sprites: + - {fileID: 2570391356933361261, guid: 0aa113ac73f3394448b77e6c4c712232, type: 3} + - {fileID: 881297774068237510, guid: 0aa113ac73f3394448b77e6c4c712232, type: 3} + - {fileID: 6754790859930108749, guid: 0aa113ac73f3394448b77e6c4c712232, type: 3} + - {fileID: -5872275606889041824, guid: 0aa113ac73f3394448b77e6c4c712232, type: 3} + - {fileID: -7095097463981226713, guid: 0aa113ac73f3394448b77e6c4c712232, type: 3} + - {fileID: 8265045834036228682, guid: 0aa113ac73f3394448b77e6c4c712232, type: 3} + InitialIdx: 5 --- !u!1 &11699643844798482 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Environment/VendingMachine.cs b/Assets/Scripts/Environment/GunDropper.cs similarity index 67% rename from Assets/Scripts/Environment/VendingMachine.cs rename to Assets/Scripts/Environment/GunDropper.cs index 237b8fa..43760de 100644 --- a/Assets/Scripts/Environment/VendingMachine.cs +++ b/Assets/Scripts/Environment/GunDropper.cs @@ -4,28 +4,33 @@ using UnityEngine; using UnityEngine.Animations; using Saltosion.OneWeapon.Guns; using Saltosion.OneWeapon.Utils; +using Saltosion.OneWeapon.Effects; namespace Saltosion.OneWeapon.Environment { - public class VendingMachine : MonoBehaviour { + [RequireComponent(typeof(Explodable))] + public class GunDropper : MonoBehaviour { [Header("General")] public float GunLaunchForceMultiplier = 1; public Transform HoleTransform; + public Explodable Explodable; + public bool ExplodeOnEmpty = false; [Header("Gunstuff")] public int GunsLeft = 3; public List PossibleGuns = new List(); - [Header("Graphics")] - public SpriteRenderer Sprite; - public List Sprites = new List(); + [Header("Graphics (optional)")] + public SpriteChanger SpriteChanger; [Header("Debug")] public bool DebugExpelGun = false; void Start() { - GunsLeft = Mathf.Clamp(GunsLeft, 0, 5); - Sprite.sprite = Sprites[GunsLeft]; + if (SpriteChanger != null) { + GunsLeft = Mathf.Clamp(GunsLeft, 0, SpriteChanger.Sprites.Count - 1); + SpriteChanger.SetSprite(GunsLeft); + } } void Update() { @@ -47,9 +52,15 @@ namespace Saltosion.OneWeapon.Environment { Body.AddForce(DownwardForce + SidewaysForce, ForceMode2D.Impulse); } GunsLeft -= 1; - Sprite.sprite = Sprites[GunsLeft]; + if (SpriteChanger != null) { + SpriteChanger.SetSprite(GunsLeft); + } if (GunsLeft == 0) { - Destroy(this); + if (ExplodeOnEmpty) { + Explodable.Explode(true); + } else { + Destroy(this); + } } } } diff --git a/Assets/Scripts/Environment/VendingMachine.cs.meta b/Assets/Scripts/Environment/GunDropper.cs.meta similarity index 100% rename from Assets/Scripts/Environment/VendingMachine.cs.meta rename to Assets/Scripts/Environment/GunDropper.cs.meta diff --git a/Assets/Scripts/Environment/SpriteChanger.cs b/Assets/Scripts/Environment/SpriteChanger.cs new file mode 100644 index 0000000..11c7624 --- /dev/null +++ b/Assets/Scripts/Environment/SpriteChanger.cs @@ -0,0 +1,27 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Saltosion.OneWeapon.Environment { + public class SpriteChanger : MonoBehaviour { + + public SpriteRenderer Sprite; + public List Sprites = new List(); + public int InitialIdx = 0; + + private int CurrentIdx = 0; + + void Start() { + CurrentIdx = Mathf.Clamp(InitialIdx, 0, Sprites.Count - 1); + } + + public bool SetSprite(int Index) { + if (Index < 0 || Index >= Sprites.Count) { + Debug.LogError("Cannot change sprite to an index that does not exist!"); + return false; + } + Sprite.sprite = Sprites[Index]; + return true; + } + } +} diff --git a/Assets/Scripts/Environment/SpriteChanger.cs.meta b/Assets/Scripts/Environment/SpriteChanger.cs.meta new file mode 100644 index 0000000..001e422 --- /dev/null +++ b/Assets/Scripts/Environment/SpriteChanger.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 963ee06ef5f5e0d4a841d0d4a16f0edc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Guns/Bullet.cs b/Assets/Scripts/Guns/Bullet.cs index 211ee78..f1f58bc 100644 --- a/Assets/Scripts/Guns/Bullet.cs +++ b/Assets/Scripts/Guns/Bullet.cs @@ -15,7 +15,7 @@ namespace Saltosion.OneWeapon.Guns { public void DoDamage(float Damage, float Intensity, Collider2D Collider, Vector2 Direction) { Explodable Explodable = Collider.GetComponent(); Health Health = Collider.GetComponent(); - VendingMachine VendingMachine = Collider.GetComponent(); + GunDropper VendingMachine = Collider.GetComponent(); if (Health != null) { Health.Damage(Damage, -Direction, true); } else if (VendingMachine != null) { diff --git a/Assets/Scripts/Player/PunchingHand.cs b/Assets/Scripts/Player/PunchingHand.cs index a3769b0..82ad182 100644 --- a/Assets/Scripts/Player/PunchingHand.cs +++ b/Assets/Scripts/Player/PunchingHand.cs @@ -20,7 +20,7 @@ namespace Saltosion.OneWeapon.Player { Explodable Explodable = collider.GetComponent(); Health Health = collider.GetComponent(); - VendingMachine VendingMachine = collider.GetComponent(); + GunDropper VendingMachine = collider.GetComponent(); Vector2 Direction = (collider.transform.position - transform.position).normalized; if (Health != null) { Health.Damage(8f, -Direction, true);