コード例 #1
0
    // Use this for initialization
    void Start()
    {
        cam = Camera.main.GetComponent <CameraShake>();
        //headfill
        fillAmount = 10;

        for (int i = 0; i < joints.Length - 1; i++)
        {
            allBodyParts[i] = joints[i];
            JointPiece j = joints[i].GetComponent <JointPiece>();
            j.index = i;
            j.owner = gameObject;
        }

        health = Settings.playerHealth;

        slowLength    = Settings.playerOnEnemyTrailSpeedLength;
        speedupLength = Settings.playerOnFriendlyTrailSpeedLength;

        speed         = Settings.playerSpeed;
        rotationSpeed = Settings.playerRotSpeed;
        maxRotSpeed   = Settings.playerMaxRotSpeed;

        distBetweenTrails  = Settings.decayDistance;
        lastPlacedTrailPos = transform.position;

        decayCost        = Settings.drainSpeedPerTrail;
        trailDecayLength = Settings.decayLength;
    }
コード例 #2
0
 void OnCollisionEnter2D(Collision2D other)
 {
     if (other.gameObject.tag == "Joint")
     {
         JointPiece j = other.gameObject.GetComponent <JointPiece>();
         if (j.hooked && j.owner != gameObject && j.index != -1)
         {
             j.owner.GetComponent <playerMovement>().breakChain(j.index);
         }
     }
 }
コード例 #3
0
ファイル: Seeker.cs プロジェクト: KasperHdL/NGJ-2015
 void OnTriggerEnter2D(Collider2D coll)
 {
     if (coll.gameObject.tag == "Joint")
     {
         JointPiece j = coll.gameObject.GetComponent <JointPiece>();
         if (!j.hooked && j.owner == player.gameObject)
         {
             player.hook(j);
         }
     }
 }
コード例 #4
0
    public void breakChain(int index)
    {
        if (index < tailLength - 1)
        {
            Debug.Log("break " + index);
            HingeJoint2D j = joints[index].GetComponent <HingeJoint2D>();


            joints[index].GetComponent <JointPiece>().fillAmount -= 15f;

            for (int i = 0; i < 50; i++)
            {
                instantTrail(joints[index].transform, new Vector3(Random.Range(-2f, 2f), Random.Range(-2f, 2f), 0));
            }

            if (joints[index + 1] != null && joints[index + 1].tag != "Follower")
            {
                JointPiece piece = joints[index + 1].GetComponent <JointPiece>();
                piece.startCooldown();
            }

            for (int i = index + 1; i < tailLength; i++)
            {
                if (joints[i] != null)
                {
                    JointPiece piece = joints[i].GetComponent <JointPiece>();
                    if (piece != null)
                    {
                        piece.index = -1;
                        piece.playSound();
                    }
                }
                joints[i] = null;
            }

            tailLength = index + 1;

            cam.startShake(.5f, .5f);

            seeker.SetActive(true);
            seeker.transform.position = j.transform.position;
            j.connectedBody           = seeker.rigidbody2D;

            checkSeeker(j);
        }
    }
コード例 #5
0
    public void hook(JointPiece j)
    {
        joints[tailLength] = j.gameObject;
        j.index            = tailLength;
        j.hooked           = true;
        j.owner            = gameObject;
        GameObject g = joints[tailLength - 1];

        if (g != null)
        {
            joints[tailLength - 1].GetComponent <HingeJoint2D>().connectedBody = j.rigidbody2D;
        }

        HingeJoint2D curJoint = j.GetComponent <HingeJoint2D>();

        //repopulate array with any parts hanging to it
        int i = tailLength + 1;

        for (; i < 7; i++)
        {
            g = curJoint.connectedBody.gameObject;
            if (g.tag == "Follower")
            {
                joints[i] = g;
                break;
            }

            curJoint = g.GetComponent <HingeJoint2D>();

            if (curJoint == null)
            {
                break;
            }

            joints[i] = curJoint.gameObject;
        }
        tailLength = i + 1;

        bool foundFollower = false;

        i = 0;
        for (; i < 7; i++)
        {
            if (joints[i] == null)
            {
                Debug.Log(player_name + " : " + i);
                HingeJoint2D hinge = joints[i - 1].GetComponent <HingeJoint2D>();

                seeker.transform.position = hinge.transform.position;
                hinge.connectedBody       = seeker.rigidbody2D;
                break;
            }
            else if (joints[i].gameObject.tag == "Follower")
            {
                foundFollower = true;
                break;
            }
        }
        if (foundFollower)
        {
            seeker.SetActive(false);
        }
    }
コード例 #6
0
    public void calcFill()
    {
        float curFill  = 0;
        float nextFill = 0;

        JointPiece curJoint  = null;
        JointPiece nextJoint = null;

        for (int i = tailLength - 1; i >= 0; i--)
        {
            //special cases
            if (joints[i] == null)
            {
                updateColor();

                return;
            }
            if (joints[i].tag != "Follower")
            {
                curJoint = joints[i].GetComponent <JointPiece>();
            }


            if (i == 0)
            {
                nextFill = fillAmount;
            }
            else
            {
                nextJoint = joints[i - 1].GetComponent <JointPiece>();
                nextFill  = nextJoint.fillAmount;
            }

            if (nextFill < Settings.partFillCapacity)
            {
                //push to next

                //set current
                if (joints[i].tag == "Follower")
                {
                    curFill = sponge.amountFilled;
                }
                else
                {
                    curFill = curJoint.fillAmount;
                }

                if (curFill + nextFill > Settings.partFillCapacity)
                {
                    //if it will result in an overflow
                    float overflow = (nextFill + curFill) % Settings.partFillCapacity;

                    //set the next
                    if (i == 0)
                    {
                        fillAmount = Settings.partFillCapacity;
                    }
                    else
                    {
                        nextJoint.fillAmount = Settings.partFillCapacity;
                    }


                    if (joints[i].tag == "Follower")
                    {
                        sponge.amountFilled = overflow;
                    }
                    else
                    {
                        curJoint.fillAmount = overflow;
                    }
                }
                else
                {
                    //set the next
                    if (i == 0)
                    {
                        fillAmount = curFill + nextFill;
                    }
                    else
                    {
                        nextJoint.fillAmount = curFill + nextFill;
                    }


                    if (joints[i].tag == "Follower")
                    {
                        sponge.amountFilled = 0;
                    }
                    else
                    {
                        curJoint.fillAmount = 0;
                    }
                }
            }

            if (joints[i].tag == "Follower")
            {
                sponge.updateColor();
            }
            else
            {
                if (curJoint == null)
                {
                    Debug.Log(i + " wth");
                }
                else
                {
                    curJoint.updateColor();
                }
            }
        }
        //update head
        updateColor();
    }