Skip to content

Commit

Permalink
bug fix #171 and code commenting
Browse files Browse the repository at this point in the history
  • Loading branch information
ClarkRM committed Apr 22, 2024
1 parent 6b5e5d0 commit a8a2656
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 58 deletions.
16 changes: 15 additions & 1 deletion Assets/Scripts/Dialogue/BannerDialogue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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)
Expand All @@ -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) {
Expand All @@ -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++) {
Expand All @@ -89,27 +96,34 @@ 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;
skipped = false;
}
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);
}
Expand Down
13 changes: 0 additions & 13 deletions Assets/Scripts/Dialogue/PopUpText.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/Scripts/Dialogue/PopUpText.cs.meta

This file was deleted.

2 changes: 1 addition & 1 deletion Assets/Scripts/Dialogue/StartDialogue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
19 changes: 17 additions & 2 deletions Assets/Scripts/Robbie Minigame/Attempt2/Wire2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion Assets/Scripts/Robbie Minigame/Attempt2/WireManager2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>();
Expand All @@ -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
Expand All @@ -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);
}
}
64 changes: 35 additions & 29 deletions Assets/Scripts/Robbie Minigame/Attempt2/WirePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Laser>() != null && !door.GetComponent<Laser>().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<TMP_Text>().text = "";
}
else
{
// alert player to interact
prompt.GetComponent<TMP_Text>().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<Laser>() != null && !door.GetComponent<Laser>().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)
Expand All @@ -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;
Expand Down

0 comments on commit a8a2656

Please sign in to comment.