Beispiel #1
0
    IEnumerator BallCountTextShow(int greenBallCount)
    {
        //초록공 합쳐지기 전후 공 개수 보여주기
        BallCountTextObj.transform.position = new Vector3(Mathf.Clamp(veryFirstPos.x, -49.9f, 49.9f), -65, 0);
        BallCountText.text = "x" + BallGroup.childCount.ToString();

        yield return(new WaitForSeconds(0.17f));

        if (BallGroup.childCount > score)
        {
            Destroy(BallGroup.GetChild(BallGroup.childCount - 1).gameObject);
        }
        BallCountText.text = "x" + BallGroup.childCount.ToString();

        // 바닥에 떨어진 초록공 +로 표시하기
        if (greenBallCount != 0)
        {
            BallPlusTextObj.SetActive(true);
            BallPlusTextObj.transform.position = new Vector3(Mathf.Clamp(veryFirstPos.x, -49.9f, 49.9f), -47, 0);
            BallPlusText.text = "+" + greenBallCount.ToString();
            S_Plus.Play();

            yield return(new WaitForSeconds(0.5f));

            BallPlusTextObj.SetActive(false);
        }
    }
Beispiel #2
0
 private void FixedUpdate()
 {
     if (timerStart && ++timerCount == 3)
     {
         timerCount = 0;
         BallGroup.GetChild(launchIndex++).GetComponent <Ball>().Launch(gap);
         BallCountText.text = "x" + (BallGroup.childCount - launchIndex).ToString();
         if (launchIndex == BallGroup.childCount)
         {
             timerStart         = false;
             launchIndex        = 0;
             BallCountText.text = "";
         }
     }
 }
Beispiel #3
0
 void FixedUpdate_GM()
 {
     // 0.06초 간격으로 공발사
     if (timerStart && ++timerCount == 3)
     {
         timerCount = 0;
         BallGroup.GetChild(launchIndex++).GetComponent <OneCommand>().Launch(gap);
         BallCountText.text = "x" + (BallGroup.childCount - launchIndex).ToString();
         if (launchIndex == BallGroup.childCount)// 모든 볼을 발사했을때
         {
             timerStart         = false;
             launchIndex        = 0;
             BallCountText.text = "";
         }
     }
 }
Beispiel #4
0
    public void Update_GM()
    {
        if (isDie)
        {
            return;
        }

        //마우스 첫번째 좌표
        if (Input.GetMouseButtonDown(0))
        {
            firstPos = Camera.main.ScreenToWorldPoint(Input.mousePosition) + new Vector3(0, 0, 10);
        }

        // 모든 움직임이 끝나면 쏠 수 있음
        shotable = true;
        for (int i = 0; i < BallGroup.childCount; i++)
        {
            if (BallGroup.GetChild(i).GetComponent <OneCommand>().isMoving)
            {
                shotable = false;
            }
        }
        if (isBlockMoving)
        {
            shotable = false;
        }

        if (!shotable)
        {
            return;
        }

        // 모든 공이 바닥에 부딪히면 한 번 실행
        if (shotTrigger && shotable)
        {
            shotTrigger = false;
            BlockGenerator();
            timeDelay = 0;

            StartCoroutine(BallCountTextShow(GreenBallGroup.childCount));
            for (int i = 0; i < GreenBallGroup.childCount; i++)
            {
                StartCoroutine(GreenBallMove(GreenBallGroup.GetChild(i)));
            }
        }

        timeDelay += Time.deltaTime;
        if (timeDelay < 0.1f)
        {
            return;                   // 0.1초 딜레이로 너무 빠르게 손떼면 라인이 남는 버그 제거
        }
        bool isMouse = Input.GetMouseButton(0);

        if (isMouse)
        {
            // 차이값
            secondPos = Camera.main.ScreenToWorldPoint(Input.mousePosition) + new Vector3(0, 0, 10);
            if ((secondPos - firstPos).magnitude < 1)
            {
                return;
            }
            gap = (secondPos - firstPos).normalized;
            gap = new Vector3(gap.y >= 0 ? gap.x : gap.x >= 0 ? 1 : -1, Mathf.Clamp(gap.y, 0.2f, 1), 0);

            //화살표, 공 미리보기
            Arrow.transform.position       = veryFirstPos;
            Arrow.transform.rotation       = Quaternion.Euler(0, 0, Mathf.Atan2(gap.y, gap.x) * Mathf.Rad2Deg);
            BallPreview.transform.position =
                Physics2D.CircleCast(new Vector2(Mathf.Clamp(veryFirstPos.x, -54, 54), groundY), 1.7f, gap, 10000, 1 << LayerMask.NameToLayer("Wall") | 1 << LayerMask.NameToLayer("Block")).centroid;

            RaycastHit2D hit = Physics2D.Raycast(veryFirstPos, gap, 10000, 1 << LayerMask.NameToLayer("Wall"));
            // 라인
            MouseLR.SetPosition(0, firstPos);
            MouseLR.SetPosition(1, secondPos);
            BallLR.SetPosition(0, veryFirstPos);
            BallLR.SetPosition(1, (Vector3)hit.point - gap * 1.5f);
        }
        BallPreview.SetActive(isMouse);
        Arrow.SetActive(isMouse);

        if (Input.GetMouseButtonUp(0))
        {
            if ((secondPos - firstPos).magnitude < 1)
            {
                return;
            }
            // 라인 초기화
            MouseLR.SetPosition(0, Vector3.zero);
            MouseLR.SetPosition(1, Vector3.zero);
            BallLR.SetPosition(0, Vector3.zero);
            BallLR.SetPosition(1, Vector3.zero);

            timerStart   = true;
            veryFirstPos = Vector3.zero;
            firstPos     = Vector3.zero;
        }
    }
