void Update()
    {
        // this is just the starting scene to start the minigame
        if (phase == 0)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                phase = 1;
                slime.assignPos(leftStartPosition);
                timer.startTicking = true;
                soundManager.ShowStarting();
            }
        }
        // this is an unseen phase that gets the audience comments ready
        else if (phase == 1)
        {
            string sourceLine    = textLines[randomLine];
            int    wordIndex     = int.Parse(sourceLine.Substring(0, 3));
            string frontSentence = sourceLine.Substring(3, wordIndex);
            boldWord = sourceLine.Substring(wordIndex + 3, letterCount);
            string backSentence = sourceLine.Substring(wordIndex + letterCount + 3);
            audienceSentence.text = frontSentence + "<color=#00F8FF>" + boldWord + "</color>" + backSentence; // I HAVE THE WORD AS RED, BUT THIS CAN BE CHANGED

            if (leftToRight)
            {
                sortedArray = SelectionSortLeftToRight(boldWord);
            }
            else
            {
                sortedArray = SelectionSortRightToLeft(boldWord);
            }

            phase = 2;
        }
        // this phase is the actual gameplay!
        else if (phase == 2)
        {
            // if the player enters a key
            if (Input.anyKeyDown && !stun)
            {
                foreach (KeyCode vKey in System.Enum.GetValues(typeof(KeyCode)))                       // for each virtual key
                {
                    string inputString = vKey.ToString();                                              //convert to string
                    int    inputID     = stageBoard.alphabet.IndexOf(inputString);                     // find string id (index on alphabet list)

                    if (Input.GetKeyDown(vKey) && inputID < stageBoard.keyBools.Count && inputID >= 0) //if its a valid input (can be expanded upon)
                    {
                        // if the player enters a correct key (and is able to because the slime isn't stunned)
                        if (inputString == sortedArray[tracker])
                        {
                            gameSoundManager.Step();
                            tracker++;
                            playerInput.text += inputString.ToUpper();
                            slime.assignPos(stageBoard.keySprites[inputID].transform.position);
                        }

                        // if the player enters an incorrect key
                        else
                        {
                            slimeEffect.createSad();
                            barnum.SetTrigger("Angry");
                            gameSoundManager.Wrong();
                            if (!stun)
                            {
                                GameManager.Instance.SubtractScore(Random.Range(0.25f, 0.75f));
                            }
                            stun          = true;
                            stunCoroutine = Stun();
                            StartCoroutine(stunCoroutine);
                        }
                    }
                }
            }

            // if player correctly types out the word, then reset
            if (tracker == letterCount && Vector3.Distance(slime.gameObject.transform.position, stageBoard.keySprites[stageBoard.alphabet.IndexOf(sortedArray[letterCount - 1])].transform.position) <= 1)
            {
                if (leftToRight)
                {
                    slime.assignPos(rightStartPosition);
                }
                else
                {
                    slime.assignPos(leftStartPosition);
                }
                slimeEffect.createHappy();
                barnum.SetTrigger("Happy");
                gameSoundManager.Win();
                GameManager.Instance.AddScore(Random.Range(1f, 1.5f));
                stun             = false;
                leftToRight      = !leftToRight;
                tracker          = 0;
                randomLine       = Random.Range(0, 12);
                phase            = 1;
                playerInput.text = "";
                timer.Reset();
                rounds++;
                // if 6 rounds have been completed, go to phase 3
                if (rounds == 6)
                {
                    timer.startTicking    = false;
                    timer.timerText.text  = "";
                    audienceSentence.text = "You have successfully completed the minigame!";
                    playerInput.text      = "Great job!";
                    phase = 3;
                }
                else
                {
                    float randomAudienceReaction = Random.Range(0f, 1f);
                    if (randomAudienceReaction <= 0.5f)
                    {
                        soundManager.CrowdClap();
                    }
                    else
                    {
                        soundManager.CrowdLaugh();
                    }
                }
            }

            // if the player runs out of time
            if (timer.timerDisplay == 0)
            {
                soundManager.CrowdBoo();
                if (leftToRight)
                {
                    slime.assignPos(leftStartPosition);
                }
                else
                {
                    slime.assignPos(rightStartPosition);
                }
                stun             = false;
                tracker          = 0;
                phase            = 1;
                playerInput.text = "";
                timer.Reset();
                GameManager.Instance.SubtractScore(Random.Range(1f, 3f));
            }
        }

        // this last phase is for when the minigame ends (player completes all rounds)
        else if (phase == 3)
        {
            slime.assignPos(new Vector3(0, 0, 0));
            soundManager.CrowdClapEnd();
            loadNextScene = LoadScene();
            StartCoroutine(loadNextScene);
            phase = 4;
        }
    }
