diff --git a/Assets/Scripts/Dialogue/BannerDialogue.cs b/Assets/Scripts/Dialogue/BannerDialogue.cs index 8e74727..e2a5c7d 100644 --- a/Assets/Scripts/Dialogue/BannerDialogue.cs +++ b/Assets/Scripts/Dialogue/BannerDialogue.cs @@ -7,7 +7,7 @@ public class BannerDialogue : MonoBehaviour { - // TODO : stop player from moving when text is active. TODO IS DONE + [SerializeField] AudioSource walk; public Rigidbody2D rb; public Animator animator; @@ -30,15 +30,18 @@ public class BannerDialogue : MonoBehaviour private void Start() { + // stop moving platforms during dialogue movingPlatforms = (MovingPlatform[]) FindObjectsOfType(typeof(MovingPlatform)); platformSpeeds = new float[movingPlatforms.Length]; for (int i = 0; i < movingPlatforms.Length; i++) { platformSpeeds[i] = movingPlatforms[i]._speed; } + // if dialogue has previously shown, do not display it again if (hasShown) { textBox.SetActive(false); } + // stop player movement and animations during dialogue else { PopulateText(); @@ -49,6 +52,8 @@ private void Start() } } + // listen for player to advance the dialogue + // if dialogue is still scrolling, skip to the end. If it is not scrolling, populate next line private void Update() { if(Input.GetKeyDown(advance) && !isShowing) @@ -63,6 +68,7 @@ private void Update() private void PopulateText() { + // populate the text with the appropriate line of text and icon with the correlated icon if(i <= text.Length - 1) { foreach(MovingPlatform movingPlatform in movingPlatforms) { @@ -75,6 +81,7 @@ private void PopulateText() display.text = text[i]; StartCoroutine(WriteText()); } + // if no more lines of text, then disable the text box and reinable the moving platforms else { for (int i = 0; i < movingPlatforms.Length; i++) { @@ -89,14 +96,19 @@ private void PopulateText() IEnumerator WriteText() { + // setup for scrolling text isShowing = true; display.ForceMeshUpdate(); int totalVisibleChars = display.textInfo.characterCount; int counter = 0; + // loop that runs while the characters are slowly being made visible while(true) { + // inc number of visible characters int visible = counter % (totalVisibleChars + 1); + + // if player skips dialogue, display the entire line at once if (skipped) { visible = totalVisibleChars; @@ -104,12 +116,14 @@ IEnumerator WriteText() } display.maxVisibleCharacters = visible; + // if all characters are visible, break out of loop and iterate to next line of text if (visible >= totalVisibleChars) { i++; isShowing = false; break; } + // update the counter and wait short time till iterating through loop again counter++; yield return new WaitForSeconds(timeBetweenChars); } diff --git a/Assets/Scripts/Dialogue/PopUpText.cs b/Assets/Scripts/Dialogue/PopUpText.cs deleted file mode 100644 index 0ef68b9..0000000 --- a/Assets/Scripts/Dialogue/PopUpText.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class PopUpText : MonoBehaviour -{ - /* TODO - * - Reference in-game pop up text bubble - * - Add randomizer - * - Create switch statement of different dialogue options for player getting hurt - * - Add TTL to pop up - */ -} diff --git a/Assets/Scripts/Dialogue/PopUpText.cs.meta b/Assets/Scripts/Dialogue/PopUpText.cs.meta deleted file mode 100644 index 09923c5..0000000 --- a/Assets/Scripts/Dialogue/PopUpText.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a0e4b586c6fb31c42b51e9d7c1fdc1d6 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Dialogue/StartDialogue.cs b/Assets/Scripts/Dialogue/StartDialogue.cs index 6f8e0bd..3d56c31 100644 --- a/Assets/Scripts/Dialogue/StartDialogue.cs +++ b/Assets/Scripts/Dialogue/StartDialogue.cs @@ -6,7 +6,7 @@ public class StartDialogue : MonoBehaviour { [SerializeField] GameObject dialogueBox; - + // on player entering a trigger box, enable dialogue and disable trigger to avoid retriggering the dialogue private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.CompareTag("Player")) { diff --git a/Assets/Scripts/Robbie Minigame/Attempt2/Wire2.cs b/Assets/Scripts/Robbie Minigame/Attempt2/Wire2.cs index 2daa6ea..cd4908a 100644 --- a/Assets/Scripts/Robbie Minigame/Attempt2/Wire2.cs +++ b/Assets/Scripts/Robbie Minigame/Attempt2/Wire2.cs @@ -10,17 +10,27 @@ public class Wire2 : MonoBehaviour Vector3 startPos; Vector3 wireStartPos; + // log the start position of the wire and parent object void Start() { startPos = transform.parent.position; wireStartPos = transform.position; } + // if the object gets disabled, snap wire to start postion + private void OnDisable() + { + OnMouseUp(); + } + + // handler for dragging wire private void OnMouseDrag() { + // vector to hold mouse position Vector3 newPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); newPos.z = 0; + // check all overlapping colliders for matching wire that is not itself Collider2D[] colliders = Physics2D.OverlapCircleAll(newPos, 0.2f); foreach (Collider2D collider in colliders) { @@ -40,11 +50,12 @@ private void OnMouseDrag() } } + // use the mouse position to update the wire's position UpdateWire(newPos); } - + // when the mouse is released, snap the wire back to start position private void OnMouseUp() { if (wireEnabled) @@ -54,18 +65,22 @@ private void OnMouseUp() } } - + // update the wire's position, rotation, and scale private void UpdateWire(Vector3 newPos) { + // change position transform.position = newPos; + // change rotation relative to the parent object Vector3 dir = newPos - startPos; transform.right = dir * transform.lossyScale.x; + // change scale based on distance float dist = Vector2.Distance(startPos, newPos); sr.size = new Vector2(dist, sr.size.y); } + // if the wire connects to it's matching wire, update the puzzle manager and distroy it's functionality void MatchWire() { if (wireEnabled) diff --git a/Assets/Scripts/Robbie Minigame/Attempt2/WireManager2.cs b/Assets/Scripts/Robbie Minigame/Attempt2/WireManager2.cs index 286db0d..4b13fe2 100644 --- a/Assets/Scripts/Robbie Minigame/Attempt2/WireManager2.cs +++ b/Assets/Scripts/Robbie Minigame/Attempt2/WireManager2.cs @@ -11,6 +11,8 @@ public class WireManager2 : MonoBehaviour [SerializeField] GameObject GO; [SerializeField] GameObject Panel; public Animator wireAnimator; + + // connections list will hold the number of successful wire connections private void Start() { connections = new List(); @@ -19,6 +21,7 @@ private void Start() void Update() { + // if there are as many connections as wires, then update the door/laser and disable the puzzle panel if(connections.Count == numWires) { // check of object is a laser @@ -38,9 +41,9 @@ void Update() } } + // called by the wire, adds entries to the list of successful connections public void SuccessfulConnection() { connections.Add(true); - Debug.Log(connections.Count); } } diff --git a/Assets/Scripts/Robbie Minigame/Attempt2/WirePanel.cs b/Assets/Scripts/Robbie Minigame/Attempt2/WirePanel.cs index 207b346..a1e7166 100644 --- a/Assets/Scripts/Robbie Minigame/Attempt2/WirePanel.cs +++ b/Assets/Scripts/Robbie Minigame/Attempt2/WirePanel.cs @@ -16,45 +16,50 @@ public class WirePanel : MonoBehaviour void Update() { - if (door.activeInHierarchy) - { - if (inRange && Input.GetKeyDown(KeyCode.E)) - { - inPanel = !inPanel; - prompt.SetActive(false); - if(inPanel) - { - // sr.enabled = false; - panel.SetActive(true); - } - } - } - else if (door.GetComponent() != null && !door.GetComponent().enabled) - { - prompt.SetActive(false); - // sr.enabled = true; - } - else - { - prompt.SetActive(false); - // sr.enabled = true; - } - - if(wireManager.connections.Count == 4) - { - hasCompleted = true; - } - + // if the puzzle is complete, remove text and do not allow the wire panel to open if(hasCompleted) { prompt.GetComponent().text = ""; } else { + // alert player to interact prompt.GetComponent().text = "Press [E] to access Wires"; + + // if the puzzle is not complete and the player is in range, pressing e disables the prompt and activates the puzzle + if (door.activeInHierarchy) + { + if (inRange && Input.GetKeyDown(KeyCode.E)) + { + inPanel = !inPanel; + prompt.SetActive(false); + if (inPanel) + { + // sr.enabled = false; + panel.SetActive(true); + } + } + } + // prompt disabling if the "door" is a laser + else if (door.GetComponent() != null && !door.GetComponent().enabled) + { + prompt.SetActive(false); + // sr.enabled = true; + } + else + { + prompt.SetActive(false); + // sr.enabled = true; + } + // if the wire manager has 4 connections, update the puzzle as completed + if (wireManager.connections.Count == 4) + { + hasCompleted = true; + } } } + // if the player enters the trigger area and the puzzle isn't complete, activate the prompt and tell update that player is in range private void OnTriggerEnter2D(Collider2D collision) { if (!hasCompleted) @@ -64,6 +69,7 @@ private void OnTriggerEnter2D(Collider2D collision) } } + // if the player exits the trigger area, disable the prompt/panel and tell update player is not in range private void OnTriggerExit2D(Collider2D collision) { inRange = false;