Пример #1
0
    private void incorrectSwipingBeyondTarget(GameObject preFlower, GameObject curFlower)
    {
        BWFlower curFlowerObj = curFlower.GetComponent <BWFlower>();
        BWFlower preFlowerObj = preFlower.GetComponent <BWFlower>();

        if (numberToFind > 0)
        {
            if (curFlowerObj.getFlowerNumber() == preFlowerObj.getFlowerNumber() + 1)
            {
                BWFlower flowerObj = curFlower.GetComponent <BWFlower>();
                beeToFlower(flowerObj.getFlowerNumber());

                addTracingLine(preFlower, curFlower);
                prevFlower    = curFlower;
                currentAnswer = false;
            }
        }
        else if (numberToFind < 0)
        {
            if (curFlowerObj.getFlowerNumber() + 1 == preFlowerObj.getFlowerNumber())
            {
                BWFlower flowerObj = curFlower.GetComponent <BWFlower>();
                beeToFlower(flowerObj.getFlowerNumber());

                addTracingLine(preFlower, curFlower);
                prevFlower    = curFlower;
                currentAnswer = false;
            }
        }
    }
Пример #2
0
    void FingerGestures_OnFingerDragBegin(int fingerIndex, Vector2 fingerPos, Vector2 startPos)
    {
        if (!touchEnabled)
        {
            return;
        }

        CancelInvoke("noInteraction");
        CancelInvoke("deduceResult");

        BWTutorialLayer tutorialScript = tutorialLayer.GetComponent <BWTutorialLayer>();

        tutorialScript.stopAnimation();

        GameObject selection = PickObject(startPos);

        if (selection == null || dragFingerIndex != -1)
        {
            return;
        }
        //Scrolling begins
        if (selection == scrollCollider)
        {
            if (!enableScrolling)
            {
                return;
            }
            dragFingerIndex = fingerIndex;
            isDragging      = true;
        }
        else if (isSelectionFlower(selection))
        {
            BWFlower flowerObj = selection.GetComponent <BWFlower>();
            if (expectedNumbers != null && expectedNumbers.Count > 0 && flowerObj.getFlowerNumber() == (int)expectedNumbers[0])
            {
                //beeToFlower((int)expectedNumbers[0]);
                dragFingerIndex = fingerIndex;
                isSwiping       = true;
                swipingWentOut  = false;
                currentAnswer   = true;
                expectedNumbers.RemoveAt(0);

                prevFlower = selection;
            }
            else
            {
                //if started from incorrect flower

                if (flowerObj.getFlowerNumber() == beeStartingPoint + numberToFind)
                {
                    playHintSound(1);
                }
                else
                {
                    playHelpSound();
                }
            }
        }
    }
Пример #3
0
    void FingerGestures_OnFingerTap(int fingerIndex, Vector2 fingerPos, int tapCount)
    {
//		Debug.Log( "tapping");
        if (!touchEnabled)
        {
            return;
        }

        CancelInvoke("noInteraction");
        Invoke("noInteraction", BWConstants.idleTime);

        GameObject selection = PickObject(fingerPos);

        if (isSelectionFlower(selection))
        {
            playSoundEffect("Bee_flowertap_new_01");

            BWFlower flowerObj = selection.GetComponent <BWFlower>();

            attempts++;

            if (flowerObj.getFlowerNumber() == numberToFind)
            {
                AGGameState.incrementStarCount();

                CancelInvoke("noInteraction");
                touchEnabled = false;
                flowerObj.setSelected();
                beeToFlower(numberToFind);
                gameState = BWGameState.BWGameStateGuessed;
                //nextQuestion();
            }
            else
            {
                flowerObj.setSelected();
                playWrongSound(flowerObj.getFlowerNumber());
                BWBee beeObj = bee.GetComponent <BWBee>();
                beeObj.playNoAnimation();
            }
        }
        else
        {
            BWBee beeObj = bee.GetComponent <BWBee>();

            if (selection == beeObj.body || selection == bubbleNumber)
            {
                voiceOverSource.clip = null;
                voiceOverSource.Stop();

                currentClips = new List <AudioClip>();
                playInstructionSound();

                beeObj.playTapAnimation();
            }
        }
    }
Пример #4
0
 public GameObject flowerWithNumber(int number)
 {
     foreach (GameObject flower in flowers)
     {
         BWFlower flowerObj = flower.GetComponent <BWFlower>();
         if (flowerObj.getFlowerNumber() == number)
         {
             return(flower);
         }
     }
     return(null);
 }
Пример #5
0
    void FingerGestures_OnFingerDragEnd(int fingerIndex, Vector2 fingerPos)
    {
        if (!touchEnabled)
        {
            return;
        }

        CancelInvoke("noInteraction");
        Invoke("noInteraction", BWConstants.idleTime);


        if (fingerIndex == dragFingerIndex)
        {
            dragFingerIndex = -1;
            isDragging      = false;


            if (isSwiping)
            {
                //Swiping

                isSwiping = false;

                GameObject selection = PickObject(fingerPos);

                if (selection != null && (selection.name.StartsWith("Flower") || selection.name.StartsWith("Hive")))
                {
                    BWFlower flowerObj = selection.GetComponent <BWFlower>();
                    if (expectedNumbers.Count > 0 && flowerObj.getFlowerNumber() == (int)expectedNumbers[0] && swipingWentOut)
                    {
                        beeToFlower((int)expectedNumbers[0]);
                        expectedNumbers.RemoveAt(0);
                        addTracingLine(prevFlower, selection);
                        prevFlower = selection;
                    }
                    else if (expectedNumbers.Count == 0 && swipingWentOut)
                    {
                        incorrectSwipingBeyondTarget(prevFlower, selection);
                    }
                }
            }

            if (expectedNumbers.Count == 0)
            {
                if (currentAnswer == true)
                {
                    prevFlower = null;

                    CancelInvoke("noInteraction");

                    AGGameState.incrementStarCount();

                    attempts++;
                    playSucess();
                    BWBee beeObj = bee.GetComponent <BWBee>();
                    beeObj.playYesAnimation();

                    if (dataManager.calculateResult(attempts, 1))
                    {
                        beeObj.shouldPlayCelebration = true;
                        dataManager.fetchLevelData();
                    }
                    touchEnabled = false;

                    BWFlowersLayer layerObj  = flowersLayer.GetComponent <BWFlowersLayer>();
                    GameObject     flower    = layerObj.flowerWithNumber(beeStartingPoint + numberToFind);
                    BWFlower       flowerObj = flower.GetComponent <BWFlower>();
                    flowerObj.setPollinated();
                }
                else
                {
                    touchEnabled = false;
                    attempts++;
                    playWrongSound(0);
                    BWBee beeObj = bee.GetComponent <BWBee>();
                    beeObj.playNoAnimation();
                    prevFlower = null;

                    CancelInvoke("noInteraction");
                    Invoke("noInteraction", BWConstants.idleTime + 5.0f);
                }
            }
            else
            {
                if (prevFlower != null)
                {
                    BWFlower flowerObj   = prevFlower.GetComponent <BWFlower>();
                    int      newStarting = flowerObj.getFlowerNumber();
                    setExpectedNumbers(newStarting, numberToFind - (newStarting - beeStartingPoint));
                }
            }
        }

        if (prevFlower != null)
        {
            CancelInvoke("deduceResult");
            Invoke("deduceResult", 3.0f);
        }
    }
Пример #6
0
    void FingerGestures_OnFingerDragMove(int fingerIndex, Vector2 fingerPos, Vector2 delta)
    {
        if (!touchEnabled)
        {
            return;
        }


        if (fingerIndex == dragFingerIndex)
        {
            //Scrolling
            if (isDragging)
            {
                if (enableTypeWriter)
                {
                    GameObject selection = PickObject(fingerPos);
                    if ((numberToFind > 0 && delta.x > 0) ||
                        (numberToFind < 0 && delta.x < 0) ||
                        (!isSelectionFlower(selection)))
                    {
                        xvel       = 0;
                        lasty      = 0;
                        direction  = BounceDirection.BounceDirectionStayingStill;
                        isDragging = false;
                        return;
                    }
                }

                // update the position by converting the current screen position of the finger to a world position on the Z = 0 plane
                Vector3 curPos = flowersLayer.transform.position;
                curPos.x += delta.x;

                float offset = (float)(Math.Tan(BWConstants.diagonalAngle)) * delta.x;
                curPos.y += offset;

                flowersLayer.transform.position = curPos;
                backgroundLayer.moveBackground(delta.x);
                foregroundLayer.moveForeground(delta.x);
            }
            else if (isSwiping)
            {
                //Swiping

                GameObject selection = PickObject(fingerPos);

                if (isSelectionFlower(selection))
                {
                    //checking for type writer scroll
                    if (prevFlower == selection)
                    {
                        if (flowerOnTheEdge(selection))
                        {
                            enableTypeWriter = true;
                            isDragging       = true;
                        }
                        else
                        {
                            enableTypeWriter = false;
                            isDragging       = false;
                        }
                    }                     //check for tracing lines
                    else
                    {
                        enableTypeWriter = false;
                        isDragging       = false;

                        BWFlower flowerObj = selection.GetComponent <BWFlower>();
                        if (expectedNumbers.Count > 0 && flowerObj.getFlowerNumber() == (int)expectedNumbers[0] && swipingWentOut)
                        {
                            playSoundEffect("Bee_flowertap_new_01");

                            beeToFlower((int)expectedNumbers[0]);
                            playNumberSound((int)expectedNumbers[0] - beeStartingPoint);

                            swipingWentOut = false;
                            expectedNumbers.RemoveAt(0);
                            addTracingLine(prevFlower, selection);
                            prevFlower = selection;
                        }
                        else if (expectedNumbers.Count == 0 && swipingWentOut)
                        {
                            playSoundEffect("Bee_flowertap_new_01");
                            incorrectSwipingBeyondTarget(prevFlower, selection);
                        }
                        else if (expectedNumbers.Count > 0 && swipingWentOut)
                        {
                            int rand = UnityEngine.Random.Range(2, 4);
                            playHintSound(rand);
                        }
                    }
                }
                else
                {
                    enableTypeWriter = false;
                    isDragging       = false;

                    //either the selection is null or selection is scrollcollider - so swiping went out
                    swipingWentOut = true;

                    //check for auto scroll
                    Vector3 curPosition = GetWorldPos(fingerPos);

                    if (numberToFind > 0 && curPosition.x > 560)
                    {
                        if (flowerOnTheEdge(prevFlower))
                        {
                            //auto scroll
                            BWFlower prevFlowerObj        = prevFlower.GetComponent <BWFlower>();
                            int      lastNumberRegistered = prevFlowerObj.getFlowerNumber();

                            if (lastNumberRegistered == dataManager.numberLineMax)
                            {
                                return;
                            }

                            int numberToScrollTo = lastNumberRegistered - 1;

                            if (numberToScrollTo < dataManager.numberLineMin)
                            {
                                numberToScrollTo = dataManager.numberLineMin;
                            }
                            if (numberToScrollTo + BWConstants.numbersOnScreen > dataManager.numberLineMax)
                            {
                                numberToScrollTo = dataManager.numberLineMax - BWConstants.numbersOnScreen;
                            }

                            Debug.Log("scroll to " + numberToScrollTo);
                            flowerLayerToInitialNumber(numberToScrollTo);
                        }
                    }
                    else if (numberToFind < 0 && curPosition.x < -560)
                    {
                        if (flowerOnTheEdge(prevFlower))
                        {
                            //auto scroll
                            BWFlower prevFlowerObj        = prevFlower.GetComponent <BWFlower>();
                            int      lastNumberRegistered = prevFlowerObj.getFlowerNumber();

                            if (lastNumberRegistered == dataManager.numberLineMin)
                            {
                                return;
                            }

                            int numberToScrollTo = lastNumberRegistered - 6;

                            if (numberToScrollTo < dataManager.numberLineMin)
                            {
                                numberToScrollTo = dataManager.numberLineMin;
                            }

                            if (numberToScrollTo + BWConstants.numbersOnScreen > dataManager.numberLineMax)
                            {
                                numberToScrollTo = dataManager.numberLineMax - BWConstants.numbersOnScreen;
                            }
                            Debug.Log("scroll to " + numberToScrollTo);
                            flowerLayerToInitialNumber(numberToScrollTo);
                        }
                    }
                }
            }
        }
    }
Пример #7
0
    void FingerGestures_OnFingerTap(int fingerIndex, Vector2 fingerPos, int tapCount)
    {
        if (!touchEnabled)
        {
            return;
        }
//		Debug.Log( "tapping");

        /*
         * GameObject selection = PickObject(fingerPos);
         * if(selection == null) return;
         * //Debug.Log(selection);
         * if(selection.name.StartsWith("Flower") || selection.name.StartsWith("Hive")) {
         *
         * }*/

        GameObject selection = PickObject(fingerPos);

        if (selection == null)
        {
            return;
        }

        BWBee beeObj = bee.GetComponent <BWBee>();

        CancelInvoke("noInteraction");
        Invoke("noInteraction", BWConstants.idleTime);

        if (prevFlower != null)
        {
            CancelInvoke("deduceResult");
            Invoke("deduceResult", 3.0f);
        }

        if (selection == beeObj.body || selection == bubbleNumber)
        {
            voiceOverSource.clip = null;
            voiceOverSource.Stop();

            currentClips = new List <AudioClip>();
            playInstructionSound();

            beeObj.playTapAnimation();

            playTutorialAnimation();

            CancelInvoke("noInteraction");
            Invoke("noInteraction", BWConstants.idleTime + 5.0f);

            if (prevFlower != null)
            {
                CancelInvoke("deduceResult");
                Invoke("deduceResult", 8.0f);
            }
        }
        else
        {
            if (isSelectionFlower(selection))
            {
                BWFlower flowerObj = selection.GetComponent <BWFlower>();

                if (flowerObj.getFlowerNumber() == beeStartingPoint + numberToFind)
                {
                    playHintSound(1);
                }
                else
                {
                    playHintSound(-1);
                }
            }
        }
    }