// Use this for initialization
    new void Awake()
    {
        base.Awake();
        Bottom9Balls = new List <BallScriptPointer> ();
        foreach (BoxCollider2D bx in WallBottom.GetComponentsInChildren <BoxCollider2D>())
        {
            bx.enabled = false;
        }
        foreach (SpriteRenderer sr in GameObject.Find("BottomWallSprite").GetComponentsInChildren <SpriteRenderer>())
        {
            sr.enabled = false;
        }

        GameSetting.Instance.gridX = 9;
        GameSetting.Instance.gridY = 8;


        for (int y = 0; y < GameSetting.Instance.gridY; y++)
        {
            for (int x = 0; x < GameSetting.Instance.gridX; x++)
            {
                if (y % 3 == 2 && x % 3 == 1)
                {
                    continue;
                }
                Vector2           pos  = new Vector2((x - GameSetting.Instance.gridX / 2 + 0.5f * (y % 2)) * GameSetting.Instance.spacing + 0.64f, -2.56f - 20.5f + GameSetting.Instance.spacing / 2 + y * 2.22f - 2.22f);
                BallScriptPointer ball = newBall(pos, true);

                if (y == 0)
                {
                    Bottom9Balls.Add(ball);
                }

                if (Random.Range(0, 1000) < 10)                 //986
                {
                    ball.setColor(BALLTYPE.BOMB);
                }
                else if (Random.Range(0, 1000) < 5)                 //986
                {
                    ball.setColor(BALLTYPE.MOVEDOWN);
                }
            }
        }

        foreach (BallScriptPointer ball in BallList)
        {
            ball.getBall().ConnectToBallsInDistance(2.87f);
        }

        foreach (BallScriptPointer ball in Bottom9Balls)
        {
            if (ball.getGameObject().activeSelf)
            {
                ball.getBall().GetComponent <Rigidbody2D>().isKinematic = true;
                ball.getBall().armor = -1;
            }
        }
        ShotsFromLastLine = 0;
    }
    void LateUpdate()
    {
        while (balls.Count > 0)
        {
            BallScriptPointer        ball = balls.Dequeue();
            List <BallScriptPointer> gm   = new List <BallScriptPointer> ();
            if (calculateDFS(ball, gm) >= 2)
            {
                bool gonnablow = false;

                foreach (BallScriptPointer pball in gm)
                {
                    if (!pball.getBall().isbasic)
                    {
                        ball.getBall().setBang();
                        gonnablow = true;
                        break;
                    }
                }
                if (gonnablow)
                {
                    foreach (BallScriptPointer pball in gm)
                    {
                        ActiveAnimation.Play(pball.getGameObject().GetComponent <Animation>(), "BallBeamSuper", AnimationOrTween.Direction.Forward);
                    }
                }
            }
        }
    }
Пример #3
0
    public BallScriptPointer newBall(LevelData.CellBall _Cell)
    {
        BallScriptPointer pball = GetFreeBall();

        pball.setPosition(_Cell.position);

        pball.getBall().isbasic = _Cell.basic;
        pball.getBall().armor   = _Cell.armor;
        pball.getBall().GetComponent <Rigidbody2D> ().isKinematic = _Cell.frozen;
        pball.setColor(_Cell.type);

        pball.getGameObject().SetActive(true);

        return(pball);

        //pball.getBall ().isbasic = isbasic ? true : false;
    }
    void AddBallsInNewLine()
    {
        ShotsFromLastLine = 0;

        foreach (BallScriptPointer ball in Bottom9Balls)
        {
            if (ball.getGameObject().activeSelf)
            {
                ball.getBall().GetComponent <Rigidbody2D>().isKinematic = false;
                ball.getBall().armor = 0;
            }
        }

        Bottom9Balls.Clear();
        pair++;
        for (int x = 0; x < GameSetting.Instance.gridX; x++)
        {
            if (pair % 3 == 1 && x % 3 == 1)
            {
                continue;
            }
            Vector2           pos  = new Vector2((x - GameSetting.Instance.gridX / 2 + 0.5f * (pair % 2)) * GameSetting.Instance.spacing + 0.64f, -2.56f - 20.5f + GameSetting.Instance.spacing / 2 - 2.22f);
            BallScriptPointer ball = newBall(pos, true);
            Bottom9Balls.Add(ball);
            ball.getBall().ConnectToBallsInDistance(2.87f);

            if (Random.Range(0, 1000) < 20)             //986
            {
                ball.setColor(BALLTYPE.BOMB);
            }
            else if (Random.Range(0, 1000) < 30)             //986
            {
                ball.setColor(BALLTYPE.MOVEDOWN);
            }
        }
        foreach (BallScriptPointer ball in Bottom9Balls)
        {
            if (ball.getGameObject().activeSelf)
            {
                ball.getBall().GetComponent <Rigidbody2D>().isKinematic = true;
                ball.getBall().armor = -1;
            }
        }
    }
    public int calculateDFS(BallScriptPointer pball, List <BallScriptPointer> list, bool bang = false)
    {
        int result = 0;

        list.Add(pball);

        foreach (JointRef joint in pball.GetJoints())
        {
            if (joint.joint == null)
            {
                continue;
            }

            if (!(list.Contains(joint.connectedBall)))
            {
                if (joint.connectedBall.color == pball.color)
                {
                    result++;
                    result += calculateDFS(joint.connectedBall, list, bang);
                }
            }
        }


        if (bang)
        {
            if (pball.getBall().isbasic)
            {
                IGame.Instance.bangbang(pball.getPosition());
            }
            else
            {
                IGame.Instance.bangbang(pball.getPosition(), false);
            }
            pball.getBall().Killitself();
        }

        return(result);
    }
Пример #6
0
    public BallScriptPointer newBall(Vector3 Position, bool isbasic = false)
    {
        BallScriptPointer pball = GetFreeBall();

        pball.setPosition(Position);

        pball.getBall().Refresh();
        pball.getBall().isbasic = isbasic ? true : false;
        pball.getBall().armor   = 0;
        pball.getBall().GetComponent <Rigidbody2D> ().isKinematic = false;
        if (isbasic)
        {
            pball.setColor(Random.Range(0, (int)BALLTYPE.LASTCOLOR));
        }
        else
        {
            pball.setColor(random_color());
        }

        pball.getGameObject().SetActive(true);

        return(pball);
    }
    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);
                }
            }
        }
    }