Beispiel #1
0
 void Start()
 {
     pc            = GetComponent <playerController>();
     startLocation = transform.position;
     following     = null;
     followedBy    = null;
 }
Beispiel #2
0
    public void breakChain(bool hurt = false, int chainLength = 0)
    {
        //Once the chain has started breaking we must recursively break every link
        //We use breakingChain because we have a half second coroutine delay
        breakingChain = false;
        if (followedBy)
        {
            followedBy.breakChain(hurt, chainLength);
        }
        following  = null;
        followedBy = null;

        switch (groundAction)
        {
        //This is for collecting starFragments
        case Actions.CheckFive:
            if (chainLength >= 5)
            {
                GameObject starSwirler = GameObject.Find("StarSwirler");
                if (!starSwirler)
                {
                    Debug.LogWarning("No star swirler!");
                }
                else
                {
                    transform.parent = starSwirler.transform;
                    enabled          = false;
                }
            }
            else
            {
                SoundManager.Instance.playClip("Collectibles/dropStarShards");
            }
            break;

        case Actions.Collect:
            if (!hurt)
            {
                collectiblesController cc = GetComponent <collectiblesController>();
                if (cc)
                {
                    cc.collect();
                    enabled = false;
                }
            }
            break;

        default:
            break;
        }
    }
Beispiel #3
0
    void Update()
    {
        //Here we trigger to resolve what happens when the player touches the ground
        //or gets hurt
        if (!breakingChain && pc && followedBy && (pc.isGrounded() || pc.resetPosition))
        {
            breakingChain = true;

            followController fc = this;
            int num;
            for (num = 0; fc.followedBy != null; num++)
            {
                fc = fc.followedBy;
            }
            StartCoroutine(callBreakChain(pc.resetPosition, num));
        }

        //Either we follow who we are following. Or we reset to the original position
        //canMoveParent means that this followController can move the object it's attached to
        if (canMoveParent)
        {
            Vector3 targetLocation = transform.position;
            if (!following)
            {
                targetLocation     = startLocation;
                transform.position = Vector3.SmoothDamp(transform.position, targetLocation, ref smoothVelocity, 0.2f);

                //We need to check the distance to the startPosition so that we can
                //reset canCollect
                if (!canCollect && Vector3.SqrMagnitude(transform.position - targetLocation) < 0.5f)
                {
                    canCollect = true;
                }
            }
            else
            {
                targetLocation = following.transform.position;

                //We use disance to space the collectibles from each other while they follow
                //the player
                if (Vector3.SqrMagnitude(transform.position - following.transform.position) > 0.5f)
                {
                    transform.position = Vector3.SmoothDamp(transform.position, targetLocation, ref smoothVelocity, 0.2f);
                }
            }
        }
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        List <Collider2D> hitters = new List <Collider2D>();

        other.GetContacts(hitters);

        //Because the hitboxes appear as children, we have to filter AllyHitboxes out
        //Otherwise you could get hurt by whacking brambles or something
        //We can probably use this to implement hitlag when hurting things..
        foreach (Collider2D h in hitters)
        {
            if (h.tag == "AllyHitbox")
            {
                continue;
            }

            //if (other.transform.tag == "ResetDamaging" && !invulnerable)
            //{
            //    if (graceFrames > 0)
            //    {
            //        graceFrames--;
            //    }
            //    else
            //    {
            //        resetPosition = true;
            //    }
            //}
            if (intangibleStates.Contains(state))
            {
                return;
            }

            //if (other.gameObject.layer == LayerMask.NameToLayer("Danger") && !invulnerable)
            //{
            //    if (other.CompareTag("ResetDamaging") && graceFrames > 0) return;
            //    startBonk(1, resetPosition);
            //    return;
            //}

            if (other.tag == "Tornado" && canTornado)
            {
                resetAnimator();
                SoundManager.Instance.playClip("LevelObjects/EnterTornado");
                canTornado     = false;
                state          = State.Tornado;
                currentTornado = other.transform;
                Deformer nadoDeformer = other.GetComponent <Deformer>();
                if (nadoDeformer)
                {
                    nadoDeformer.startDeform(new Vector3(1.75f, .75f, 1.0f), 0.1f);
                }
            }

            if (other.CompareTag("Door"))
            {
                if (other.GetComponent <doorController>().enterable)
                {
                    currentDoor = other.GetComponent <doorController>();
                }
            }


            if (other.tag == "Follower")
            {
                followController other_fc = other.GetComponent <followController>();
                if (!other_fc.canCollect)
                {
                    return;
                }

                int numFollowers = 0;
                other_fc.following            = getFollower(GetComponent <followController>());
                other_fc.following.followedBy = other_fc;
                other_fc.canCollect           = false;

                followController getFollower(followController fc)
                {
                    if (!fc.followedBy)
                    {
                        return(fc);
                    }
                    else
                    {
                        numFollowers++;
                        return(getFollower(fc.followedBy));
                    }
                }

                SoundManager.Instance.playClip("Collectibles/starShard", numFollowers);
            }

            if (other.CompareTag("BroomCollectible") && state == State.Broom && hanger.childCount == 0)
            {
                other.transform.parent   = hanger;
                other.transform.position = hanger.position - Vector3.up * 0.15f;
                other.SendMessage("BroomPickUp");
            }

            if (other.CompareTag("Water"))
            {
                steps.isSubmerged = true;
            }
        }
    }