Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        timeElapsed += Time.deltaTime;

        if (!gameOver && !betweenLevels)
        {
            return;
        }

        if (!FingerInput.GetInputPresent())
        {
            return;
        }

        if (FingerInput.GetFingerPressed())
        {
            waitingForRelease = true;
        }

        if (waitingForRelease && FingerInput.GetFingerReleased())
        {
            /*if ((betweenLevels && levelFinished) || gameOver)
             *  ResetLevel();*/
            if (betweenLevels)
            {
                levelText.text    = "";
                waitingForRelease = false;
                betweenLevels     = false;
                scoreText.text    = "Candies sorted: " + score.ToString() + "/" + GameMetaInfo.Instance.CandiesInLevel;
                Time.timeScale    = 1f;
                AudioManager.menu.Stop();
                AudioManager.gameplay.Play();
            }
        }
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        /*if (FingerInput.GetFingerPressed())
         * {
         *  pressed = true;
         * }*/

        if (!FingerInput.GetInputPresent() || !FingerInput.GetFingerDown())
        {
            swiped       = false;
            needsRelease = false;
            return;
        }

        if (needsRelease)
        {
            return;
        }

        fingerPos = FingerInput.GetFingerPosition();

        /*if (FingerInput.GetFingerDown())
         * {
         *  fingerPos = FingerInput.GetFingerPosition();
         * }*/

        if (FingerInput.GetFingerPressed())
        {
            touchPos = fingerPos;
        }

        //if (Mathf.Abs(touchPos.y - fingerPos.y) >= minSwipeDistance && pressed)
        if (Mathf.Abs(touchPos.y - fingerPos.y) >= minSwipeDistance && !swiped)
        {
            //pressed = false;
            //if(touchPos.y >= Screen.height / 2)
            if (touchPos.y - fingerPos.y < 0)
            {
                handController.slap();
                swiped = true;
            }
            //else if(touchPos.y < Screen.height / 2)
            else
            {
                handController.premiumCandy();
                swiped = true;
            }
            needsRelease = true;
        }
    }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        timeElapsed += Time.deltaTime;
        if (timeElapsed > message1Duration && timeElapsed <= message1Duration + message2Duration)
        {
            messageBox.text = message2;
        }
        else if (timeElapsed > message1Duration + message2Duration)
        {
            canvas.enabled = false;
        }

        if (!FingerInput.GetInputPresent() || !FingerInput.GetFingerDown())
        {
            timeHeld = 0f;
            if (heldCandy == null)
            {
                return;
            }

            if (heldCandy.tag == "good")
            {
                goodCandies.Remove(heldCandy);
            }
            else
            {
                badCandies.Remove(heldCandy);
            }

            if ((cam.WorldToScreenPoint(heldCandy.transform.position).y >= cam.pixelHeight / 2 ||
                 badCandies.Count >= 9) && goodCandies.Count < 9)
            {
                goodCandies.Add(heldCandy);
                heldCandy.tag = "good";
            }
            else
            {
                badCandies.Add(heldCandy);
                heldCandy.tag = "bad";
            }

            heldCandy = null;
            ArrangeGoodCandies();
            ArrangeBadCandies();
            return;
        }

        Vector3 fingerPos = cam.ScreenToWorldPoint(FingerInput.GetFingerPosition());

        fingerPos.z = 0;
        if (FingerInput.GetFingerPressed())
        {
            holding = true;
            grabPos = fingerPos;
            Vector2      startPoint = fingerPos;
            RaycastHit2D raycastHit = Physics2D.Raycast(startPoint, Vector2.zero);
            if (raycastHit.collider != null)
            {
                heldCandy = raycastHit.collider.gameObject;
            }
        }

        if (heldCandy != null)
        {
            heldCandy.transform.position = fingerPos;
        }

        if (holding)
        {
            if ((grabPos - fingerPos).magnitude > holdMovementTolerance)
            {
                holding = false;
            }
            else
            {
                timeHeld += Time.deltaTime;
                if ((heldCandy != null && timeHeld >= holdDurationOverCandy) ||
                    heldCandy == null && timeHeld >= holdDuration)
                {
                    GoToNewsScreen();
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (GameState.Instance.GameOver || GameState.Instance.BetweenLevels || swipeTime >= candyGenerator.number)
        {
            return;
        }

        // If the user isn't touching the screen, the candy should be released
        if (!FingerInput.GetInputPresent() || !FingerInput.GetFingerDown())
        {
            swiped = false;

            // Gradually move the candy to the center of the screen
            currentCandy.transform.position = Vector3.Lerp(currentCandy.transform.position, objectPos, Time.deltaTime * centerSpeed);

            needsRelease = false;
            return;
        }

        if (needsRelease)
        {
            return;
        }

        fingerPos = FingerInput.GetFingerPosition();

        if (FingerInput.GetFingerPressed())
        {
            touchPos    = fingerPos;
            startPosSet = true;
        }

        if (!startPosSet)
        {
            return;
        }

        if (Mathf.Abs(touchPos.x - fingerPos.x) >= minSwipeDistance && !swiped && swipeTime < candyGenerator.number)
        {
            GameObject candyChild = currentCandy.transform.GetChild(0).gameObject;
            // The user swiped left
            if (touchPos.x - fingerPos.x > 0)
            {
                if (candyChild.tag == "bad")
                {
                    // The user correctly disposed of a bad candy
                    badEffect.Play(true);
                    AudioManager.goodSwipe.Play();
                    GameState.Instance.AddToScore(1);
                }
                else if (candyChild.tag == "good")
                {
                    // The user incorrectly disposed of a good candy
                    goodEffect.Play(true);
                    AudioManager.badSwipe.Play();
                    GameState.Instance.DecrementLives();
                }

                // Check if the user disposed of too many good candies
                if (GameState.Instance.GameOver)
                {
                    return;
                }
            }
            else // The user swiped right
            {
                // The user incorrectly saved a bad candy, poisoning their child and triggering a game over
                if (candyChild.tag == "bad")
                {
                    badEffect.Play(true);
                    GameState.Instance.InvokeGameOver();
                    return;
                }

                // The user correctly saved a good candy
                goodEffect.Play(true);
                AudioManager.goodSwipe.Play();
                GameState.Instance.AddToScore(1);
            }

            // Check if the last candy was swiped
            if (swipeTime == candyGenerator.number - 1)
            {
                candyGenerator.RemoveLast();
                swipeTime++;
                swiped = true;
            }
            else
            {
                if (swipeTime == candyGenerator.number - 2)
                {
                    candyGenerator.RemoveLastInBag();
                    swipeTime++;
                    swiped = true;
                }
                if (swipeTime < candyGenerator.number - 2)
                {
                    candyGenerator.RemoveCandyInBag();
                    swipeTime++;
                    swiped = true;
                }

                // Set current candy to be the new candy pulled from the bag
                currentCandy = GameObject.Find("CurrentCandy");
                currentCandy.transform.position = objectPos;
                needsRelease = true;
            }
        }

        // Update the candy position if the user is swiping
        if (swipeTime < candyGenerator.number && !needsRelease)
        {
            currentCandy.transform.position = objectPos + new Vector3(cam.ScreenToWorldPoint(fingerPos).x - cam.ScreenToWorldPoint(touchPos).x, 0f, 0f);
        }
    }