public void InputDetected(TileBrain a, Vector2 dir)
    {
        //Debug.Log("ID: " + a + " in Direction " + dir);
        string number = a.name.Substring(4);
        int x = Convert.ToInt32(number[0].ToString());
        int y = Convert.ToInt32(number[1].ToString());

        int x2 = x - (int)dir.y;
        int y2 = y + (int)dir.x;

        GameObject b = AllTilesX[x2, y2];

        //Debug.Log(b.name);

        AllTilesX[x, y] = b;
        AllTilesY[y, x] = b;

        AllTilesX[x2, y2] = a.gameObject;
        AllTilesY[y2, x2] = a.gameObject;

        Vector2 posa = a.gameObject.transform.position;
        a.gameObject.transform.position = b.transform.position;
        b.transform.position = posa;

        string aname = a.name;

        a.name = b.name;
        b.name = aname;
        //if (PerformCheck())
        //    InputDetected(a, -dir);

        Check();
    }
예제 #2
0
    public void CheckN()
    {
        n = new List<TileBrain>();
        int oldLayer = gameObject.layer;
        gameObject.layer = LayerMask.NameToLayer("Ghost");
        int layerToIgnore = 1 << gameObject.layer;
        layerToIgnore = ~layerToIgnore;

        Vector2 cast = new Vector2(transform.position.x, transform.position.y);
        RaycastHit2D hit = Physics2D.Raycast(cast, Vector2.down, 0.40f, layerToIgnore);
        if (hit.collider != null)
        {
            hit.transform.gameObject.SendMessage("Hello", new HelloMsg(this, "top"));
        }
        else if (botn != null)
            botn = null;

        cast = new Vector2(transform.position.x, transform.position.y);
        hit = Physics2D.Raycast(transform.position, Vector2.up, 0.40f, layerToIgnore);
        if (hit.collider != null)
        {
            hit.transform.gameObject.SendMessage("Hello", new HelloMsg(this, "bot"));
        }
        else if (topn != null)
            topn = null;

        cast = new Vector2(transform.position.x, transform.position.y);
        hit = Physics2D.Raycast(transform.position, Vector2.left, 0.40f, layerToIgnore);
        if (hit.collider != null)
        {
            hit.transform.gameObject.SendMessage("Hello", new HelloMsg(this, "right"));
        }
        else if (leftn != null)
            leftn = null;

        cast = new Vector2(transform.position.x, transform.position.y);
        hit = Physics2D.Raycast(transform.position, Vector2.right, 0.40f, layerToIgnore);
        if (hit.collider != null)
        {
            hit.transform.gameObject.SendMessage("Hello", new HelloMsg(this, "left"));
        }
        else if (rightn != null)
            rightn = null;

        //if(pbotn != botn)
        //{
        //    MoveOneDown();
        //}

        if (botn != pbotn)
            pbotn = botn;

        gameObject.layer = oldLayer;
    }
예제 #3
0
 public HelloMsg(TileBrain n, string p)
 {
     neighbor = n;
     pos = p;
 }
예제 #4
0
 //private void Destroy(List wh)
 //{
 //    if (wh.chain >= 0)
 //    {
 //        this.gameObject.SetActive(false);
 //        wh.chain--;
 //        EndChain(wh);
 //    }
 //}
 public void Hello(HelloMsg msg)
 {
     switch(msg.pos)
     {
         case "top":
             topn = msg.neighbor;
             topn.change += CheckN;
             break;
         case "bot":
             botn = msg.neighbor;
             botn.change += CheckN;
             break;
         case "left":
             leftn = msg.neighbor;
             leftn.change += CheckN;
             break;
         case "right":
             rightn = msg.neighbor;
             rightn.change += CheckN;
             break;
     }
 }