Beispiel #5
0
    IEnumerator BlockMoveDown(Transform TR)
    {
        yield return(new WaitForSeconds(0.2f));

        Vector3 targetPos = TR.position + new Vector3(0, -12.8f, 0);

        BlockColorChange();

        // 마지막 줄이면 게임오버 트리거, 콜라이더 비활성화
        if (targetPos.y < -50)
        {
            if (TR.CompareTag("Block"))
            {
                isDie = true;
            }
            for (int i = 0; i < BallGroup.childCount; i++)
            {
                BallGroup.GetChild(i).GetComponent <CircleCollider2D>().enabled = false;
            }
        }

        // 0.3 초간 블럭 이동
        float TT = 1.5f;

        while (true)
        {
            yield return(null); TT -= Time.deltaTime * 1.5f;
            TR.position             = Vector3.MoveTowards(TR.position, targetPos + new Vector3(0, -6, 0), TT);
            if (TR.position == targetPos + new Vector3(0, -6, 0))
            {
                break;
            }
        }
        TT = 0.9f;
        while (true)
        {
            yield return(null); TT -= Time.deltaTime;
            TR.position             = Vector3.MoveTowards(TR.position, targetPos, TT);
            if (TR.position == targetPos)
            {
                break;
            }
        }
        isBlockMoving = false;

        // 이동되고 난 후 마지막줄이면 & 블럭이면 게임오버, 초록구면 파괴
        if (targetPos.y < -50)
        {
            if (TR.CompareTag("Block"))
            {
                for (int i = 0; i < BallGroup.childCount; i++)
                {
                    Destroy(BallGroup.GetChild(i).gameObject);
                }
                Destroy(Instantiate(P_ParticleBlue, veryFirstPos, QI), 1);

                BallCountTextObj.SetActive(false);
                BallPlusTextObj.SetActive(false);
                BestScoreText.gameObject.SetActive(false);
                ScoreText.gameObject.SetActive(false);

                GameOverPanel.SetActive(true);
                FinalScoreText.text = "최종점수 : " + score.ToString();
                if (isNewRecord)
                {
                    NewRecordText.gameObject.SetActive(true);
                }

                Camera.main.GetComponent <Animator>().SetTrigger("shake");
                S_GameOver.Play();
            }
            else
            {
                Destroy(TR.gameObject);
                Destroy(Instantiate(P_ParticleGreen, TR.position, QI), 1);

                for (int i = 0; i < BallGroup.childCount; i++)
                {
                    BallGroup.GetChild(i).GetComponent <CircleCollider2D>().enabled = true;
                }
            }
        }
    }
