Ejemplo n.º 1
0
    new void Update()
    {
        bool change = Utils.updateSoftVariable(ref sparkScale, sparkTargetScale, 30.0f);

        if (change)
        {
            spark1.transform.localScale = new Vector3(sparkScale, sparkScale, sparkScale);
            spark2.transform.localScale = new Vector3(sparkScale, sparkScale, sparkScale);
            spark3.transform.localScale = new Vector3(sparkScale, sparkScale, sparkScale);
        }

        if (state == QAControllerState.idle)
        {
            elapsedTime += Time.deltaTime;


            if (elapsedTime > initialDelay)
            {
                letterOutputSpeed = slowletterOutputSpeed;
                state             = QAControllerState.idle2;
            }
        }

        if (state == QAControllerState.idle2)
        {
            /* extract question and answers */

            ab            = qa.getNextBank();
            correctAnswer = qb.correntAnswer [currentQuestion];
            ab.rosetta    = rosetta;
            qb.rosetta    = rosetta;

            ab.reset();

            burn [currentQuestion].lightUp();

            question = qb.getNextString();

            state = QAControllerState.printingQuestion;

            questionLetterOutput = 0.0f;
        }

        if (state == QAControllerState.printingQuestion)
        {
            int letters = (int)questionLetterOutput;

            if (Input.GetMouseButtonDown(0))
            {
                letterOutputSpeed = fastletterOutputSpeed;
            }

            if ((letters > 2) && (letters < question.Length - 2))
            {
                questionText.text = "<color=" + color1 + ">" + question.Substring(0, letters) + "</color>" +
                                    "<color=" + color2 + ">" + question.Substring(letters, 1) + "</color>" +
                                    "<color=" + color3 + ">" + question.Substring(letters + 1, 1) + "</color>" +
                                    "<color=" + color4 + ">" + question.Substring(letters + 2, question.Length - 1 - letters - 2) +
                                    "</color>";
            }
            if (letters == question.Length)
            {
                questionText.text = question;
            }
            questionLetterOutput += letterOutputSpeed * Time.deltaTime;

            if (letters > question.Length - 1)
            {
                letters           = question.Length - 1;
                questionText.text = "" + question;
                state             = QAControllerState.waitingForAnswer;

                for (int i = 0; i < maxAnswers; ++i)
                {
                    answerGO [i] = null;
                }

                float yPos = YAdjust - (question.Length / QuestionLettersPerLine) * QuestionLineHeight;
                for (int i = 0; i < ab.nItems(); ++i)
                {
                    GameObject newAnswer;
                    newAnswer = Instantiate(QAnswerPrefab);
                    newAnswer.transform.SetParent(answerPanel.transform);
                    newAnswer.transform.localScale = Vector3.one;
                    newAnswer.GetComponent <RectTransform>().sizeDelta        = new Vector2(800, 45);
                    newAnswer.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;
                    newAnswer.GetComponent <Text> ().alignment = TextAnchor.UpperCenter;
                    newAnswer.GetComponent <QAAnswer> ().initialize(yPos);
                    newAnswer.GetComponent <QAAnswer> ().answerNumber = i + 1;
                    int nLines;
                    newAnswer.GetComponent <QAAnswer> ().setText(StringUtils.chopLines(ab.getNextString(), 85, out nLines));
                    newAnswer.GetComponent <QAAnswer> ().setDelay(i * 0.3f);
                    yPos        -= (InterAnswerDistance + AnswerLineHeight * (nLines - 1));
                    answerGO [i] = newAnswer;
                }
            }
        }

        if (state == QAControllerState.waitingForAnswer)
        {
            bool waiting = true;
            for (int i = 0; i < ab.nItems(); i++)
            {
                if (answerGO [i].GetComponent <QAAnswer> ().state != QAAnswerState.idle)
                {
                    waiting = false;
                }
                else
                {
                    waiting = true;
                }
            }

            if (waiting)
            {
                for (int i = 0; i < ab.nItems(); i++)
                {
                    answerGO [i].GetComponent <QAAnswer> ().state = QAAnswerState.ready;
                    state = QAControllerState.waitingForAnswer2;
                }
            }
        }

        if (state == QAControllerState.waitingForAnswer2)
        {
        }

        if (state == QAControllerState.answered)
        {
            letterOutputSpeed = slowletterOutputSpeed;
            for (int i = 0; i < ab.nItems(); ++i)
            {
                if (answerGO [i].GetComponent <QAAnswer> ().answerNumber != selectedAnswer)
                {
                    answerGO [i].GetComponent <QAAnswer> ().dispose();
                }
                else
                {
                    answerGO [i].GetComponent <QAAnswer> ().blink(selectedAnswer == correctAnswer);
                    if (selectedAnswer == correctAnswer)
                    {
                        levelRef.playSound(hitSound);
                    }
                    else
                    {
                        levelRef.playSound(missSound);
                    }
                }
            }

            elapsedTime = 0.0f;
            state       = QAControllerState.preparingNextQuestion;
        }

        if (state == QAControllerState.preparingNextQuestion)
        {
            elapsedTime += Time.deltaTime;
            if (elapsedTime > postAnswerTimeOut)
            {
                elapsedTime = 0.0f;
                state       = QAControllerState.preparingNextQuestion2;
                if (selectedAnswer == correctAnswer)
                {
                    burn [currentQuestion].burstInFlames();
                }
                else
                {
                    ++nMisses;
                    if (nMisses > 1)
                    {
                        fader._wa_fadeOut(this);
                        keyChannel = -1;
                        // mark this flame for resurrection, please
                        string lvl           = ds.retrieveStringValue("CurrentLevelFlame");
                        int    FlameIndex    = ds.retrieveIntValue("CurrentFlameIndex");
                        string FlameName     = ds.retrieveStringValue("FlameResurrectionName" + lvl + FlameIndex);
                        string FlameLocation = ds.retrieveStringValue("FlameResurrectionLocation" + lvl + FlameIndex);
                        ds.storeIntValue("Flame" + (FlameIndex) + "Resurrect" + FlameLocation, 3);
                        ds.storeStringValue("Flame" + (FlameIndex) + "Resurrect" + FlameLocation, FlameName);
                        this.isWaitingForActionToComplete = true;
                        state = QAControllerState.exitting3;
                    }
                }
                if (currentQuestion == numQuestions - 1)
                {
                    //fader._wa_fadeOut (this);
                    //this.isWaitingForActionToComplete = true;
                    /* do the flower thing */
                    flowerRenderQuad.GetComponent <GameObjectFader> ().fadeIn();
                    flowerAnim.SetBool("open", true);
                    spark1Anim.SetBool("open", true);
                    spark2Anim.SetBool("open", true);
                    spark3Anim.SetBool("open", true);
                    levelRef.dipMusic(4);
                    levelRef.playSound(sparksSound);
                    sparkTargetScale = 60.0f;
                    elapsedTime      = 0.0f;
                    state            = QAControllerState.exitting1;
                }
            }
        }

        if (state == QAControllerState.preparingNextQuestion2)
        {
            elapsedTime += Time.deltaTime;
            if (elapsedTime > postAnswerTimeOut)
            {
                questionText.text = "";
                ++currentQuestion;
                state = QAControllerState.idle;
            }
        }

        if (state == QAControllerState.exitting1)
        {
            elapsedTime += Time.deltaTime;
            if (elapsedTime > 5.6f)
            {
                fader.setFadeColor(1, 1, 1);
                fader._wa_fadeOut(this);
                keyImageFader.fadeIn();
                youGotAKeyTextFader.fadeIn();
                this.isWaitingForActionToComplete = true;
                state = QAControllerState.exitting2;
            }
        }

        if (state == QAControllerState.exitting2)
        {
            if (!isWaitingForActionToComplete)
            {
                levelRef.playSound(winSound);
                elapsedTime = 0.0f;
                state       = QAControllerState.exitting3;
            }
        }

        if (state == QAControllerState.exitting3)
        {
            elapsedTime += Time.deltaTime;
            if (elapsedTime > 2.0f)
            {
                secondFader.setFadeValue(1.0f);
                secondFader.setFadeColor(0, 0, 0);
                secondFader._wa_fadeOut(this);
                this.isWaitingForActionToComplete = true;
                state = QAControllerState.exitting4;
            }
        }

        if (state == QAControllerState.exitting4)
        {
            string rLoc = mcRef.getStorage().retrieveStringValue("ReturnLocation");
            string lvl  = rLoc.Substring(0, 6);

            if (isWaitingForActionToComplete)
            {
            }
            else
            {
                switch (keyChannel)
                {
                case 0:
                    mcRef.getStorage().storeBoolValue("Has" + lvl + "RedKey", true);
                    break;

                case 1:
                    mcRef.getStorage().storeBoolValue("Has" + lvl + "OrangeKey", true);
                    break;

                case 2:
                    mcRef.getStorage().storeBoolValue("Has" + lvl + "BlueKey", true);
                    break;

                case 3:
                    mcRef.getStorage().storeBoolValue("Has" + lvl + "GreenKey", true);
                    break;

                case 4:
                    mcRef.getStorage().storeBoolValue("Has" + lvl + "YellowKey", true);
                    break;

                case 5:
                    mcRef.getStorage().storeBoolValue("Has" + lvl + "PurpleKey", true);
                    break;

                case 6:
                    mcRef.getStorage().storeBoolValue("Has" + lvl + "BrownKey", true);
                    break;
                }
                mcRef.getStorage().storeBoolValue("IsHUDCracked", false);                   // return HUD crack to non-crcked

                // increment number of keys
                string curLev = mcRef.getStorage().retrieveStringValue("CurrentLevel");
                int    n      = mcRef.getStorage().retrieveIntValue(curLev + "NumberOfKeys");
                ++n;
                mcRef.getStorage().storeIntValue(curLev + "NumberOfKeys", n);
                SceneManager.LoadScene(rLoc);
            }
        }
    }