private void ConfigureFirstStep() { CurrentStepObject = Instantiate(LevelSteps[0]); CurrentStep = CurrentStepObject.GetComponent <AddressingStep>(); CurrentStepObject.transform.parent = this.transform; PlaceInBox(CurrentStepObject); IncorrectCircles = LoadGrayNotes(CurrentStepObject, CurrentStep, out CorrectCircle); firstNoteHeight = CurrentStep.FirstNoteCollider.bounds.center.y; //if (((levelNumber == 3) || (levelNumber == 4)) || // ((levelNumber == 5 || levelNumber == 6) && (Random.value < 0.5f))) //{ // SuperdogText.text = "Swing to the note " + // GetDifferential(CurrentStep.StartNote, CurrentStep.Notes[CurrentStep.CorrectIndex]) + // " the note you're hanging from!"; //} //else //{ // SuperdogText.text = "Swing to the " + CurrentStep.Notes[CurrentStep.CorrectIndex] + "!"; //} if (!IsFirstLevel && LevelSelection.IsAutoplaying()) { CorrectCircleClicked(CorrectCircle); } }
public void InitializeVineLength(AddressingStep CurrentStep) { Vector2 handPos = Supergirl.GetComponent <CircleCollider2D>().bounds.center; Vector2 notePos = CurrentStep.FirstNoteCollider.bounds.center; vineLength = Vector3.Magnitude(handPos - notePos); }
private void UpdateHangingVine(AddressingStep step) { Vector3 handPos = Supergirl.GetComponent <CircleCollider2D>().bounds.center; Vector3 notePos = step.FirstNoteCollider.bounds.center; PlaceVineBetween(Vine, handPos + 0.5f * Vector3.back, notePos + 0.5f * Vector3.back); float deltaX = notePos.x - handPos.x; float deltaY = notePos.y - handPos.y; float mag2 = Vector2.SqrMagnitude(notePos - handPos); sgVelocity += sgGrav * (new Vector3(deltaX * deltaY, -deltaX * deltaX) / mag2); Vector3 direction = Vector3.Normalize(new Vector3(-deltaY, deltaX, 0f)); sgVelocity = direction * Vector3.Dot(direction, sgVelocity); sgVelocity *= sgFriction; Supergirl.transform.position += sgVelocity; handPos = Supergirl.GetComponent <CircleCollider2D>().bounds.center; Vector3 delta = notePos + Mathf.Sqrt(mag2) * (handPos - notePos).normalized - handPos; Supergirl.transform.position += delta; }
public void ShowHint(AddressingStep step) { if (step.Notes[step.CorrectIndex].Contains("Space")) { spaceHint.SetActive(true); } else if (step.Notes[step.CorrectIndex].Contains("Line")) { lineHint.SetActive(true); } else { Debug.Log("neither space nor line tf"); } }
private IEnumerator ConfigureFirstStep() { CurrentStepObject = Instantiate(LevelSteps[0]); CurrentStep = CurrentStepObject.GetComponent <AddressingStep>(); CurrentStepObject.transform.parent = this.transform; PlaceInBox(CurrentStepObject); IncorrectCircles = LoadGrayNotes(CurrentStepObject, CurrentStep, out CorrectCircle); firstNoteHeight = CurrentStep.FirstNoteCollider.bounds.center.y; SuperdogText.text = "Swing to the " + CurrentStep.Notes[CurrentStep.CorrectIndex] + "!"; yield return(Transition.FadeIn(SuperdogText.gameObject, tutorialFadeTime, false)); if (!IsFirstLevel && LevelSelection.IsAutoplaying()) { CorrectCircleClicked(CorrectCircle); } }
public void NormalizeVineLength(AddressingStep CurrentStep, float sgSpring, float firstNoteHeight) { Vector2 handPos = Supergirl.GetComponent <CircleCollider2D>().bounds.center; Vector2 notePos = new Vector2(); if (CurrentStep != null) { notePos = CurrentStep.FirstNoteCollider.bounds.center; } float vineGoal = vineLength + (notePos.y - firstNoteHeight); Vector2 desiredPos = notePos + vineGoal * (handPos - notePos).normalized; Vector3 delta = desiredPos - handPos; if (delta.magnitude > sgSpring) { delta *= (sgSpring / delta.magnitude); } Supergirl.transform.position += delta; }
private GameObject[] LoadGrayNotes(GameObject stepObj, AddressingStep step, out GrayCircle correct) { Bounds bounds = step.NotesBox.bounds; float yMin = bounds.center.y - bounds.extents.y; float yMax = bounds.center.y + bounds.extents.y; float xMin = bounds.center.x - bounds.extents.x; float xMax = bounds.center.x + bounds.extents.x; correct = null; GameObject[] circles = new GameObject[step.Notes.Length - 1]; int j = 0; for (int i = 0; i < step.Notes.Length; i++) { Vector3 position = new Vector3(xMin + (xMax - xMin) * (((float)i) / step.Notes.Length), yMin + (yMax - yMin) * GetYByAddress(step.Notes[i]), -2); GameObject gray = (GameObject)Instantiate(GrayCirclePrefab, position, Quaternion.identity); gray.name = step.Notes[i]; gray.transform.parent = stepObj.transform; gray.name = step.Notes[i]; GrayCircle circ = gray.GetComponent <GrayCircle>(); bool isCorrect = (i == step.CorrectIndex); if (isCorrect) { circ.IsCorrect = true; correct = circ; } else { circ.IsCorrect = false; circles[j++] = gray; } circ.controller = this; } return(circles); }
public void UpdateHangingVine(AddressingStep step) { Vector3 handPos = Supergirl.GetComponent <CircleCollider2D>().bounds.center; Vector3 notePos = new Vector3(); if (step != null) { notePos = step.FirstNoteCollider.bounds.center; } PlaceVineBetween(gameObject, handPos + 0.1f * Vector3.forward, notePos + 0.1f * Vector3.forward); float deltaX = notePos.x - handPos.x; float deltaY = notePos.y - handPos.y; float mag2 = Vector2.SqrMagnitude(notePos - handPos); sgVelocity += addressingController.sgGrav * (new Vector3(deltaX * deltaY, -deltaX * deltaX) / mag2); Vector3 direction = Vector3.Normalize(new Vector3(-deltaY, deltaX, 0f)); sgVelocity = direction * Vector3.Dot(direction, sgVelocity); sgVelocity *= addressingController.sgFriction; Supergirl.transform.position += sgVelocity; handPos = Supergirl.GetComponent <CircleCollider2D>().bounds.center; // set z values equal to each other to avoid a change in z --> keep all z vals constant // solves problem of supergirl z pos inching backward on every update() call notePos.z = handPos.z; Vector3 delta = notePos + Mathf.Sqrt(mag2) * (handPos - notePos).normalized - handPos; Supergirl.transform.position += delta; }
private IEnumerator LoadNextStep(GrayCircle circ) { Debug.Log("loading next step" + " and transitionbackgrounds is " + TransitioningBackgrounds); hintController.HideHint(); HintDisplayed = false; bool isLastLevel; GameObject[] nextIncorrect; AddressingStep OldStep = CurrentStep; GameObject OldStepObject = CurrentStepObject; GameObject NewStepObject = Instantiate(LevelSteps[stepsCompleted]); AddressingStep NextStep = NewStepObject.GetComponent <AddressingStep>(); GrayCircle NextCorrect = null; isLastLevel = NextStep.Notes.Length == 0; NewStepObject.transform.parent = this.transform; TransitioningBackgrounds = true; Debug.Log("transitioningBackgrounds set to True" + " and transitionbackgrounds is " + TransitioningBackgrounds); if (OldStep.TutorialObject != null) { Destroy(OldStep.TutorialObject); Debug.Log("Destroyed OldStep.TutorialObject" + " and transitionbackgrounds is " + TransitioningBackgrounds); } //PlaceInBox(NewStepObject); float currentNoteBoxHeight = OldStep.NotesBox.bounds.size.y; float newNoteBoxHeight = NextStep.NotesBox.bounds.size.y; NewStepObject.transform.localScale *= (currentNoteBoxHeight / newNoteBoxHeight); Vector3 positionDeltaY = Vector3.up * (OldStep.NotesBox.bounds.center.y - NextStep.NotesBox.bounds.center.y); NewStepObject.transform.position += positionDeltaY; if (!isLastLevel) { nextIncorrect = LoadGrayNotes(NewStepObject, NextStep, out NextCorrect); } else { nextIncorrect = new GameObject[0]; } Vector3 offset = Vector3.Scale(Vector3.right, circ.gameObject.transform.position - NextStep.FirstNoteCollider.bounds.center); Vector3 finalOffset = Vector3.Scale(Vector3.right, circ.gameObject.transform.position - OldStep.FirstNoteCollider.bounds.center); NewStepObject.transform.position += offset; OldStepObject.transform.position += Vector3.forward * 0.2f; SuperdogDialogue.SetActive(false); Debug.Log("Placed new object in box, deactivated Superdog" + " and transitionbackgrounds is " + TransitioningBackgrounds); // Stage 1: "Swap" StartCoroutine(Transition.FadeOut(IncorrectCircles, swaptime, Transition.FinishType.Destroy)); StartCoroutine(Transition.FadeOut(circ.gameObject, swaptime)); if (NextStep.TutorialAlpha != null) { NextStep.TutorialAlpha.SetActive(false); } StartCoroutine(Transition.FadeIn(NewStepObject, swaptime, exclude: NextStep.TutorialAlpha)); //yield return Transition.Rotate(SupergirlArm.transform, swaptime / 2, 0f, 160f); Debug.Log("Finished swap" + " and transitionbackgrounds is " + TransitioningBackgrounds); // Stage 1.5: Throw vine SupergirlVineCurled.SetActive(false); SupergirlAnimator.SetTrigger("noteClicked"); // Trigger vine throwing animation yield return(vineController.ThrowVine(ThrowingVine, SupergirlVineCurled.transform.position, circ.transform.position, swaptime / 2)); Audio.PlayNote(CurrentStep.Notes[CurrentStep.CorrectIndex]); Debug.Log("Vine thrown" + " and transitionbackgrounds is " + TransitioningBackgrounds); if (circ != null) { Destroy(circ.gameObject); } Debug.Log("circle destroyed" + " and transitionbackgrounds is " + TransitioningBackgrounds); CurrentStep = NextStep; CurrentStepObject = NewStepObject; IncorrectCircles = nextIncorrect; CorrectCircle = NextCorrect; Debug.Log("Switched all the variables" + " and transitionbackgrounds is " + TransitioningBackgrounds); if (!isLastLevel) { StartCoroutine(TransitionBackgrounds()); StartCoroutine(Transition.Translate(CurrentStepObject.transform, CurrentStepObject.transform.position - finalOffset, flytime)); StartCoroutine(superdogController.FlySuperdog(flytime)); } else { StartCoroutine(Transition.Translate(CurrentStepObject.transform, Vector3.Scale(CurrentStepObject.transform.position, new Vector3(0f, 1f, 1f)), flytime)); } StartCoroutine(Transition.FadeOut(OldStepObject, flytime)); StartCoroutine(Transition.Translate(OldStepObject.transform, OldStepObject.transform.position - finalOffset, flytime)); SupergirlVineCurled.SetActive(true); StartCoroutine(Transition.Rotate(SupergirlArm.transform, flytime, 160f, 0f)); yield return(new WaitForSeconds(flytime + 0.2f)); Debug.Log("Supergirl has flown" + " and transitionbackgrounds is " + TransitioningBackgrounds); TransitioningBackgrounds = false; Debug.Log("transitioningBackgrounds set to False" + " and transitionbackgrounds is " + TransitioningBackgrounds); if (!isLastLevel) { SuperdogDialogue.SetActive(true); dialogueController.updateDialogue(TutorialIndex++); Debug.Log("Superdog reactivated" + " and transitionbackgrounds is " + TransitioningBackgrounds); } Destroy(OldStepObject); Debug.Log("Old step object destroyed" + " and transitionbackgrounds is " + TransitioningBackgrounds); if (NextStep.TutorialAlpha != null) { NextStep.TutorialAlpha.SetActive(true); } if (isLastLevel) { yield return(CompleteLevel()); } else if (LevelSelection.IsAutoplaying()) { CorrectCircleClicked(CorrectCircle); Debug.Log("Called CorrectCircleClicked" + " and transitionbackgrounds is " + TransitioningBackgrounds); } }
private IEnumerator LoadNextStep(GrayCircle circ) { bool isLastLevel; GameObject[] nextIncorrect; AddressingStep OldStep = CurrentStep; GameObject OldStepObject = CurrentStepObject; GameObject NewStepObject = Instantiate(LevelSteps[stepsCompleted]); AddressingStep NextStep = NewStepObject.GetComponent <AddressingStep>(); GrayCircle NextCorrect = null; isLastLevel = NextStep.Notes.Length == 0; NewStepObject.transform.parent = this.transform; TransitioningBackgrounds = true; //PlaceInBox(NewStepObject); float currentNoteBoxHeight = OldStep.NotesBox.bounds.size.y; float newNoteBoxHeight = NextStep.NotesBox.bounds.size.y; NewStepObject.transform.localScale *= (currentNoteBoxHeight / newNoteBoxHeight); Vector3 positionDeltaY = Vector3.up * (OldStep.NotesBox.bounds.center.y - NextStep.NotesBox.bounds.center.y); NewStepObject.transform.position += positionDeltaY; if (!isLastLevel) { nextIncorrect = LoadGrayNotes(NewStepObject, NextStep, out NextCorrect); } else { nextIncorrect = new GameObject[0]; } Vector3 offset = Vector3.Scale(Vector3.right, circ.gameObject.transform.position - NextStep.FirstNoteCollider.bounds.center); Vector3 finalOffset = Vector3.Scale(Vector3.right, circ.gameObject.transform.position - OldStep.FirstNoteCollider.bounds.center); NewStepObject.transform.position += offset; OldStepObject.transform.position += Vector3.forward * 0.2f; SuperdogDialogue.SetActive(false); if (!isLastLevel) { SuperdogText.text = "Swing to the " + NextStep.Notes[NextStep.CorrectIndex] + "!"; } // Stage 1: "Swap" StartCoroutine(Transition.FadeOut(IncorrectCircles, swaptime, Transition.FinishType.Destroy)); StartCoroutine(Transition.FadeOut(circ.gameObject, swaptime, false)); StartCoroutine(Transition.FadeIn(NewStepObject, swaptime, false)); yield return(Transition.Rotate(SupergirlArm.transform, swaptime / 2, 0f, 160f)); // Stage 1.5: Throw vine SupergirlVineCurled.SetActive(false); yield return(ThrowVine(SupergirlVineCurled.transform.position, circ.transform.position, swaptime / 2)); Destroy(circ.gameObject); CurrentStep = NextStep; CurrentStepObject = NewStepObject; IncorrectCircles = nextIncorrect; CorrectCircle = NextCorrect; if (!isLastLevel) { StartCoroutine(TransitionBackgrounds()); StartCoroutine(Transition.Translate(CurrentStepObject.transform, CurrentStepObject.transform.position - finalOffset, flytime)); StartCoroutine(FlySuperdog(flytime)); } else { StartCoroutine(Transition.Translate(CurrentStepObject.transform, Vector3.Scale(CurrentStepObject.transform.position, new Vector3(0f, 1f, 1f)), flytime)); StartCoroutine(FlySuperdogAway(flytime)); } StartCoroutine(Transition.FadeOut(OldStepObject, flytime, false)); StartCoroutine(Transition.Translate(OldStepObject.transform, OldStepObject.transform.position - finalOffset, flytime)); SupergirlVineCurled.SetActive(true); StartCoroutine(Transition.Rotate(SupergirlArm.transform, flytime, 160f, 0f)); yield return(new WaitForSeconds(flytime + 0.2f)); TransitioningBackgrounds = false; if (!isLastLevel) { SuperdogDialogue.SetActive(true); } Destroy(OldStepObject); if (isLastLevel) { yield return(CompleteLevel()); } else if (LevelSelection.IsAutoplaying()) { CorrectCircleClicked(CorrectCircle); } }
private void UpdateHangingVine(AddressingStep step) { Vector3 handPos = Supergirl.GetComponent<CircleCollider2D>().bounds.center; Vector3 notePos = step.FirstNoteCollider.bounds.center; PlaceVineBetween(Vine, handPos + 0.5f * Vector3.back, notePos + 0.5f * Vector3.back); float deltaX = notePos.x - handPos.x; float deltaY = notePos.y - handPos.y; float mag2 = Vector2.SqrMagnitude(notePos - handPos); sgVelocity += sgGrav * (new Vector3(deltaX * deltaY, -deltaX * deltaX) / mag2); Vector3 direction = Vector3.Normalize(new Vector3(-deltaY, deltaX, 0f)); sgVelocity = direction * Vector3.Dot(direction, sgVelocity); sgVelocity *= sgFriction; Supergirl.transform.position += sgVelocity; handPos = Supergirl.GetComponent<CircleCollider2D>().bounds.center; Vector3 delta = notePos + Mathf.Sqrt(mag2) * (handPos - notePos).normalized - handPos; Supergirl.transform.position += delta; }
private IEnumerator LoadNextStep(GrayCircle circ) { bool isLastLevel; GameObject[] nextIncorrect; AddressingStep OldStep = CurrentStep; GameObject OldStepObject = CurrentStepObject; GameObject NewStepObject = Instantiate(LevelSteps[stepsCompleted]); AddressingStep NextStep = NewStepObject.GetComponent<AddressingStep>(); GrayCircle NextCorrect = null; isLastLevel = NextStep.Notes.Length == 0; NewStepObject.transform.parent = this.transform; TransitioningBackgrounds = true; //PlaceInBox(NewStepObject); float currentNoteBoxHeight = OldStep.NotesBox.bounds.size.y; float newNoteBoxHeight = NextStep.NotesBox.bounds.size.y; NewStepObject.transform.localScale *= (currentNoteBoxHeight / newNoteBoxHeight); Vector3 positionDeltaY = Vector3.up * (OldStep.NotesBox.bounds.center.y - NextStep.NotesBox.bounds.center.y); NewStepObject.transform.position += positionDeltaY; if (!isLastLevel) { nextIncorrect = LoadGrayNotes(NewStepObject, NextStep, out NextCorrect); } else { nextIncorrect = new GameObject[0]; } Vector3 offset = Vector3.Scale(Vector3.right, circ.gameObject.transform.position - NextStep.FirstNoteCollider.bounds.center); Vector3 finalOffset = Vector3.Scale(Vector3.right, circ.gameObject.transform.position - OldStep.FirstNoteCollider.bounds.center); NewStepObject.transform.position += offset; OldStepObject.transform.position += Vector3.forward * 0.2f; SuperdogDialogue.SetActive(false); if (!isLastLevel) { SuperdogText.text = "Swing to the " + NextStep.Notes[NextStep.CorrectIndex] + "!"; } // Stage 1: "Swap" StartCoroutine(Transition.FadeOut(IncorrectCircles, swaptime, Transition.FinishType.Destroy)); StartCoroutine(Transition.FadeOut(circ.gameObject, swaptime, false)); StartCoroutine(Transition.FadeIn(NewStepObject, swaptime, false)); yield return Transition.Rotate(SupergirlArm.transform, swaptime / 2, 0f, 160f); // Stage 1.5: Throw vine SupergirlVineCurled.SetActive(false); yield return ThrowVine(SupergirlVineCurled.transform.position, circ.transform.position, swaptime / 2); Destroy(circ.gameObject); CurrentStep = NextStep; CurrentStepObject = NewStepObject; IncorrectCircles = nextIncorrect; CorrectCircle = NextCorrect; if (!isLastLevel) { StartCoroutine(TransitionBackgrounds()); StartCoroutine(Transition.Translate(CurrentStepObject.transform, CurrentStepObject.transform.position - finalOffset, flytime)); StartCoroutine(FlySuperdog(flytime)); } else { StartCoroutine(Transition.Translate(CurrentStepObject.transform, Vector3.Scale(CurrentStepObject.transform.position, new Vector3(0f, 1f, 1f)), flytime)); StartCoroutine(FlySuperdogAway(flytime)); } StartCoroutine(Transition.FadeOut(OldStepObject, flytime, false)); StartCoroutine(Transition.Translate(OldStepObject.transform, OldStepObject.transform.position - finalOffset, flytime)); SupergirlVineCurled.SetActive(true); StartCoroutine(Transition.Rotate(SupergirlArm.transform, flytime, 160f, 0f)); yield return new WaitForSeconds(flytime + 0.2f); TransitioningBackgrounds = false; if (!isLastLevel) { SuperdogDialogue.SetActive(true); } Destroy(OldStepObject); if (isLastLevel) { yield return CompleteLevel(); } else if (LevelSelection.IsAutoplaying()) { CorrectCircleClicked(CorrectCircle); } }
private GameObject[] LoadGrayNotes(GameObject stepObj, AddressingStep step, out GrayCircle correct) { Bounds bounds = step.NotesBox.bounds; float yMin = bounds.center.y - bounds.extents.y; float yMax = bounds.center.y + bounds.extents.y; float xMin = bounds.center.x - bounds.extents.x; float xMax = bounds.center.x + bounds.extents.x; correct = null; GameObject[] circles = new GameObject[step.Notes.Length - 1]; int j = 0; for (int i = 0; i < step.Notes.Length; i++) { Vector3 position = new Vector3(xMin + (xMax - xMin) * (((float)i) / step.Notes.Length), yMin + (yMax - yMin) * GetYByAddress(step.Notes[i]), -2); GameObject gray = (GameObject)Instantiate(GrayCirclePrefab, position, Quaternion.identity); gray.name = step.Notes[i]; gray.transform.parent = stepObj.transform; gray.name = step.Notes[i]; GrayCircle circ = gray.GetComponent<GrayCircle>(); bool isCorrect = (i == step.CorrectIndex); if (isCorrect) { circ.IsCorrect = true; correct = circ; } else { circ.IsCorrect = false; circles[j++] = gray; } circ.controller = this; } return circles; }
private IEnumerator ConfigureFirstStep() { CurrentStepObject = Instantiate(LevelSteps[0]); CurrentStep = CurrentStepObject.GetComponent<AddressingStep>(); CurrentStepObject.transform.parent = this.transform; PlaceInBox(CurrentStepObject); IncorrectCircles = LoadGrayNotes(CurrentStepObject, CurrentStep, out CorrectCircle); firstNoteHeight = CurrentStep.FirstNoteCollider.bounds.center.y; SuperdogText.text = "Swing to the " + CurrentStep.Notes[CurrentStep.CorrectIndex] + "!"; yield return Transition.FadeIn(SuperdogText.gameObject, tutorialFadeTime, false); if (!IsFirstLevel && LevelSelection.IsAutoplaying()) { CorrectCircleClicked(CorrectCircle); } }