Пример #2
0
    void Update()
    {
        if (finishedMinigame == 0)
        {
            if (roundStage == 0 && landed)
            {
                //newPos = new Vector3(Marker.position.x, 0, Marker.position.z);
                foreach (KeyCode vKey in System.Enum.GetValues(typeof(KeyCode))) // for each virtual key
                {
                    string inputString = vKey.ToString();                        //convert to string
                    int    inputID     = Board.alphabet.IndexOf(inputString);    // find string id (index on alphabet list)

                    if (inputID < Board.keyBools.Count && inputID >= 0)          //if its a valid input (can be expanded upon)
                    {
                        if (Input.GetKey(vKey))                                  //if this key is being pressed
                        {
                            if (Board.isKeyTangent(occupiedKey, inputID))
                            {
                                if (occupiedKey != inputID)
                                {
                                    gameSoundManager.Step();
                                    slimeForward = Board.keySprites[inputID].transform.position - Board.keySprites[occupiedKey].transform.position;
                                    slimeForward.Normalize();
                                }
                                Slime.localScale = new Vector3(0.36029f * 1.2f, 0.36029f * .3f, 0.36029f * 1.2f);
                                occupiedKey      = inputID;
                            }
                        }
                    }
                }

                if (occupiedKey == stagingKey)
                {
                    GenerateDistance(); roundStage = 1;
                }
            }

            else
            {
                //newPos = new Vector3(Marker.position.x, 0, Marker.position.z);
                if (Input.anyKeyDown && landed)
                {
                    foreach (KeyCode vKey in System.Enum.GetValues(typeof(KeyCode))) // for each virtual key
                    {
                        string inputString = vKey.ToString();                        //convert to string
                        int    inputID     = Board.alphabet.IndexOf(inputString);    // find string id (index on alphabet list)

                        if (inputID < Board.keyBools.Count && inputID >= 0)          //if its a valid input (can be expanded upon)
                        {
                            if (Input.GetKey(vKey))                                  //if this key is being pressed
                            {
                                occupiedKey = inputID;
                                newPos      = new Vector3(Board.keySprites[occupiedKey].transform.position.x, 0, Board.keySprites[occupiedKey].transform.position.z);
                                initDist    = Vector3.Distance(new Vector3(Marker.position.x, 0, Marker.position.z), newPos);
                                jumping     = true;
                            }
                        }
                    }
                    if (Board.isKeyTangent(occupiedKey, targetKey))
                    {
                        slimeEffect.createHappy();
                        barnum.SetTrigger("Happy");
                        //Debug.Log("SUCCESS!!");
                        GameManager.Instance.AddScore(Random.Range(1f, 1.5f));
                        gameSoundManager.Win();
                        float randomAudienceReaction = Random.Range(0f, 1f);
                        if (randomAudienceReaction <= 0.5f)
                        {
                            if (day != 0)
                            {
                                soundManager.CrowdClap();
                            }
                        }
                        else
                        {
                            if (day != 0)
                            {
                                soundManager.CrowdLaugh();
                            }
                        }
                        GameObject.Find("Spot Light").GetComponent <Light>().color = Color.green;

                        /*if (phase + 1 == phases && Vector3.Distance(Marker.gameObject.transform.position, Board.keySprites[stagingKey].transform.position) <= 1.51)
                         * {
                         *  finishedMinigame = 1;
                         * }*/
                    }
                    else
                    {
                        GameManager.Instance.SubtractScore(Random.Range(1f, 2f));
                        slimeEffect.createSad();
                        barnum.SetTrigger("Angry");
                        //Debug.Log("FAILURE!!");
                        gameSoundManager.Wrong();
                        if (day != 0)
                        {
                            soundManager.CrowdBoo();
                        }
                        GameObject.Find("Spot Light").GetComponent <Light>().color = Color.red;
                    }
                    stagingKey    = Random.Range(0, 26);
                    stagingString = Board.alphabet[stagingKey];
                    //Debug.Log($"Go To Key {Board.alphabet[stagingKey]}");
                    if (phase + 1 != phases)
                    {
                        audienceSentence.text = $"Go To Key {Board.alphabet[stagingKey]}";
                    }
                    GameObject.Find("DIST").GetComponent <TextMeshPro>().text = $"Go To Key {Board.alphabet[stagingKey]}";
                    phase++;
                    roundStage = 0;
                }
                if (jumping)
                {
                    jumping2 = true;
                }
            }

            if (jumping2)
            {
                landed  = false;
                jumping = false;
                Debug.Log((initDist - Vector3.Distance(new Vector3(Marker.position.x, 0, Marker.position.z), newPos)) / initDist);

                Slime.localPosition = new Vector3(0, -.84f + 5 * jump.Evaluate((initDist - Vector3.Distance(new Vector3(Marker.position.x, 0, Marker.position.z), newPos)) / initDist), 0);
                if (Vector3.Distance(new Vector3(Marker.position.x, 0, Marker.position.z), newPos) < 0.1f)
                {
                    landed   = true;
                    jumping2 = false;
                    if (phase == phases)
                    {
                        finishedMinigame = 1;
                    }
                }
            }
            else
            {
                Slime.localPosition = new Vector3(0, -.84f, 0);
            }

            if (phase == phases && landed)
            {
                audienceSentence.text = "You have successfully completed the minigame!";
                if (Vector3.Distance(Marker.gameObject.transform.position, Board.keySprites[stagingKey].transform.position) <= 1.51)
                {
                    finishedMinigame = 1;
                }
            }
            Marker.position = Vector3.Lerp(Marker.position, new Vector3(Board.keySprites[occupiedKey].transform.position.x, 1.5f, Board.keySprites[occupiedKey].transform.position.z), Time.deltaTime * 8);
            SlimeController();
            GameObject.Find("Spot Light").GetComponent <Light>().color = Color.Lerp(GameObject.Find("Spot Light").GetComponent <Light>().color, new Color(1, 0.7215686f, 0), Time.deltaTime * 15);
        }
        else if (finishedMinigame == 1 && landed)
        {
            Marker.position = Vector3.Lerp(Marker.position, new Vector3(Board.keySprites[occupiedKey].transform.position.x, 1.5f, Board.keySprites[occupiedKey].transform.position.z), Time.deltaTime * 8);
            if (day != 0)
            {
                soundManager.CrowdClapEnd();
            }
            loadNextScene = LoadScene();
            StartCoroutine(loadNextScene);
            finishedMinigame = 2;
        }
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        if (phase == 0)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                soundManager.ShowStarting();
                countDownCoroutine = CountDown();
                StartCoroutine(countDownCoroutine);
            }
        }
        // unseen phase that just selects a random letter
        if (phase == 1)
        {
            if (!ranOutOfTime)
            {
                if (queueLetters.Count >= numberOfSlimes)
                {
                    removedLetterIndex = stageBoard.alphabet.IndexOf(queueLetters[0]);
                    queueLetters.RemoveAt(0);
                }
                randoLetter = Random.Range(0, 26);
                while (queueLetters.Contains(stageBoard.alphabet[randoLetter]) || removedLetterIndex == randoLetter)
                {
                    randoLetter = Random.Range(0, 26);
                }
                queueLetters.Add(stageBoard.alphabet[randoLetter]);
                tracker = queueLetters.Count - 1;
            }
            audienceSentence.text = "<color=#00F8FF>" + stageBoard.alphabet[randoLetter] + "</color>";
            playerInput.text      = "";
            slimeTracker          = 0;
            phase        = 2;
            ranOutOfTime = false;
        }
        // this phase is the core gameplay stage but only when SOME slimes are on stage
        else if (phase == 2 && !countingDown)
        {
            // if the player correctly types in all of the letters
            if (tracker == -1)
            {
                slimeEffect.createHappy();
                barnum.SetTrigger("Happy");
                float randomAudienceReaction = Random.Range(0f, 1f);
                if (randomAudienceReaction <= 0.5f)
                {
                    soundManager.CrowdClap();
                }
                else
                {
                    soundManager.CrowdLaugh();
                }
                gameSoundManager.Win();
                if (maxLengthLetters != numberOfSlimes)
                {
                    maxLengthLetters++;
                    while (slimeTracker < numberOfSlimes)
                    {
                        slimes[slimeTracker].assignPos(previousPositions[slimeTracker - 1]);
                        slimeTracker++;
                    }
                }
                for (int i = 0; i < numberOfSlimes; i++)
                {
                    previousPositions[i] = slimes[i].positionToMove;
                }
                currentRound++;
                if (currentRound < totalRounds)
                {
                    countDownCoroutine = CountDown();
                    StartCoroutine(countDownCoroutine);
                }
                else
                {
                    phase = 3;
                }
                GameManager.Instance.AddScore(Random.Range(0.5f, 1f));
                timer.Reset();
            }
            // if the player enters a key
            if (Input.anyKeyDown && tracker != -1)
            {
                foreach (KeyCode vKey in System.Enum.GetValues(typeof(KeyCode)))                       // for each virtual key
                {
                    string inputString = vKey.ToString();                                              //convert to string
                    int    inputID     = stageBoard.alphabet.IndexOf(inputString);                     // find string id (index on alphabet list)

                    if (Input.GetKeyDown(vKey) && inputID < stageBoard.keyBools.Count && inputID >= 0) //if its a valid input (can be expanded upon)
                    {
                        // if the player enters a correct key (and is able to because the slime isn't stunned)
                        if (inputString == queueLetters[tracker])
                        {
                            playerInput.text += inputString.ToUpper();
                            slimes[slimeTracker].assignPos(stageBoard.keySprites[inputID].transform.position);
                            slimeTracker++;
                            tracker--;
                            if (tracker != -1)
                            {
                                gameSoundManager.Step();
                            }
                        }

                        // if the player enters an incorrect key
                        else
                        {
                            slimeEffect.createSad();
                            barnum.SetTrigger("Angry");
                            gameSoundManager.Wrong();
                            GameManager.Instance.SubtractScore(Random.Range(0.25f, 1f));
                            GoBack();
                        }
                    }
                }
            }
            if (timer.timerDisplay <= 0)
            {
                soundManager.CrowdBoo();
                GameManager.Instance.SubtractScore(Random.Range(0.5f, 1f));
                ranOutOfTime = true;
                GoBack();
                timer.Reset();
                countDownCoroutine = CountDown();
                StartCoroutine(countDownCoroutine);
            }
        }
        else if (phase == 3)
        {
            soundManager.CrowdClapEnd();
            timer.startTicking    = false;
            timer.timerText.text  = "";
            audienceSentence.text = "Great job!";
            playerInput.text      = "You have successfully completed the minigame!";
            loadNextScene         = LoadScene();
            StartCoroutine(loadNextScene);
            phase = 4;
        }
    }