Beispiel #1
0
    public JointRef AddJoint(SpringJoint2D joint, BallScriptPointer connectedBall)
    {
        JointRef jointref = new JointRef(this, joint, connectedBall);

        joints.Add(jointref);
        return(jointref);
    }
Beispiel #2
0
    public JointRef AddJoint(SpringJoint2D joint)
    {
        JointRef jointref = new JointRef(this, joint);

        joints.Add(jointref);
        if (this.GetJointsCount() == 6)
        {
            ball.GetComponent <Rigidbody2D>().Sleep();
        }
        return(jointref);
    }
    void OnCollisionEnter2D(Collision2D coll)
    {
        // Check if more then 6 connected balls,
        // not allow to create more
        if (BallScriptPtr.GetJointsCount() > 6)
        {
#if UNITY_EDITOR
            Debug.Log("too many connects!!!");
#endif
            GetComponent <Renderer>().material.color = Color.black;
            return;
        }


        // Creating new joint to the other ball
        if (coll.gameObject.tag == "Ball")
        {
            foreach (JointRef jointref in BallScriptPtr.GetJoints())
            {
                if (jointref.connectedBall.getGameObject() == coll.gameObject)
                {
#if UNITY_EDITOR
                    Debug.Log("it connected!!!");
#endif

                    return;
                }
            }

            //Debug.Log ("New joint");
            SpringJoint2D joint = gameObject.AddComponent <SpringJoint2D> ();
            joint.connectedBody = coll.gameObject.GetComponent <Rigidbody2D>();
            joint.distance      = 2.56f;
            joint.frequency     = 0;

//			if(GameSetting.Instance.IsGame){
            //ContactPoint2D contact = coll.contacts[0];
            //IGame.Instance.bangbang (contact.point);
            //Instantiate (GameSetting.Instance.particleShockWave, contact.point, Quaternion.identity);
            //TODO: azazazaza tut iskri ot udarov
//			}

            JointRef newjointref = BallScriptPtr.AddJoint(joint);

            if (BallScriptPtr.color == BALLTYPE.BOMB && armor >= 0)
            {
                if (!newjointref.connectedBall.getBall().isbasic)
                {
                    setBang(0);
                }
            }

            if (BallScriptPtr.color == BALLTYPE.MOVEDOWN && armor >= 0)
            {
                if (!newjointref.connectedBall.getBall().isbasic)
                {
                    setBang(0);
                    IGame.Instance.BonusBallsBanged(15);
                }
            }

            DFS.dfs.addBall(BallScriptPtr);

            ConnectToBallsInDistance(2.87f);
        }

        //		if (coll.gameObject.tag == "Wheel") {
        //
        //			//Debug.Log ("New joint");
        //			//HingeJoint2D joint = gameObject.AddComponent<HingeJoint2D> ();
        //			//joint.connectedBody = coll.gameObject.rigidbody2D;
        //
        //
        //			transform.position.Set(coll.gameObject.transform.parent.position.x, coll.gameObject.transform.parent.position.y+2.56f, coll.gameObject.transform.parent.position.z);
        //
        //
        //			transform.RotateAround(coll.gameObject.transform.parent.position, Vector3.forward, coll.gameObject.transform.localRotation.z);
        //
        //			gameObject.rigidbody2D.isKinematic = true;
        //
        //
        //		}
    }
    public void ConnectToBallsInDistance(float distance = 3.1f)
    {
//		Debug.Log (Time.time + ": " + ball.getGameObject().name + ": " + ball.getPosition ().ToString());

//		Vector3 vector = new Vector3(2.56f, 0, 0);
        foreach (BallScriptPointer pball in IGame.Instance.BallList)
        {
            if (pball == BallScriptPtr)
            {
                continue;
            }
            if (!pball.getGameObject().activeSelf)
            {
                continue;
            }

//			Debug.Log (Time.time + ": " + ball.getGameObject().name + ": From:" + ball.getPosition () +
////			           " To:" + (ball.getPosition () + vector).ToString() +
//			           "To: " + pball.getGameObject().name +
//			           " " + (pball.getPosition()).ToString() +
//			           " Distance:" + Vector2.Distance(pball.getPosition(), ball.getPosition ()).ToString()
//			           );
            if (Vector2.Distance(pball.getPosition(), BallScriptPtr.getPosition()) < distance)
            {
                bool getthatshit = false;
                foreach (JointRef jointref in BallScriptPtr.GetJoints())
                {
                    if (jointref.connectedBall.getGameObject() == pball.getGameObject())
                    {
                        getthatshit = true;
                        break;
                    }
                }
                if (!getthatshit)
                {
//					Debug.Log (Time.time + ": " + pball.getGameObject ().name + " Adding kinematic connect ");
                    SpringJoint2D joint = gameObject.AddComponent <SpringJoint2D> ();
                    joint.connectedBody = pball.getGameObject().GetComponent <Rigidbody2D>();
                    joint.distance      = 2.56f;
                    joint.frequency     = 0;
                    JointRef newjointref = BallScriptPtr.AddJoint(joint);
                    if (BallScriptPtr.color == BALLTYPE.BOMB)
                    {
                        if (!newjointref.connectedBall.getBall().isbasic)
                        {
                            BallScriptPtr.getBall().setBang(0);
                        }
                    }

                    if (BallScriptPtr.color == BALLTYPE.MOVEDOWN && armor >= 0)
                    {
                        if (!newjointref.connectedBall.getBall().isbasic)
                        {
                            BallScriptPtr.getBall().setBang(0);
                            IGame.Instance.BonusBallsBanged(15);
                        }
                    }
                    DFS.dfs.addBall(BallScriptPtr);
                }

                getthatshit = false;
                foreach (JointRef jointref in pball.GetJoints())
                {
                    if (jointref.connectedBall.getGameObject() == BallScriptPtr.getGameObject())
                    {
                        getthatshit = true;
                        break;
                    }
                }
                if (!getthatshit)
                {
//					Debug.Log (Time.time + ": " + pball.getGameObject ().name + " Adding kinematic connect BACK");
                    SpringJoint2D joint = pball.getGameObject().AddComponent <SpringJoint2D> ();
                    joint.connectedBody = gameObject.GetComponent <Rigidbody2D>();
                    joint.distance      = 2.56f;
                    joint.frequency     = 0;
                    JointRef newjointref = pball.AddJoint(joint);
                    if (pball.color == BALLTYPE.BOMB)
                    {
                        if (!newjointref.connectedBall.getBall().isbasic)
                        {
                            pball.getBall().setBang(0);
                        }
                    }

                    if (pball.color == BALLTYPE.MOVEDOWN && armor >= 0)
                    {
                        if (!newjointref.connectedBall.getBall().isbasic)
                        {
                            pball.getBall().setBang(0);
                            IGame.Instance.BonusBallsBanged(15);
                        }
                    }
                    DFS.dfs.addBall(pball);
                }
            }
        }
    }
Beispiel #5
0
 public void RemoveJoint(JointRef jointref)
 {
     joints.Remove(jointref);
 }