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);
                    }
                }
            }
        }
    }
Пример #2
0
 public JointRef(BallScriptPointer ball, SpringJoint2D joint, BallScriptPointer connectedBall)
 {
     this.deletemyself  = false;
     this.ball          = ball;
     this.joint         = joint;
     this.connectedBall = connectedBall;
 }
Пример #3
0
    public JointRef AddJoint(SpringJoint2D joint, BallScriptPointer connectedBall)
    {
        JointRef jointref = new JointRef(this, joint, connectedBall);

        joints.Add(jointref);
        return(jointref);
    }
Пример #4
0
 public JointRef(BallScriptPointer ball, SpringJoint2D joint)
 {
     this.deletemyself  = false;
     this.ball          = ball;
     this.joint         = joint;
     this.connectedBall = (joint.connectedBody.gameObject.GetComponent <BallScript>()).BallScriptPtr;
 }
Пример #5
0
//	#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define
//	#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define
//	#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define
//	#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define
//	#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define

    public virtual bool InPull(BallScriptPointer pball, List <BallScriptPointer> list)
    {
        bool result = false;

        list.Add(pball);

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

            if (!(list.Contains(joint.connectedBall)))
            {
                if (joint.connectedBall.getGameObject().GetComponent <Rigidbody2D> ().isKinematic)
                {
                    return(true);
                }
                result = InPull(joint.connectedBall, list);
                if (result)
                {
                    return(result);
                }
            }
        }

        return(result);
    }
    // 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;
    }
Пример #7
0
 void OnTriggerStay2D(Collider2D other)
 {
     if (on && other.tag == "Ball")
     {
         pball     = (other.gameObject.GetComponent("BallScript") as BallScript).BallScriptPtr;
         needcheck = true;
     }
 }
 // Use this for initialization
 void Awake()
 {
     isbang        = false;
     bangtime      = 0f;
     BallScriptPtr = new BallScriptPointer(this);
     IGame.Instance.BallList.Add(BallScriptPtr);
     gameObject.name = "Ball:" + IGame.Instance.BallList.Count;
     gameObject.SetActive(false);
 }
Пример #9
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);
    }
Пример #12
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);
    }
Пример #13
0
    // Update is called once per frame
    void Update()
    {
        if (GameSetting.Instance.IsGameFinished())
        {
            return;
        }
        if (GameSetting.Instance.IsGamePaused())
        {
            bStartAim = false;
            return;
        }

//		if (Input.GetMouseButtonUp (1)) {
//			Vector2 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
//			//Camera.main.ScreenToViewportPoint (Input.mousePosition);
//			main.Main.newBall (pos, false);
//		}


        if (fLastClickTime < (Time.time - 0.33f))
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (IGame.Instance.ChangeColorBox.GetComponent <Collider2D>().OverlapPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition)))
                {
                    IGame.Instance.ChangeColor();
                }
                else
                {
                    vStartPos = Camera.main.ScreenToViewportPoint(Input.mousePosition);
                    bStartAim = true;
                }
            }

            if (Input.GetMouseButtonUp(0) && bStartAim)
            {
                bStartAim = false;
                Vector2 finish_pos = Camera.main.ScreenToViewportPoint(Input.mousePosition);
                Vector2 pos        = new Vector2(0.0f, 18.5f);
                Vector2 force      = finish_pos - vStartPos;
                Debug.Log("Force = " + force + " sqrt = " + force.sqrMagnitude);
                if (force.sqrMagnitude > .0001f)
                {
                    BallScriptPointer pball = IGame.Instance.newBall(pos, false);
                    IGame.Instance.Turn();

                    force *= 20000f;
                    if (force.y > 0)
                    {
                        force = -force;
                    }
                    if (force.y < -10000f)
                    {
                        force.y = -10000f;
                    }
                    if (force.y > -1000f)
                    {
                        force.y = -1000f;
                    }

                    if (force.x > 8000f)
                    {
                        force.x = 8000f;
                    }
                    if (force.x < -8000f)
                    {
                        force.x = -8000f;
                    }

                    pball.getGameObject().GetComponent <Rigidbody2D>().AddForce(force);

                    fLastClickTime = Time.time;
                }
            }
        }
    }
 public void addBall(BallScriptPointer pball)
 {
     balls.Enqueue(pball);
 }
Пример #15
0
 void Start()
 {
     on        = true;
     needcheck = false;
     pball     = null;
 }