From 8b6b2649ebe009f2a485bb8334e938da17e54890 Mon Sep 17 00:00:00 2001 From: Ivy Date: Wed, 14 Apr 2021 21:13:00 -0500 Subject: [PATCH] Added glider powerup --- .../Animations/Protagonist Run Cycle.anim | 2 +- .../Protagonist Run Cycle.controller | 2 +- MuseumGame/Assets/Prefabs/Player.prefab | 15 ++++ .../Assets/Scenes/DemoLevels/PathToBoss.unity | 80 ++++++++++++++++--- .../Assets/Scenes/DemoLevels/Spawn.unity | 4 +- .../Scenes/DemoLevels/Spike Scene.unity | 66 +++++++++++++++ MuseumGame/Assets/Scripts/GameManager.cs | 35 +++++++- MuseumGame/Assets/Scripts/Glider.cs | 45 +++++++++++ MuseumGame/Assets/Scripts/Glider.cs.meta | 11 +++ .../Assets/Scripts/GliderPowerupPickup.cs | 26 ++++++ .../Scripts/GliderPowerupPickup.cs.meta | 11 +++ MuseumGame/Assets/Scripts/Powerup.cs | 5 ++ MuseumGame/Assets/Scripts/Powerup.cs.meta | 11 +++ .../UserSettings/EditorUserSettings.asset | 10 +-- 14 files changed, 303 insertions(+), 20 deletions(-) create mode 100644 MuseumGame/Assets/Scripts/Glider.cs create mode 100644 MuseumGame/Assets/Scripts/Glider.cs.meta create mode 100644 MuseumGame/Assets/Scripts/GliderPowerupPickup.cs create mode 100644 MuseumGame/Assets/Scripts/GliderPowerupPickup.cs.meta create mode 100644 MuseumGame/Assets/Scripts/Powerup.cs create mode 100644 MuseumGame/Assets/Scripts/Powerup.cs.meta diff --git a/MuseumGame/Assets/Animations/Protagonist Run Cycle.anim b/MuseumGame/Assets/Animations/Protagonist Run Cycle.anim index 5c446e0..dc067cc 100644 --- a/MuseumGame/Assets/Animations/Protagonist Run Cycle.anim +++ b/MuseumGame/Assets/Animations/Protagonist Run Cycle.anim @@ -6,7 +6,7 @@ AnimationClip: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: Protagonist + m_Name: Protagonist Run Cycle serializedVersion: 6 m_Legacy: 0 m_Compressed: 0 diff --git a/MuseumGame/Assets/Animations/Protagonist Run Cycle.controller b/MuseumGame/Assets/Animations/Protagonist Run Cycle.controller index 2e1c392..df59b56 100644 --- a/MuseumGame/Assets/Animations/Protagonist Run Cycle.controller +++ b/MuseumGame/Assets/Animations/Protagonist Run Cycle.controller @@ -28,7 +28,7 @@ AnimatorController: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: Protagonist Run Cycle_0 + m_Name: Protagonist Run Cycle serializedVersion: 5 m_AnimatorParameters: [] m_AnimatorLayers: diff --git a/MuseumGame/Assets/Prefabs/Player.prefab b/MuseumGame/Assets/Prefabs/Player.prefab index e58e75e..8b63481 100644 --- a/MuseumGame/Assets/Prefabs/Player.prefab +++ b/MuseumGame/Assets/Prefabs/Player.prefab @@ -15,6 +15,7 @@ GameObject: - component: {fileID: 3275569032751403274} - component: {fileID: 4572441351392969366} - component: {fileID: 4796302867346557188} + - component: {fileID: 971613887410275354} m_Layer: 0 m_Name: Player m_TagString: Player @@ -178,3 +179,17 @@ Animator: m_HasTransformHierarchy: 1 m_AllowConstantClipSamplingOptimization: 1 m_KeepAnimatorControllerStateOnDisable: 0 +--- !u!114 &971613887410275354 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 374150667840124763} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 93764b8ff5a5045da89d2ddfc1195c97, type: 3} + m_Name: + m_EditorClassIdentifier: + m_FallSpeed: 0.7 + IsGliding: 0 diff --git a/MuseumGame/Assets/Scenes/DemoLevels/PathToBoss.unity b/MuseumGame/Assets/Scenes/DemoLevels/PathToBoss.unity index 09eb339..dfb7f31 100644 --- a/MuseumGame/Assets/Scenes/DemoLevels/PathToBoss.unity +++ b/MuseumGame/Assets/Scenes/DemoLevels/PathToBoss.unity @@ -332,6 +332,22 @@ CompositeCollider2D: Y: 0 - X: -40000000 Y: 0 + - - X: 170000100 + Y: -40000041 + - X: 170000100 + Y: -19999959 + - X: 170000041 + Y: -19999900 + - X: 149999959 + Y: -19999900 + - X: 149999900 + Y: -19999959 + - X: 149999900 + Y: -40000041 + - X: 149999959 + Y: -40000100 + - X: 170000041 + Y: -40000100 - - X: 70000100 Y: -130000041 - X: 70000100 @@ -454,6 +470,10 @@ CompositeCollider2D: - {x: 42.999973, y: 13} - {x: -6.00001, y: 12.999974} - {x: -5.999971, y: 0.00001} + - - {x: 16.999975, y: -4.00001} + - {x: 16.999975, y: -1.99999} + - {x: 14.99999, y: -2.0000253} + - {x: 15.000026, y: -4.00001} - - {x: 6.9999743, y: -13.00001} - {x: 7.000039, y: -12} - {x: 44, y: -11.99997} @@ -3692,6 +3712,26 @@ Tilemap: m_TileObjectToInstantiateIndex: 65535 dummyAlignment: 0 m_AllTileFlags: 1073741825 + - first: {x: 15, y: -4, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 4 + m_TileSpriteIndex: 4 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: 16, y: -4, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 3 + m_TileSpriteIndex: 3 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 - first: {x: 34, y: -4, z: 0} second: serializedVersion: 2 @@ -3922,6 +3962,26 @@ Tilemap: m_TileObjectToInstantiateIndex: 65535 dummyAlignment: 0 m_AllTileFlags: 1073741825 + - first: {x: 15, y: -3, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 2 + m_TileSpriteIndex: 2 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: 16, y: -3, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 1 + m_TileSpriteIndex: 1 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 - first: {x: 25, y: -3, z: 0} second: serializedVersion: 2 @@ -7966,13 +8026,13 @@ Tilemap: m_TileAssetArray: - m_RefCount: 4 m_Data: {fileID: 11400000, guid: a75fae817255147dfb5af80c89349553, type: 2} - - m_RefCount: 3 + - m_RefCount: 4 m_Data: {fileID: 11400000, guid: 06e92d3a7a0654704bc339efcb7aa6aa, type: 2} - - m_RefCount: 3 + - m_RefCount: 4 m_Data: {fileID: 11400000, guid: c5c8363f80db64a66a5a8eff42e70a32, type: 2} - - m_RefCount: 3 + - m_RefCount: 4 m_Data: {fileID: 11400000, guid: d6ba3f6ba8f5640a9874b2ccc62a69c2, type: 2} - - m_RefCount: 3 + - m_RefCount: 4 m_Data: {fileID: 11400000, guid: cdabe21a28af4458785296fb55cb3c69, type: 2} - m_RefCount: 11 m_Data: {fileID: 11400000, guid: a9e61ac9b92cc4d7ca4efb63365c4ffe, type: 2} @@ -8001,13 +8061,13 @@ Tilemap: m_TileSpriteArray: - m_RefCount: 4 m_Data: {fileID: -8806091605853736217, guid: 33f7d659c72ba459ba2a9485c9501630, type: 3} - - m_RefCount: 3 + - m_RefCount: 4 m_Data: {fileID: -873322832810516204, guid: 33f7d659c72ba459ba2a9485c9501630, type: 3} - - m_RefCount: 3 + - m_RefCount: 4 m_Data: {fileID: 3433671182191017847, guid: 33f7d659c72ba459ba2a9485c9501630, type: 3} - - m_RefCount: 3 + - m_RefCount: 4 m_Data: {fileID: -5521210291312998094, guid: 33f7d659c72ba459ba2a9485c9501630, type: 3} - - m_RefCount: 3 + - m_RefCount: 4 m_Data: {fileID: -4930461731810238109, guid: 33f7d659c72ba459ba2a9485c9501630, type: 3} - m_RefCount: 11 m_Data: {fileID: 8984585068276349725, guid: 33f7d659c72ba459ba2a9485c9501630, type: 3} @@ -8034,7 +8094,7 @@ Tilemap: - m_RefCount: 10 m_Data: {fileID: 4798128000316562087, guid: 33f7d659c72ba459ba2a9485c9501630, type: 3} m_TileMatrixArray: - - m_RefCount: 740 + - m_RefCount: 744 m_Data: e00: 1 e01: 0 @@ -8053,7 +8113,7 @@ Tilemap: e32: 0 e33: 1 m_TileColorArray: - - m_RefCount: 740 + - m_RefCount: 744 m_Data: {r: 1, g: 1, b: 1, a: 1} m_TileObjectToInstantiateArray: [] m_AnimationFrameRate: 1 diff --git a/MuseumGame/Assets/Scenes/DemoLevels/Spawn.unity b/MuseumGame/Assets/Scenes/DemoLevels/Spawn.unity index 8c56161..47cb625 100644 --- a/MuseumGame/Assets/Scenes/DemoLevels/Spawn.unity +++ b/MuseumGame/Assets/Scenes/DemoLevels/Spawn.unity @@ -1978,7 +1978,9 @@ MonoBehaviour: spriteToFade: {fileID: 874186942} events: {fileID: 1051066022} player: {fileID: 1370635947} - sceneToLoad: + obtainedPowerups: + powerupStatus: + sceneToLoad: Spike Scene --- !u!4 &637676178 Transform: m_ObjectHideFlags: 0 diff --git a/MuseumGame/Assets/Scenes/DemoLevels/Spike Scene.unity b/MuseumGame/Assets/Scenes/DemoLevels/Spike Scene.unity index f56972e..b08a948 100644 --- a/MuseumGame/Assets/Scenes/DemoLevels/Spike Scene.unity +++ b/MuseumGame/Assets/Scenes/DemoLevels/Spike Scene.unity @@ -2375,6 +2375,8 @@ GameObject: m_Component: - component: {fileID: 219367236} - component: {fileID: 219367235} + - component: {fileID: 219367237} + - component: {fileID: 219367238} m_Layer: 0 m_Name: Powerup placeholder m_TagString: Untagged @@ -2447,6 +2449,70 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &219367237 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 219367234} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3405314fa73da438982268d433fbbc2f, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!60 &219367238 +PolygonCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 219367234} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_UsedByComposite: 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.8828125, y: 1} + newSize: {x: 0.8828125, y: 1} + adaptiveTilingThreshold: 0.5 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + m_Points: + m_Paths: + - - {x: 0.4375, y: -0.265625} + - {x: 0.44140625, y: -0.2578125} + - {x: 0.44140625, y: 0.2578125} + - {x: 0.4375, y: 0.265625} + - {x: 0.390625, y: 0.29296875} + - {x: 0.36328125, y: 0.30859375} + - {x: 0.26171875, y: 0.3671875} + - {x: 0.21484375, y: 0.39453125} + - {x: 0.16015625, y: 0.42578125} + - {x: 0.05859375, y: 0.484375} + - {x: 0.02734375, y: 0.5} + - {x: -0.03125, y: 0.5} + - {x: -0.05859375, y: 0.484375} + - {x: -0.1875, y: 0.41015625} + - {x: -0.36328125, y: 0.30859375} + - {x: -0.4375, y: 0.265625} + - {x: -0.44140625, y: 0.2578125} + - {x: -0.44140625, y: -0.2578125} + - {x: -0.4375, y: -0.265625} + - {x: -0.31640625, y: -0.3359375} + - {x: -0.26171875, y: -0.3671875} + - {x: -0.21484375, y: -0.39453125} + - {x: -0.11328125, y: -0.453125} + - {x: -0.03125, y: -0.5} + - {x: 0.03125, y: -0.5} + - {x: 0.0859375, y: -0.46875} + - {x: 0.2421875, y: -0.37890625} --- !u!1 &563510750 GameObject: m_ObjectHideFlags: 0 diff --git a/MuseumGame/Assets/Scripts/GameManager.cs b/MuseumGame/Assets/Scripts/GameManager.cs index 5716b59..4e584ee 100644 --- a/MuseumGame/Assets/Scripts/GameManager.cs +++ b/MuseumGame/Assets/Scripts/GameManager.cs @@ -1,5 +1,9 @@ +using System; using System.Collections; +using System.Collections.Generic; +using System.Linq; using UnityEngine; +using UnityEngine.Assertions.Must; using UnityEngine.SceneManagement; using UnityEngine.UI; @@ -12,6 +16,9 @@ public class GameManager : MonoBehaviour public GameObject events; public GameObject player; + public List obtainedPowerups = new List{ }; + public List powerupStatus = new List{ }; + public string sceneToLoad = ""; void Awake() @@ -38,14 +45,14 @@ public class GameManager : MonoBehaviour { if (sceneToLoad != "") { - LoadLevel(sceneToLoad, new Vector3(0,0,0)); + LoadLevel(sceneToLoad, new Vector3(0, 0, 0)); } } // Update is called once per frame void Update() { - + doGliderButtonCheck(); } public void LoadLevel(string levelName, Vector3 whereTo) @@ -84,5 +91,29 @@ public class GameManager : MonoBehaviour spriteToFade.SetActive(false); } + private void doGliderButtonCheck() + { + if (obtainedPowerups.Contains(Powerup.Glider)) + { + if (Input.GetKeyDown("1")) + { + var index = Array.IndexOf(obtainedPowerups.ToArray(), Powerup.Glider); + var status = powerupStatus[index]; + if (!status) + { + player.GetComponent().IsGliding = true; + powerupStatus[index] = true; + } + else + { + player.GetComponent().IsGliding = false; + powerupStatus[index] = false; + } + } + } + } } +// } +//} +//} diff --git a/MuseumGame/Assets/Scripts/Glider.cs b/MuseumGame/Assets/Scripts/Glider.cs new file mode 100644 index 0000000..be62fce --- /dev/null +++ b/MuseumGame/Assets/Scripts/Glider.cs @@ -0,0 +1,45 @@ +using UnityEngine; +//http://answers.unity.com/answers/1778449/view.html +public class Glider : MonoBehaviour +{ + /// + /// The speed when falling + /// + [SerializeField] + private float m_FallSpeed = 0f; + + /// + /// + /// + private Rigidbody2D m_Rigidbody2D = null; + + // Awake is called before Start function + void Awake() + { + m_Rigidbody2D = GetComponent(); + } + + // Update is called once per frame + void Update() + { + if (IsGliding && m_Rigidbody2D.velocity.y < 0f && Mathf.Abs(m_Rigidbody2D.velocity.y) > m_FallSpeed) + m_Rigidbody2D.velocity = new Vector2(m_Rigidbody2D.velocity.x, Mathf.Sign(m_Rigidbody2D.velocity.y) * m_FallSpeed); + } + + public void StartGliding() + { + IsGliding = true; + } + + public void StopGliding() + { + IsGliding = false; + } + + /// + /// Flag to check if gliding + /// + /// + public bool IsGliding { get; set; } = false; + +} \ No newline at end of file diff --git a/MuseumGame/Assets/Scripts/Glider.cs.meta b/MuseumGame/Assets/Scripts/Glider.cs.meta new file mode 100644 index 0000000..54e7874 --- /dev/null +++ b/MuseumGame/Assets/Scripts/Glider.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 93764b8ff5a5045da89d2ddfc1195c97 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MuseumGame/Assets/Scripts/GliderPowerupPickup.cs b/MuseumGame/Assets/Scripts/GliderPowerupPickup.cs new file mode 100644 index 0000000..0af27de --- /dev/null +++ b/MuseumGame/Assets/Scripts/GliderPowerupPickup.cs @@ -0,0 +1,26 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class GliderPowerupPickup : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + + private void OnTriggerEnter2D(Collider2D collision) + { + Debug.Log("Test"); + GameManager.Instance.obtainedPowerups.Add(Powerup.Glider); + GameManager.Instance.powerupStatus.Add(false); + Destroy(gameObject); + } +} diff --git a/MuseumGame/Assets/Scripts/GliderPowerupPickup.cs.meta b/MuseumGame/Assets/Scripts/GliderPowerupPickup.cs.meta new file mode 100644 index 0000000..1c6b352 --- /dev/null +++ b/MuseumGame/Assets/Scripts/GliderPowerupPickup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3405314fa73da438982268d433fbbc2f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MuseumGame/Assets/Scripts/Powerup.cs b/MuseumGame/Assets/Scripts/Powerup.cs new file mode 100644 index 0000000..53be126 --- /dev/null +++ b/MuseumGame/Assets/Scripts/Powerup.cs @@ -0,0 +1,5 @@ +using System; +public enum Powerup +{ + Glider +} \ No newline at end of file diff --git a/MuseumGame/Assets/Scripts/Powerup.cs.meta b/MuseumGame/Assets/Scripts/Powerup.cs.meta new file mode 100644 index 0000000..8452c37 --- /dev/null +++ b/MuseumGame/Assets/Scripts/Powerup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9af10219a8237432585dcf45948fe641 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MuseumGame/UserSettings/EditorUserSettings.asset b/MuseumGame/UserSettings/EditorUserSettings.asset index 3c0c7a6..a3f3e85 100644 --- a/MuseumGame/UserSettings/EditorUserSettings.asset +++ b/MuseumGame/UserSettings/EditorUserSettings.asset @@ -15,22 +15,22 @@ EditorUserSettings: value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d flags: 0 RecentlyUsedScenePath-3: - value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621a0d3ae9e5740be1e238eca92f31352d1b + value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621d1224e7f27a2decee22f0 flags: 0 RecentlyUsedScenePath-4: - value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621d1224e7f27a2decee22f0 + value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23620b1132eceb7414e7f133e5a92f31352d1b flags: 0 RecentlyUsedScenePath-5: - value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23620b1132eceb7414e7f133e5a92f31352d1b + value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23620c1336eff9002dece933e5a92f31352d1b flags: 0 RecentlyUsedScenePath-6: - value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23620c1336eff9002dece933e5a92f31352d1b + value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621b1226f6e50037d6e821ecf5742a323016f6 flags: 0 RecentlyUsedScenePath-7: value: 22424703114646680e0b0227036c7b151b18342f3a2d2a2362191c27ead43b1aedf425a7f234362820 flags: 0 RecentlyUsedScenePath-8: - value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621b1226f6e50037d6e821ecf5742a323016f6 + value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621a0d3ae9e5740be1e238eca92f31352d1b flags: 0 RecentlyUsedScenePath-9: value: 22424703114646680e0b0227036c7b151b18342f3a2d2a23621a0d32f5ee7a2decee22f0