diff --git a/Assets/Scenes/Default.unity b/Assets/Scenes/Default.unity index 341a4ce..36c1a4b 100644 --- a/Assets/Scenes/Default.unity +++ b/Assets/Scenes/Default.unity @@ -127,6 +127,26 @@ RectTransform: type: 3} m_PrefabInstance: {fileID: 903729141283580811} m_PrefabAsset: {fileID: 0} +--- !u!1 &625994393 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 1475586332177117423, guid: 83b3c042c2cf3ce4fafc6b3346509ad9, + type: 3} + m_PrefabInstance: {fileID: 1475586331571591191} + m_PrefabAsset: {fileID: 0} +--- !u!114 &625994397 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 625994393} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5083bec7e6907f844b7599d852b744c9, type: 3} + m_Name: + m_EditorClassIdentifier: + displayText: OVER + displayColor: {r: 1, g: 0, b: 0, a: 1} --- !u!1 &706082052 GameObject: m_ObjectHideFlags: 0 @@ -307,6 +327,45 @@ RectTransform: type: 3} m_PrefabInstance: {fileID: 3646290606250593900} m_PrefabAsset: {fileID: 0} +--- !u!1 &1939693950 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 1475586332062904173, guid: 83b3c042c2cf3ce4fafc6b3346509ad9, + type: 3} + m_PrefabInstance: {fileID: 1475586331571591191} + m_PrefabAsset: {fileID: 0} +--- !u!114 &1939693954 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1939693950} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5083bec7e6907f844b7599d852b744c9, type: 3} + m_Name: + m_EditorClassIdentifier: + displayText: GAME + displayColor: {r: 1, g: 0, b: 0, a: 1} +--- !u!1 &1959137559 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 3876737460387516449, guid: 83b3c042c2cf3ce4fafc6b3346509ad9, + type: 3} + m_PrefabInstance: {fileID: 1475586331571591191} + m_PrefabAsset: {fileID: 0} +--- !u!114 &1959137561 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1959137559} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 434b0b9680e8eb946ad858c56a075518, type: 3} + m_Name: + m_EditorClassIdentifier: + displayWhen: 2 --- !u!1001 &742014443134654871 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Main/GameController.cs b/Assets/Scripts/Main/GameController.cs index e0157ee..cc568bc 100644 --- a/Assets/Scripts/Main/GameController.cs +++ b/Assets/Scripts/Main/GameController.cs @@ -28,6 +28,11 @@ public class GameController : MonoBehaviour } } } + public bool GameOver { + get { + return Lives <= 0; + } + } [BeforeStart] public float startingTimescale = 1.0f; @@ -109,18 +114,21 @@ public class GameController : MonoBehaviour private void OnMicrogameEnd(MicrogameController microgame, bool victory) { Debug.Assert(microgame != null); - if(victory) { - Score += 1; - } - else { + if(!victory) { Lives -= 1; } + Score += 1; CurrentMicrogame = null; - Faster(); - StartCoroutine("SpinTheWheel"); + if(!GameOver) { + if(score % increaseSpeedEvery == 0) { + Faster(); + } + StartCoroutine("SpinTheWheel"); + } } public float timescaleIncreaseFactor = 0.05f; + public float increaseSpeedEvery = 5; private void Faster() { Timescale += timescaleIncreaseFactor; } diff --git a/Assets/Scripts/Microgame/MicrogameController.cs b/Assets/Scripts/Microgame/MicrogameController.cs index d6b806c..cfbf428 100644 --- a/Assets/Scripts/Microgame/MicrogameController.cs +++ b/Assets/Scripts/Microgame/MicrogameController.cs @@ -16,6 +16,9 @@ public abstract class MicrogameController : MonoBehaviour [BeforeStart] public Font microgameNameFont; + [Header("Microgame Results")] + public bool victory = true; + protected GameController gameController; public delegate void OnTimeLeftChangeHandler(float previous, float current); @@ -44,8 +47,6 @@ public abstract class MicrogameController : MonoBehaviour public delegate void OnMicrogameEndHandler(MicrogameController microgame, bool victory); public event OnMicrogameEndHandler OnMicrogameEnd; - protected abstract bool MicrogameResults(); - private void Awake() { gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent(); } @@ -56,7 +57,7 @@ public abstract class MicrogameController : MonoBehaviour } private void End() { - OnMicrogameEnd?.Invoke(this, MicrogameResults()); + OnMicrogameEnd?.Invoke(this, victory); } private void Update() { diff --git a/Assets/Scripts/Microgame/TestMicrogame.cs b/Assets/Scripts/Microgame/TestMicrogame.cs index ad4e3f3..59c2c9b 100644 --- a/Assets/Scripts/Microgame/TestMicrogame.cs +++ b/Assets/Scripts/Microgame/TestMicrogame.cs @@ -4,7 +4,4 @@ using UnityEngine; public class TestMicrogame : MicrogameController { - protected override bool MicrogameResults() { - return true; - } } diff --git a/Assets/Scripts/UI/DisplayOnGameOver.cs b/Assets/Scripts/UI/DisplayOnGameOver.cs new file mode 100644 index 0000000..5440722 --- /dev/null +++ b/Assets/Scripts/UI/DisplayOnGameOver.cs @@ -0,0 +1,35 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + + +public enum DisplayOnGameOverOptions { + ALWAYS, + SHOW_ON_GAME_OVER, + HIDE_ON_GAME_OVER, + NEVER +} + + +public class DisplayOnGameOver : MonoBehaviour +{ + public DisplayOnGameOverOptions displayWhen; + + private GameController gameController; + private Text text; + + private void Awake() { + gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent(); + text = GetComponent(); + } + + private void Start() { + gameController.OnGameOver += OnGameOver; + gameObject.SetActive(displayWhen == DisplayOnGameOverOptions.ALWAYS || displayWhen == DisplayOnGameOverOptions.HIDE_ON_GAME_OVER); + } + + private void OnGameOver(GameController sender) { + gameObject.SetActive(displayWhen == DisplayOnGameOverOptions.ALWAYS || displayWhen == DisplayOnGameOverOptions.SHOW_ON_GAME_OVER); + } +} diff --git a/Assets/Scripts/UI/DisplayOnGameOver.cs.meta b/Assets/Scripts/UI/DisplayOnGameOver.cs.meta new file mode 100644 index 0000000..fe17cd0 --- /dev/null +++ b/Assets/Scripts/UI/DisplayOnGameOver.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 434b0b9680e8eb946ad858c56a075518 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/TextOnGameOver.cs b/Assets/Scripts/UI/TextOnGameOver.cs new file mode 100644 index 0000000..c04aa1c --- /dev/null +++ b/Assets/Scripts/UI/TextOnGameOver.cs @@ -0,0 +1,28 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +[RequireComponent(typeof(Text))] +public class TextOnGameOver : MonoBehaviour +{ + public string displayText; + public Color displayColor; + + private GameController gameController; + private Text text; + + private void Awake() { + gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent(); + text = GetComponent(); + } + + private void Start() { + gameController.OnGameOver += OnGameOver; + } + + private void OnGameOver(GameController sender) { + text.text = displayText; + text.color = displayColor; + } +} diff --git a/Assets/Scripts/UI/TextOnGameOver.cs.meta b/Assets/Scripts/UI/TextOnGameOver.cs.meta new file mode 100644 index 0000000..0f471ac --- /dev/null +++ b/Assets/Scripts/UI/TextOnGameOver.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5083bec7e6907f844b7599d852b744c9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: