Ejemplo n.º 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;
            }
        }
    }
Ejemplo n.º 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();
                }
            }
        }
    }
Ejemplo n.º 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();
            }
        }
    }
Ejemplo n.º 4
0
    public void resetCurrentQuestion()
    {
        BWFlowersLayer layer = flowersLayer.GetComponent <BWFlowersLayer>();

        foreach (GameObject flower in layer.flowers)
        {
            BWFlower flowerObj = flower.GetComponent <BWFlower>();
            flowerObj.setDisabled();
        }
    }
Ejemplo n.º 5
0
 public GameObject flowerWithNumber(int number)
 {
     foreach (GameObject flower in flowers)
     {
         BWFlower flowerObj = flower.GetComponent <BWFlower>();
         if (flowerObj.getFlowerNumber() == number)
         {
             return(flower);
         }
     }
     return(null);
 }
Ejemplo n.º 6
0
    public void setDiagonalFlowersLayer(int min, int max, int initial)
    {
        numberLineMax = max;
        numberLineMin = min;
        initialNumber = initial;

        if (flowers != null)
        {
            destroyFlowersLayer();
        }

        float diagonalAngle = BWConstants.diagonalAngle;

        flowers = new ArrayList(numberLineMax - numberLineMin + 1);
        Vector3 pos = new Vector3(85, 0, 0);

        for (int i = numberLineMin; i <= numberLineMax; i++)
        {
            GameObject flower;
            if (i != 0)
            {
                flower = Instantiate(flowerPrefab) as GameObject;
            }
            else
            {
                flower = Instantiate(hivePrefab) as GameObject;
            }

            float yPos = (float)(Math.Tan(diagonalAngle) * pos.x);
            pos.y = yPos;
            flower.transform.parent        = this.transform;
            flower.transform.localPosition = pos;

            pos.x += 170;
            flowers.Add(flower);

            BWFlower flowerObj = flower.GetComponent <BWFlower>();
            flowerObj.setFlowerNumber(i, i - numberLineMin);
            flowerObj.openFlower();
        }

        contentWidth = pos.x - 85;

        tracingLines = new ArrayList();
    }
Ejemplo n.º 7
0
    public void resetFlowersLayer()
    {
        foreach (GameObject flower in flowers)
        {
            BWFlower flowerObj = flower.GetComponent <BWFlower>();
            flowerObj.setDisabled();
        }

        if (tracingLines != null)
        {
            while (tracingLines.Count > 0)
            {
                DestroyObject((GameObject)tracingLines[0]);
                tracingLines.RemoveAt(0);
            }
            tracingLines = new ArrayList();
        }
    }
Ejemplo n.º 8
0
    public void beeMoveFinished()
    {
        if (gameState == BWGameState.BWGameStateGuessed)
        {
            BWBee beeObj = bee.GetComponent <BWBee>();
            beeObj.playYesAnimation();

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

            playSucess();

            BWFlowersLayer layerObj  = flowersLayer.GetComponent <BWFlowersLayer>();
            GameObject     flower    = layerObj.flowerWithNumber(numberToFind);
            BWFlower       flowerObj = flower.GetComponent <BWFlower>();
            flowerObj.setPollinated();
        }
    }
Ejemplo n.º 9
0
    public void destroyFlowersLayer()
    {
        foreach (GameObject flower in flowers)
        {
            BWFlower flowerObj = flower.GetComponent <BWFlower>();
            flowerObj.closeFlower(numberLineMax - numberLineMin - flowerObj.index);
        }

        float delay = (float)(numberLineMax - numberLineMin) * (2.0f / 30.0f) + 6.0f / 30.0f;

        iTween.RotateTo(gameObject, iTween.Hash("time", delay, "onComplete", "allFlowersClosed"));

        if (tracingLines != null)
        {
            while (tracingLines.Count > 0)
            {
                DestroyObject((GameObject)tracingLines[0]);
                tracingLines.RemoveAt(0);
            }
        }
        tracingLines = null;
    }
Ejemplo n.º 10
0
    private void addTracingLine(GameObject preFlower, GameObject curFlower)
    {
        if (preFlower == null || curFlower == null)
        {
            return;
        }

        GameObject tracingLine = Instantiate(linePrefab) as GameObject;

        tracingLine.transform.parent = flowersLayer.transform;

        Vector3 pos = new Vector3(0, 0, 0);

        if (numberToFind > 0)
        {
            pos.x = preFlower.transform.localPosition.x + tracingLine.transform.localScale.x / 2.0f;
            pos.y = preFlower.transform.localPosition.y + 270;
            pos.z = 0;
        }
        else if (numberToFind < 0)
        {
            pos.x = curFlower.transform.localPosition.x + tracingLine.transform.localScale.x / 2.0f;
            pos.y = curFlower.transform.localPosition.y + 270;
            pos.z = 0;
        }
        else
        {
            DestroyObject(tracingLine);
            return;
        }
        tracingLine.transform.localPosition = pos;
        BWFlowersLayer layer = flowersLayer.GetComponent <BWFlowersLayer>();

        layer.tracingLines.Add(tracingLine);

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

        flowerObj.setSelected();
    }
Ejemplo n.º 11
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);
        }
    }
Ejemplo n.º 12
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);
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 13
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);
                }
            }
        }
    }