예제 #1
0
    private void FrogMove(int x, int y)
    {
        if (!cooldown && !GetComponent <FrogTongue>().extendTongue)
        {
            StartCoroutine(MovementCooldown());
            newPosition = newPosition + new Vector2(x, y);
            anim.SetBool("isMoving", true);

            float rotation = 0;

            if (x == 1)
            {
                rotation = 90;
                frogDir  = FrogDirection.RIGHT;
            }
            else if (x == -1)
            {
                rotation = -90;
                frogDir  = FrogDirection.LEFT;
            }

            if (y == 1)
            {
                rotation = 180;
                frogDir  = FrogDirection.UP;
            }
            else if (y == -1)
            {
                rotation = 0;
                frogDir  = FrogDirection.DOWN;
            }

            transform.eulerAngles = new Vector3(0, 0, rotation);

            GetComponent <AudioSource>().PlayOneShot(ribbit);
        }
    }
예제 #2
0
    void Update()
    {
        if (hasItem && (item == null || item.transform.parent != transform))
        {
            hasItem = false;
        }

        if (Input.GetButtonDown(tongueButton) == true && !extendTongue)
        {
            // item not going to the right place !!!! NEEDS FIXING !!!!
            if (hasItem)
            {
                hasItem = false;

                //fire item
                RaycastHit2D tongueBlocker = Physics2D.CircleCast(transform.position, 0.25f, GetComponent <FrogMovement>().GetFrogDirectionVector(), maxTongueLength / 2, ~(1 << gameObject.layer));

                Vector3       newItemPosition = transform.position;
                FrogDirection tongueDir       = GetComponent <FrogMovement>().GetFrogDirection();

                if (tongueBlocker)
                {
                    switch (tongueDir)
                    {
                    case FrogDirection.UP:
                        newItemPosition.y = Mathf.Round(tongueBlocker.point.y) - 0.5f;
                        break;

                    case FrogDirection.DOWN:
                        newItemPosition.y = Mathf.Round(tongueBlocker.point.y) + 0.5f;
                        break;

                    case FrogDirection.LEFT:
                        newItemPosition.x = Mathf.Round(tongueBlocker.point.x) + 0.5f;
                        break;

                    case FrogDirection.RIGHT:
                        newItemPosition.x = Mathf.Round(tongueBlocker.point.x) - 0.5f;
                        break;
                    }
                }
                else
                {
                    switch (tongueDir)
                    {
                    case FrogDirection.UP:
                        newItemPosition.y = transform.position.y + maxTongueLength / 2;
                        break;

                    case FrogDirection.DOWN:
                        newItemPosition.y = transform.position.y - maxTongueLength / 2;
                        break;

                    case FrogDirection.LEFT:
                        newItemPosition.x = transform.position.x - maxTongueLength / 2;
                        break;

                    case FrogDirection.RIGHT:
                        newItemPosition.x = transform.position.x + maxTongueLength / 2;
                        break;
                    }
                }

                item.layer = LayerMask.NameToLayer("Default");
                item.transform.position = newItemPosition;
                item.transform.parent   = null;
                item = null;
            }
            else
            {
                tongue.SetActive(true);
                audioSource.PlayOneShot(frogTongue);
                StartCoroutine(TongueExtend());
            }
        }
        else if (Input.GetButtonUp(tongueButton) == true && extendTongue)
        {
            TongueRetract();
        }

        if (extendTongue)
        {
            float        tongueLength  = Vector3.Distance(tongueTip.position, tonguePivot.transform.position);
            RaycastHit2D tongueBlocker = Physics2D.CircleCast(transform.position, 0.25f, GetComponent <FrogMovement>().GetFrogDirectionVector(), tongueLength, ~(1 << gameObject.layer));

            if (tongueBlocker)
            {
                if (tongueBlocker.collider.tag == "PullItem")
                {
                    hasItem    = true;
                    item       = tongueBlocker.collider.gameObject;
                    item.layer = gameObject.layer;

                    Vector3       newItemPosition = tongueBlocker.transform.position;
                    FrogDirection tongueDir       = GetComponent <FrogMovement>().GetFrogDirection();

                    switch (tongueDir)
                    {
                    case FrogDirection.UP:
                        newItemPosition.y = transform.position.y + 0.5f;
                        break;

                    case FrogDirection.DOWN:
                        newItemPosition.y = transform.position.y - 0.5f;
                        break;

                    case FrogDirection.LEFT:
                        newItemPosition.x = transform.position.x - 0.5f;
                        break;

                    case FrogDirection.RIGHT:
                        newItemPosition.x = transform.position.x + 0.5f;
                        break;
                    }
                    tongueBlocker.transform.parent = transform;

                    tongueBlocker.transform.position = newItemPosition;
                }
                else if (tongueBlocker.collider.tag == "ConsumeItem")
                {
                    item = tongueBlocker.collider.gameObject;

                    //do stuff

                    Destroy(item);
                }
                else
                {
                    float leapFrogMultiplier = 1.0f;

                    if (tongueBlocker.collider.tag == "Frog")
                    {
                        leapFrogMultiplier = 3.0f;
                    }

                    Vector3       newPosition = transform.position;
                    FrogDirection tongueDir   = GetComponent <FrogMovement>().GetFrogDirection();

                    switch (tongueDir)
                    {
                    case FrogDirection.UP:
                        newPosition.y = Mathf.Round(tongueTip.position.y) + 0.5f * leapFrogMultiplier;
                        break;

                    case FrogDirection.DOWN:
                        newPosition.y = Mathf.Round(tongueTip.position.y) - 0.5f * leapFrogMultiplier;
                        break;

                    case FrogDirection.LEFT:
                        newPosition.x = Mathf.Round(tongueTip.position.x) - 0.5f * leapFrogMultiplier;
                        break;

                    case FrogDirection.RIGHT:
                        newPosition.x = Mathf.Round(tongueTip.position.x) + 0.5f * leapFrogMultiplier;
                        break;
                    }

                    transform.position = newPosition;
                }

                TongueRetract();
                audioSource.PlayOneShot(tongueGrab);
            }
        }
    }