Esempio n. 1
0
    void HitCheck()
    {
        if (canMove)
        {
            int            index    = 0;
            RaycastHit2D[] rayArray = new RaycastHit2D[4];

            foreach (Transform t in transform)
            {
                rayArray[index] = Physics2D.Linecast(t.position, t.position + ((GridSize.scale / 2) + 0.05f) * Vector3.down, minoLayer);
                index++;
            }

            foreach (RaycastHit2D r in rayArray)
            {
                if (r)
                {
                    sm.PlaySFX(sm.audioList[8]);
                    canFall = false;
                    canMove = false;
                    if (PosToCoor(transform.position.x, gs.gridWidth) >= 5)
                    {
                        Camera.main.GetComponent <Animator>().SetBool("playRight", true);
                    }
                    else
                    {
                        Camera.main.GetComponent <Animator>().SetBool("playLeft", true);
                    }
                    foreach (Transform t in transform)
                    {
                        int xCoor = PosToCoor(t.position.x, gs.gridWidth);
                        int yCoor = PosToCoor(t.position.y, gs.gridHeight);
                        t.gameObject.layer = 9;
                        if (xCoor >= 0 && xCoor < gs.gridWidth && yCoor >= 0 && yCoor < gs.gridHeight)
                        {
                            g.grid[xCoor, yCoor] = t;
                        }
                        if (t.position.y > (GridSize.scale * (gs.gridHeight - 1) / 2f))
                        {
                            gameOver = true;
                            break;
                        }
                    }
                    CheckRow();
                    StartCoroutine(HitCheckPlayer());


                    g.FindHighestPoint();
                    foreach (Transform t in transform)
                    {
                        t.GetComponent <SpriteRenderer>().sprite   = white;
                        t.GetComponent <BoxCollider2D>().isTrigger = false;
                    }
                    break;
                }
            }
        }
    }
Esempio n. 2
0
    void HitCheck()
    {
        if (canMove)
        {
            int            index    = 0;
            RaycastHit2D[] rayArray = new RaycastHit2D[4];

            foreach (Transform t in transform)
            {
                rayArray[index] = Physics2D.Linecast(t.position, t.position + ((GridSize.scale / 2) + 0.05f) * Vector3.down, minoLayer);
                index++;
            }

            foreach (RaycastHit2D r in rayArray)
            {
                if (r)
                {
                    sm.PlaySFX(sm.audioList[8]);
                    canFall = false;
                    canMove = false;
                    if (PosToCoor(transform.position.x, gs.gridWidth) >= 5)
                    {
                        Camera.main.GetComponent <Animator>().SetBool("playRight", true);
                    }
                    else
                    {
                        Camera.main.GetComponent <Animator>().SetBool("playLeft", true);
                    }
                    foreach (Transform t in transform)
                    {
                        int xCoor = PosToCoor(t.position.x, gs.gridWidth);
                        int yCoor = PosToCoor(t.position.y, gs.gridHeight);
                        t.gameObject.layer = 9;
                        if (xCoor >= 0 && xCoor < gs.gridWidth && yCoor >= 0 && yCoor < gs.gridHeight)
                        {
                            g.grid[xCoor, yCoor] = t;
                        }
                        if (t.position.y > (GridSize.scale * (gs.gridHeight - 1) / 2f))
                        {
                            gameOver = true;
                            sm.PlaySFX(sm.audioList[5]);
                            StartCoroutine(FindObjectOfType <SoundManager>().FadeOut(FindObjectOfType <AudioSource>(), 0.1f, 1f));
                            break;
                        }
                    }
                    int a = FindObjectOfType <GridScript>().CheckRow();

                    if (a == 0)
                    {
                        SpawnMino();
                    }
                    else if (a == 1)
                    {
                        sm.PlaySFX(sm.audioList[1]);
                    }
                    else if (a == 2 || a == 3)
                    {
                        sm.PlaySFX(sm.audioList[2]);
                    }
                    else
                    {
                        sm.PlaySFX(sm.audioList[3]);
                    }
                    StartCoroutine(HitCheckPlayer());

                    /*for(int i=0;i<gs.gridWidth;i++)
                     * {
                     *  for (int j = 0; j < gs.gridHeight; j++)
                     *  {
                     *      if(g.grid[i, j]!=null)
                     *      {
                     *          Debug.Log(new Vector2(i, j));
                     *      }
                     *  }
                     * }*/

                    g.FindHighestPoint();
                    foreach (Transform t in transform)
                    {
                        t.GetComponent <SpriteRenderer>().sprite   = white;
                        t.GetComponent <BoxCollider2D>().isTrigger = false;
                    }
                    break;
                }
            }
        }
    }