Beispiel #6
0
    // Update is called once per frame
    void Update()
    {
        // 죽으면 실행 안함
        if (isDie)
        {
            return;
        }

        //클릭하면 클릭한 지점을 저장
        if (Input.touchCount > 0 || Input.GetMouseButtonDown(0) && firstPos == Vector3.zero)
        {
            if (!EventSystem.current.IsPointerOverGameObject() || !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
            {
                firstPos = Camera.main.ScreenToWorldPoint(Input.mousePosition) + new Vector3(0, 0, 10);
            }
        }


        shotable = true;
        //볼이 움직이고 있으면 쏠 수 없음
        for (int i = 0; i < BallGroup.childCount; i++)
        {
            if (BallGroup.GetChild(i).GetComponent <Ball>().isMoving)
            {
                shotable = false;
            }
        }

        //블럭이 내려올때 쏠 수 없음
        if (isBlockMoving)
        {
            shotable = false;
        }

        //쏠 수 없으면 실행안함
        if (!shotable)
        {
            return;
        }

        //
        if (shotTrigger && shotable)
        {
            shotTrigger = false;
            if (!ice)
            {
                BlockGenerator();
            }
            else
            {
                ice = false;
            }
            timeDelay = 0;


            for (int i = 0; i < GreenBallGroup.childCount; i++)
            {
                StartCoroutine(GreenBallMove(GreenBallGroup.GetChild(i)));
            }
            StartCoroutine(BallCountTextShow(GreenBallGroup.childCount));

            if (coinObtain == 3)
            {
                COcount++;
                if (COcount >= 5)
                {
                    COcount    = 0;
                    coinObtain = 1;
                }
            }

            if (shadow)
            {
                shadow = false;
                for (int i = 0; i < BallGroup.childCount / 2; i++)
                {
                    Destroy(BallGroup.GetChild(i).gameObject);
                }
                BallCountText.text = "x" + BallGroup.childCount.ToString();
            }
            if (gold)
            {
                gold = false;
            }
        }

        //
        timeDelay += Time.deltaTime;
        if (timeDelay < 0.1f)
        {
            return;
        }

        //입력
        bool isMouse = Input.GetMouseButton(0);

        if (Input.touchCount > 0 || isMouse)
        {
            if (!EventSystem.current.IsPointerOverGameObject() || !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
            {
                if (isGBallMove)
                {
                    isGBallMove = false;
                    for (int i = 0; i < GreenBallGroup.childCount; i++)
                    {
                        StartCoroutine(GreenBallMove(GreenBallGroup.GetChild(i)));
                    }
                    StartCoroutine(BallCountTextShow(GreenBallGroup.childCount));
                }

                secondPos = Camera.main.ScreenToWorldPoint(Input.mousePosition) + new Vector3(0, 0, 10);
                if ((secondPos - firstPos).magnitude < 1)
                {
                    return;
                }

                gap = (secondPos - firstPos).normalized;
                gap = new Vector3(gap.y >= 0 ? gap.x : gap.x >= 0 ? 1 : -1, Mathf.Clamp(gap.y, 0.2f, 1), 0);

                Arrow.transform.position       = veryFirstPos;
                Arrow.transform.rotation       = Quaternion.Euler(0, 0, Mathf.Atan2(gap.y, gap.x) * Mathf.Rad2Deg);
                BallPreview.transform.position =
                    Physics2D.CircleCast(new Vector2(Mathf.Clamp(veryFirstPos.x, -54, 54), groundY), 1.7f, gap, 10000, 1 << LayerMask.NameToLayer("Wall") | 1 << LayerMask.NameToLayer("Block")).centroid;

                RaycastHit2D hit1 = Physics2D.Raycast(veryFirstPos, gap, 10000, 1 << LayerMask.NameToLayer("Wall"));

                MouseLR.SetPosition(0, firstPos);
                MouseLR.SetPosition(1, secondPos);
                BallLR.SetPosition(0, veryFirstPos);
                BallLR.SetPosition(1, (Vector3)hit1.point - gap * 1.5f);
            }
        }
        else
        {
            isGBallMove = true;
        }

        //터치중 일때 표시선 온
        BallPreview.SetActive(isMouse && !EventSystem.current.IsPointerOverGameObject() || Input.touchCount > 0 && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId));
        Arrow.SetActive(isMouse && !EventSystem.current.IsPointerOverGameObject() || Input.touchCount > 0 && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId));

        //터치를 땟을때 초기화
        if (Input.touchCount > 0 || Input.GetMouseButtonUp(0))
        {
            Debug.Log("hi");

            if (!EventSystem.current.IsPointerOverGameObject() || !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
            {
                Debug.Log("bye");
                if ((secondPos - firstPos).magnitude < 1)
                {
                    return;
                }

                MouseLR.SetPosition(0, Vector3.zero);
                MouseLR.SetPosition(1, Vector3.zero);
                BallLR.SetPosition(0, Vector3.zero);
                BallLR.SetPosition(1, Vector3.zero);

                timerStart   = true;
                veryFirstPos = Vector3.zero;
                firstPos     = Vector3.zero;
            }
        }
    }