Example #1
0
        void CheckAnswer()
        {
            PipeAnswer pipeAnswer = game.pipesAnswerController.GetCurrentPipeAnswer();

            if (pipeAnswer != null && Enabled)
            {
                bool isCorrectAnswer = pipeAnswer.IsCorrectAnswer;

                if (isCorrectAnswer)
                {
                    game.Context.GetAudioManager().PlaySound(Sfx.LetterHappy);
                }
                else
                {
                    game.Context.GetAudioManager().PlaySound(Sfx.LetterSad);
                }

                if (onAnswered != null)
                {
                    onAnswered(currentQuestionPack, isCorrectAnswer);
                }

                pipeAnswer.StopSelectedAnimation();
            }
        }
Example #2
0
        public void Initialize(ToboganGame game)
        {
            this.game = game;

            currentPipeAnswer = null;

            HidePipes();

            game.Context.GetInputManager().onPointerDown += OnPointerDown;
        }
Example #3
0
        void Update()
        {
            if (!dragging)
            {
                NearTube = null;
            }
            Vector3 targetScale;
            Vector3 targetPosition = transform.position;

            if (Sucked)
            {
                transform.localScale = Vector3.Lerp(transform.localScale, Vector3.zero, 10.0f * Time.deltaTime);
                transform.position  += Vector3.up * Time.deltaTime * 20;
            }
            else
            {
                if (dragging)
                {
                    targetPosition = targetDragPosition;
                }
                if (NearTube != null)
                {
                    float yScale = 1.3f * (1 + 0.1f * Mathf.Cos(Time.realtimeSinceStartup * 3.14f * 6));

                    targetScale = 0.75f * new Vector3(1 / yScale, yScale, 1);

                    targetPosition = NearTube.tutorialPoint.position - ContentOffset;

                    targetPosition.y = Mathf.Lerp(targetPosition.y, maxY, 2.0f * Mathf.Abs(targetPosition.x - transform.position.x));
                }
                else
                {
                    targetScale = Vector3.one;
                }

                transform.localScale = Vector3.Lerp(transform.localScale, targetScale, 15.0f * Time.deltaTime);
                transform.position   = Vector3.Lerp(transform.position, targetPosition, 25.0f * Time.deltaTime);

                if (isFalling)
                {
                    // Linear fall
                    transform.position = ClampPositionToStage(transform.position + Vector3.down * 20 * Time.deltaTime);
                }
            }

            boxCollider.size = new Vector3(colliderStartScale.x * letter.Scale, colliderStartScale.y, colliderStartScale.z);
        }
Example #4
0
        public void SetPipeAnswers(IEnumerable <ILivingLetterData> wrongAnswers, ILivingLetterData correctAnswers, bool sunMoonQuestion)
        {
            // Selecting auto-hiding signs
            toHide.Clear();
            for (int i = 0; i < pipeAnswers.Length; ++i)
            {
                if (Random.value + 0.0001f < hidingProbability)
                {
                    toHide.Add(pipeAnswers[i]);
                }
            }

            hideSignsTimer = 1.5f + 0.5f * toHide.Count;
            HidePipes();

            currentPipeAnswer = null;

            List <ILivingLetterData> wrongs = new List <ILivingLetterData>();

            foreach (ILivingLetterData answer in wrongAnswers)
            {
                wrongs.Add(answer);
            }

            int answersCount = wrongs.Count + 1;

            if (answersCount > 4)
            {
                answersCount = 4;
            }

            if (sunMoonQuestion)
            {
                int correctIndex = 0;
                int wrongIndex   = 1;

                if (correctAnswers.Id == "the_sun")
                {
                    correctIndex = 1;
                    wrongIndex   = 0;
                }

                pipeAnswers[correctIndex].SetAnswer(correctAnswers, true, game.drawingMaterial, Color.black);
                pipeAnswers[correctIndex].active   = true;
                pipeAnswers[correctIndex].ShowSign = true;

                pipeAnswers[wrongIndex].SetAnswer(wrongs[0], false, game.drawingMaterial, Color.black);
                pipeAnswers[wrongIndex].active   = true;
                pipeAnswers[wrongIndex].ShowSign = true;
            }
            else
            {
                int correctPosition = Random.Range(0, answersCount);

                for (int i = 0; i < answersCount; i++)
                {
                    if (i == correctPosition)
                    {
                        pipeAnswers[i].SetAnswer(correctAnswers, true,
                                                 ToboganGame.I.Difficulty <= 0.1f ? game.markedTextMaterial : game.textMaterial,
                                                 ToboganGame.I.Difficulty <= 0.1f ? (Color)ToboganGame.LETTER_MARK_PIPE_COLOR : Color.black);
                    }
                    else
                    {
                        int wrongIndex = Random.Range(0, wrongs.Count);

                        pipeAnswers[i].SetAnswer(wrongs[wrongIndex], false, game.textMaterial, Color.black);

                        wrongs.RemoveAt(wrongIndex);
                    }

                    pipeAnswers[i].active   = true;
                    pipeAnswers[i].ShowSign = true;
                }
            }
        }
Example #5
0
        void UpdateCurrentPipeAnswer()
        {
            var currentLivingLetter = game.questionsManager.GetQuestionLivingLetter();

            if (currentLivingLetter == null)
            {
                currentPipeAnswer = null;
                return;
            }

            PipeAnswer newPipeAnswer = null;

            Vector3?letterPosition = currentLivingLetter.TargetContentDragPosition;

            if (!letterPosition.HasValue)
            {
                currentPipeAnswer            = null;
                currentLivingLetter.NearTube = null;
                return;
            }

            float pipeDistanceX = float.PositiveInfinity;
            float pipeDistanceY = float.PositiveInfinity;

            for (int i = 0; i < pipeAnswers.Length; i++)
            {
                if (pipeAnswers[i].active)
                {
                    Vector3 pipePosition    = pipeAnswers[i].tutorialPoint.position;
                    float   newPipeDistance = Mathf.Abs(pipePosition.x - letterPosition.Value.x);

                    if (newPipeDistance < pipeDistanceX)
                    {
                        newPipeAnswer = pipeAnswers[i];
                        pipeDistanceX = newPipeDistance;
                        pipeDistanceY = Mathf.Abs(pipePosition.y - letterPosition.Value.y);
                    }
                }
            }

            if (pipeDistanceX > maxLetterDistanceX || pipeDistanceY > maxLetterDistanceY)
            {
                currentLivingLetter.NearTube = null;

                if (currentPipeAnswer != null)
                {
                    currentPipeAnswer.StopSelectedAnimation();
                    currentPipeAnswer = null;
                }
            }
            else
            {
                if (currentPipeAnswer != null && currentPipeAnswer != newPipeAnswer)
                {
                    currentPipeAnswer.StopSelectedAnimation();
                    currentPipeAnswer = null;
                }

                currentLivingLetter.NearTube = currentPipeAnswer;

                if (currentPipeAnswer == null)
                {
                    if (newPipeAnswer != null)
                    {
                        newPipeAnswer.PlaySelectedAnimation();
                    }

                    currentPipeAnswer = newPipeAnswer;
                }
            }
        }