Exemplo n.º 1
0
    /// <summary>
    /// Kick off something the player needs to interact with
    /// </summary>
    /// <param name="myHurdleIndex"></param>
    /// <param name="myHurdle"></param>
    /// <returns></returns>
    private IEnumerator KickOffHurdle(int myHurdleIndex, Hurdle myHurdle, List <float> times, Transform start, Transform end, bool isFish)
    {
        Hurdle  mirrorHurdle = Instantiate(myHurdle.gameObject).GetComponent <Hurdle>();
        Vector3 mirrorStart  = new Vector3(-start.position.x, start.position.y, start.position.z);
        Vector3 mirrorEnd    = new Vector3(-end.position.x, end.position.y, end.position.z);

        mirrorHurdle.transform.localScale = new Vector3(-1, 1, 1);

        bool madeYellow = false;

        float visualStartTime = times[myHurdleIndex] - beatRadiusVisualHint;
        float visualEndTime   = times[myHurdleIndex] + beatRadiusVisualHint;

        float inputStartTime = times[myHurdleIndex] - beatInputLead;
        float inputEndTime   = times[myHurdleIndex] + beatInputLag;

        bool inputSuccess = false;
        bool missed       = false;

        Command correctCode = Command.Fire;

        if (myHurdle.CorrectCommand == "up")
        {
            correctCode = Command.Up;
        }
        else if (myHurdle.CorrectCommand == "down")
        {
            correctCode = Command.Down;
        }
        else
        {
            Debug.LogError("unhandled code!");
        }

        while (currentTime < visualEndTime)
        {
            if (currentTime > inputStartTime && !madeYellow)
            {
                madeYellow = true;
                myHurdle.MakeReady();
                mirrorHurdle.MakeReady();
            }

            // success
            if (currentTime > inputStartTime && currentTime < inputEndTime &&
                (CommandsStartedThisFrame.ContainsKey(correctCode)))
            {
                success.Play();
                inputSuccess = true;

                // make the hurdle green
                if (isFish)
                {
                    // they do the fish flippy thing instead of just disappearing, flying into moxie's mouth
                    ((FishHurdle)myHurdle).SetGoSpot(fishEatSpot.transform.position);
                    ((FishHurdle)myHurdle).MakeCorrect();
                    ((FishHurdle)mirrorHurdle).SetGoSpot(fishEatSpot.transform.position);
                    ((FishHurdle)mirrorHurdle).MakeCorrect();
                }
                else
                {
                    myHurdle.MakeCorrect();
                    mirrorHurdle.MakeCorrect();
                }

                // shout a success shout
                int successShoutIndex = Random.Range(0, successShouts.Count);
                if (lastSuccessShout == successShoutIndex)
                {
                    successShoutIndex++;
                    if (successShoutIndex >= successShouts.Count)
                    {
                        successShoutIndex = 0;
                    }
                }
                outputText.text  = successShouts[successShoutIndex];
                lastSuccessShout = successShoutIndex;
            }

            // miss..
            else if (currentTime > inputEndTime && !inputSuccess && !missed)
            {
                missed = true;

                myHurdle.MakeWrong();
                mirrorHurdle.MakeWrong();

                // shout a miss shout
                int missShoutIndex = Random.Range(0, missShouts.Count);
                if (lastMissShout == missShoutIndex)
                {
                    missShoutIndex++;
                    if (missShoutIndex >= missShouts.Count)
                    {
                        missShoutIndex = 0;
                    }
                }
                outputText.text = missShouts[missShoutIndex];
                lastMissShout   = missShoutIndex;

                numMistakes++;
                mistake.Play();
            }


            if (isFish && myHurdle.GetState() == Hurdle.HurdleState.Correct)
            {
                // if you're a fish and you're correctly answered, do nothing
            }
            else
            {
                // move the hurdle
                float hurdleProgress = (currentTime - visualStartTime) / (visualEndTime - visualStartTime);
                myHurdle.transform.position     = Vector3.Lerp(start.position, end.position, hurdleProgress);
                mirrorHurdle.transform.position = Vector3.Lerp(mirrorStart, mirrorEnd, hurdleProgress);
            }

            yield return(0);
        }

        if (numMistakes > allowedMistakes)
        {
            StartCoroutine(Failure());
        }

        yield return(new WaitForSeconds(0.2f));

        Destroy(myHurdle.gameObject);
        Destroy(mirrorHurdle.gameObject);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Kick off something the player needs to interact with
    /// </summary>
    /// <param name="myHurdleIndex"></param>
    /// <param name="myHurdle"></param>
    /// <returns></returns>
    private IEnumerator KickOffHurdle(int myHurdleIndex, Hurdle myHurdle, List <float> times, Transform start, Transform end, Transform disappearSpot = null, bool isFish = false)
    {
        bool madeYellow = false;

        float visualStartTime = times[myHurdleIndex] - beatRadiusVisualHint;
        float visualEndTime   = times[myHurdleIndex] + beatRadiusVisualHint;

        float inputStartTime = times[myHurdleIndex] - beatInputLead;
        float inputEndTime   = times[myHurdleIndex] + beatInputLag;

        bool inputSuccess = false;
        bool missed       = false;

        Command correctCode = Command.Fire;

        if (myHurdle.CorrectCommand == "up")
        {
            correctCode = Command.Up;
        }
        else if (myHurdle.CorrectCommand == "down")
        {
            correctCode = Command.Down;
        }
        else
        {
            Debug.LogError("unhandled direction!");
        }

        while (currentTime < visualEndTime)
        {
            if (currentTime > inputStartTime && !madeYellow)
            {
                madeYellow = true;
                myHurdle.MakeReady();
            }

            // success
            if (currentTime > inputStartTime && currentTime < inputEndTime &&
                (CommandsStartedThisFrame.ContainsKey(correctCode)))
            {
                success.Play();
                inputSuccess = true;

                myHurdle.MakeCorrect();

                // shout a success shout
                int successShoutIndex = Random.Range(0, successShouts.Count);
                if (lastSuccessShout == successShoutIndex)
                {
                    successShoutIndex++;
                    if (successShoutIndex >= successShouts.Count)
                    {
                        successShoutIndex = 0;
                    }
                }
                outputText.text  = successShouts[successShoutIndex];
                lastSuccessShout = successShoutIndex;
            }

            // miss..
            else if (currentTime > inputEndTime && !inputSuccess && !missed)
            {
                missed = true;

                // todo toss the hurdle
                myHurdle.MakeWrong();

                // shout a miss shout
                int missShoutIndex = Random.Range(0, missShouts.Count);
                if (lastMissShout == missShoutIndex)
                {
                    missShoutIndex++;
                    if (missShoutIndex >= missShouts.Count)
                    {
                        missShoutIndex = 0;
                    }
                }
                outputText.text = missShouts[missShoutIndex];
                lastMissShout   = missShoutIndex;

                numMistakes++;
                mistake.Play();
            }

            float hurdleProgress = (currentTime - visualStartTime) / (visualEndTime - visualStartTime);
            myHurdle.transform.position = Vector3.Lerp(start.position, end.position, hurdleProgress);

            // disappear when you move past the spot and you're successful
            if (disappearSpot != null && myHurdle.GetState() == Hurdle.HurdleState.Correct)
            {
                // objects moving right
                if (disappearSpot.position.x > start.position.x)
                {
                    if (myHurdle.transform.position.x > disappearSpot.position.x)
                    {
                        // disappear
                        myHurdle.SetVisible(false);
                    }
                }
                else
                {
                    if (myHurdle.transform.position.x < disappearSpot.position.x)
                    {
                        // disappear
                        myHurdle.SetVisible(false);
                    }
                }
            }

            yield return(0);
        }

        if (numMistakes > allowedMistakes)
        {
            StartCoroutine(Failure());
        }

        yield return(new WaitForSeconds(0.2f));

        Destroy(myHurdle.gameObject);
    }
Exemplo n.º 3
0
    /// <summary>
    /// Kick off something the player needs to interact with
    /// </summary>
    /// <param name="myHurdleIndex"></param>
    /// <param name="myHurdle"></param>
    /// <returns></returns>
    protected IEnumerator KickOffHurdle(int myHurdleIndex, Hurdle myHurdle)
    {
        bool madeYellow = false;

        float visualStartTime = beatTimes[myHurdleIndex] - beatRadiusVisualHint;
        float visualEndTime   = beatTimes[myHurdleIndex] + beatRadiusVisualHint;

        float inputStartTime = beatTimes[myHurdleIndex] - beatInputLead;
        float inputEndTime   = beatTimes[myHurdleIndex] + beatInputLag;

        bool inputSuccess = false;
        bool missed       = false;

        while (currentTime < visualEndTime)
        {
            if (currentTime > inputStartTime && !madeYellow)
            {
                madeYellow = true;
                myHurdle.MakeReady();
            }

            // success
            if (currentTime > inputStartTime && currentTime < inputEndTime &&
                CommandsStartedThisFrame.ContainsKey(Command.Up))
            {
                success.Play();
                inputSuccess = true;

                // make the hurdle green
                myHurdle.MakeCorrect();

                // shout a success shout
                int successShoutIndex = Random.Range(0, successShouts.Count);
                if (lastSuccessShout == successShoutIndex)
                {
                    successShoutIndex++;
                    if (successShoutIndex >= successShouts.Count)
                    {
                        successShoutIndex = 0;
                    }
                }
                outputText.text  = successShouts[successShoutIndex];
                lastSuccessShout = successShoutIndex;
            }

            // miss..
            else if (currentTime > inputEndTime && !inputSuccess && !missed)
            {
                missed = true;

                // todo toss the hurdle
                myHurdle.MakeWrong();

                // shout a miss shout
                int missShoutIndex = Random.Range(0, missShouts.Count);
                if (lastMissShout == missShoutIndex)
                {
                    missShoutIndex++;
                    if (missShoutIndex >= missShouts.Count)
                    {
                        missShoutIndex = 0;
                    }
                }
                outputText.text = missShouts[missShoutIndex];
                lastMissShout   = missShoutIndex;

                numMistakes++;
                mistake.Play();
            }

            float hurdleProgress = (currentTime - visualStartTime) / (visualEndTime - visualStartTime);
            myHurdle.transform.position = Vector3.Lerp(rightEdge.transform.position, leftEdge.transform.position, hurdleProgress);

            yield return(0);
        }

        if (numMistakes > allowedMistakes)
        {
            StartCoroutine(Failure());
        }

        yield return(new WaitForSeconds(0.2f));

        Destroy(myHurdle.gameObject);
    }