Ejemplo n.º 1
0
    public void initialSetUp()
    {
        this.blocks = new BlockControl[Block.BLOCK_NUM_X, Block.BLOCK_NUM_Y];
        int color_index = 0;

        for (int y = 0; y < Block.BLOCK_NUM_Y; y++)
        {
            for (int x = 0; x < Block.BLOCK_NUM_X; x++)
            {
                GameObject   game_object = Instantiate(this.BlockPrefab) as GameObject;
                BlockControl block       = game_object.GetComponent <BlockControl>();
                this.blocks[x, y] = block;

                block.i_pos.x = x;
                block.i_pos.y = y;

                block.block_root = this;

                Vector3 position = BlockRoot.calcBlockPosition(block.i_pos);

                block.transform.position = position;

                block.setColor((Block.COLOR)color_index);

                block.name = "block(" + block.i_pos.x.ToString() + "," + block.i_pos.y.ToString() + ")";

                color_index = Random.Range(0, (int)Block.COLOR.NORMAL_COLOR_NUM);
            }
        }
    }
Ejemplo n.º 2
0
    public void InitialSetUp()
    {
        this.blocks = new BlockControl[Block.BLOCK_NUM_X, Block.BLOCK_NUM_Y];
        int color_index = 0;

        for (int y = 0; y < Block.BLOCK_NUM_Y; y++)
        {
            for (int x = 0; x < Block.BLOCK_NUM_X; x++)
            {
                // BlockPrefab의 인스턴스를 씬에 만든다
                GameObject   game_object = Instantiate(this.BlockPrefab) as GameObject;
                BlockControl block       = game_object.GetComponent <BlockControl>();
                this.blocks[x, y] = block;

                block.i_pos.x    = x;
                block.i_pos.y    = y;
                block.block_root = this;

                Vector2 position = BlockRoot.calcBlockPosition(block.i_pos);
                block.transform.position   = position;
                block.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f);
                block.SetColor((Block.COLOR)color_index);
                block.name = "block(" + block.i_pos.x.ToString() + ", " + block.i_pos.y.ToString() + ")";

                color_index = Random.Range(0, SizeManager.colorNum);
            }
        }
    }
Ejemplo n.º 3
0
    // 블록을 만들어 내고 가로 9칸, 세로 9칸에 배치한다.
    public void initialSetUp()
    {
        this.blocks = new BlockControl[Block.BLOCK_NUM_X, Block.BLOCK_NUM_Y]; // 그리드의 크기를 9×9로 한다.
        int color_index = 0;                                                  // 블록의 색 번호.

        Block.COLOR color = Block.COLOR.FIRST;

        for (int y = 0; y < Block.BLOCK_NUM_Y; y++)
        {     // 처음~마지막행
            for (int x = 0; x < Block.BLOCK_NUM_X; x++)
            { // 왼쪽~오른쪽
              // BlockPrefab의 인스턴스를 씬에 만든다.
                GameObject   game_object = Instantiate(this.BlockPrefab) as GameObject;
                BlockControl block       = game_object.GetComponent <BlockControl>(); // 블록의 BlockControl 클래스를 가져온다.
                this.blocks[x, y] = block;                                            // 블록을 그리드에 저장한다.
                block.i_pos.x     = x;                                                // 블록의 위치 정보(그리드 좌표)를 설정한다.
                block.i_pos.y     = y;
                block.block_root  = this;                                             // 각 BlockControl이 연계할 GameRoot는 자신이라고 설정한다.
                Vector3 position = BlockRoot.calcBlockPosition(block.i_pos);          // 그리드 좌표를 실제 위치(씬의 좌표)로 변환
                block.transform.position = position;                                  // 씬의 블록 위치를 이동한다.
                block.setColor((Block.COLOR)color_index);                             // 블록의 색을 변경한다.
                                                                                      // 블록의 이름을 설정(후술)한다. 나중에 블록 정보 확인때 필요.
                                                                                      // block.setColor((Block.COLOR)color_index); // 주석처리혹은삭제한다.
                // 현재출현확률을바탕으로색을결정한다.
                color = this.selectBlockColor();
                block.setColor(color);

                block.name = "block(" + block.i_pos.x.ToString() + "," + block.i_pos.y.ToString() + ")";
                // 전체 색 중에서 임의로 하나의 색을 선택한다.
                color_index = Random.Range(0, (int)Block.COLOR.NORMAL_COLOR_NUM);
            }
        }
    }
Ejemplo n.º 4
0
    // 초기 배치.
    public void             initialSetUp()
    {
        // 블록 생성, 배치.

        this.blocks = new BlockControl[Block.BLOCK_NUM_X, Block.BLOCK_NUM_Y];

        Block.COLOR color = Block.COLOR.FIRST;

        for (int y = 0; y < Block.BLOCK_NUM_Y; y++)
        {
            for (int x = 0; x < Block.BLOCK_NUM_X; x++)
            {
                GameObject game_object = Instantiate(this.blockPrefab) as GameObject;

                BlockControl block = game_object.GetComponent <BlockControl>();

                this.blocks[x, y] = block;

                block.i_pos.x          = x;
                block.i_pos.y          = y;
                block.block_root       = this;
                block.leave_block_root = this.leave_block_root;

                //

                Vector3 position = BlockRoot.calcBlockPosition(block.i_pos);

                block.transform.position = position;

                color = this.selectBlockColor();
                block.setColor(color);

                // 하이어라키 뷰에서 위치를 확인하기 쉽게 블록의 좌표를 이름에 붙여 둔다.
                block.name = "block(" + block.i_pos.x.ToString() + "," + block.i_pos.y.ToString() + ")";
            }
        }

        //

        this.block_islands = new int[Block.BLOCK_NUM_X, Block.BLOCK_NUM_Y];

        for (int y = 0; y < Block.BLOCK_NUM_Y; y++)
        {
            for (int x = 0; x < Block.BLOCK_NUM_X; x++)
            {
                this.block_islands[x, y] = -1;
            }
        }
    }
Ejemplo n.º 5
0
    // 블록을 만들어 내고, 가로 아홉 칸 세로 아홉 칸으로 배치.
    public void initialSetUp()
    {
        // 크기는 9×9로 한다.
        this.blocks =
            new BlockControl[Block.BLOCK_NUM_X, Block.BLOCK_NUM_Y];
        // 블록의 색 번호.
        int color_index = 0;

        Block.COLOR color = Block.COLOR.FIRST;


        for (int y = 0; y < Block.BLOCK_NUM_Y; y++)
        {     // 처음행부터 시작행부터 마지막행까지.
            for (int x = 0; x < Block.BLOCK_NUM_X; x++)
            { // 왼쪽 끝에서부터 오른쪽 끝까지.
             // BlockPrefab의 인스턴스를 씬 위에 만든다.
                GameObject game_object =
                    Instantiate(this.BlockPrefab) as GameObject;
                // 위에서 만든 블록의 BlockControl 클래스를 가져온다.
                BlockControl block = game_object.GetComponent <BlockControl>();
                // 블록을 칸에 넣는다.
                this.blocks[x, y] = block;
                // 블록의 위치 정보(그리드 좌표)를 설정.
                block.i_pos.x = x;
                block.i_pos.y = y;
                // 각 BlockControl이 연계하는 GameRoot는 자신이라고 설정.
                block.block_root = this;
                // 그리드 좌표를 실제 위치(씬 좌표)로 변환.
                Vector3 position = BlockRoot.calcBlockPosition(block.i_pos);
                // 씬 상의 블록 위치를 이동.
                block.transform.position = position;

                // 블록의 색을 변경.
                // block.setColor((Block.COLOR)color_index);
                // 지금의 출현 확률을 바탕으로 색을 결정한다.
                color = this.selectBlockColor();
                block.setColor(color);

                // 블록의 이름을 설정(후술).
                block.name = "block(" + block.i_pos.x.ToString() +
                             "," + block.i_pos.y.ToString() + ")";
                // 모든 종류의 색 중에서 임의로 한 색을 선택.
                color_index =
                    Random.Range(0, (int)Block.COLOR.NORMAL_COLOR_NUM);
            }
        }
    }
    // ブロックを作り出して、横9ます、縦9マスに配置
    public void initialSetUp()
    {
        // マス目のサイズを9×9にする
        this.blocks = new BlockControl[Block.BLOCK_NUM_X, Block.BLOCK_NUM_Y];
        // ブロックの色番号
        int color_index = 0;

        Block.COLOR color = Block.COLOR.FIRST;

        for (int y = 0; y < Block.BLOCK_NUM_Y; y++)     // 先頭行から最終行まで
        {
            for (int x = 0; x < Block.BLOCK_NUM_X; x++) // 左端から右端まで
            {
                // BlockPrefabのインスタンスをシーン上に作る
                GameObject game_object = Instantiate(this.BlockPrefab) as GameObject;
                // 上で作ったブロックのBlockControlクラスを取得
                BlockControl block = game_object.GetComponent <BlockControl>();
                // ブロックをマス目に格納
                this.blocks[x, y] = block;

                // ブロックの位置情報(グリッド座標)を設定
                block.i_pos.x = x;
                block.i_pos.y = y;
                // 各BlockControlが連携するGameRootは自分だと設定
                block.block_root = this;

                // グリッド座標を実際の位置(シーン上の座標)に変換
                Vector3 position = BlockRoot.calcBlockPosition(block.i_pos);
                // シーン上のブロックの位置を移動
                block.transform.position = position;

                // 今の出現確率に基づいて色を決める
                color = this.selectBlockColor();
                block.setColor(color);
                // ブロックの名前を設定(後述)
                block.name = "block(" + block.i_pos.x.ToString() + "," + block.i_pos.y.ToString() + ")";

                // 全種類の色の中から、ランダムに1色を選択
                color_index = Random.Range(0, (int)Block.COLOR.NORMAL_COLOR_NUM);
            }
        }
    }
Ejemplo n.º 7
0
    // 블록을 만들어 내고, 가로9칸 세로9칸에 배치.
    public void initialSetUp()
    {
        // 그리드의 크기를 9×9로 한다.
        this.blocks =
            new BlockControl [Block.BLOCK_NUM_X, Block.BLOCK_NUM_Y];
        // 블록의 색 번호.
        int color_index = 0;

        for (int y = 0; y < Block.BLOCK_NUM_Y; y++)          // 처음부터 마지막행까지.
        {
            for (int x = 0; x < Block.BLOCK_NUM_X; x++)      // 왼쪽부터 오른쪽까지.
            // BlockPrefab의 인스턴스를 씬 상에 만든다.
            {
                GameObject game_object =
                    Instantiate(this.BlockPrefab) as GameObject;
                // 위에서 만든 블록의 BlockControl 클래스를 가져온다.
                BlockControl block = game_object.GetComponent <BlockControl>();
                // 블록을 그리드에 저장.
                this.blocks[x, y] = block;
                // 블록의 위치 정보(그리도 좌표)를 설정.
                block.i_pos.x = x;
                block.i_pos.y = y;
                // 각 BlockControl이 연계할 GameRoot는 자신이라고 설정.
                block.block_root = this;
                // 그리도 좌표를 실제 위치(씬 상의 좌표)로 변환.
                Vector3 position = BlockRoot.calcBlockPosition(block.i_pos);
                // 씬 상의 블록 위치를 이동.
                block.transform.position = position;
                // 블록의 색을 변경.
                block.setColor((Block.COLOR)color_index);
                // 블록의 이름을 설정(후술).
                block.name = "block(" + block.i_pos.x.ToString() +
                             "," + block.i_pos.y.ToString() + ")";
                // 전체 색 중에서 임의로 하나의 색을 선택.
                color_index =
                    Random.Range(0, (int)Block.COLOR.NORMAL_COLOR_NUM);
            }
        }
    }
Ejemplo n.º 8
0
    void Update()
    {
        Vector3 mouse_position;                                                          // マウスの位置

        this.block_root.unprojectMousePosition(out mouse_position, Input.mousePosition); // マウスの位置を取得

        // 取得したマウス位置をXとYだけにする
        Vector2 mouse_position_xy = new Vector2(mouse_position.x, mouse_position.y);

        if (this.vanish_timer >= 0.0f)             // タイマーが0以上なら
        {
            this.vanish_timer -= Time.deltaTime;   // タイマーの値を減らす
            if (this.vanish_timer < 0.0f)          // タイマーが0未満なら
            {
                if (this.step != Block.STEP.SLIDE) // スライド中でないなら
                {
                    this.vanish_timer = -1.0f;
                    this.next_step    = Block.STEP.VACANT; // 状態を「消滅中」に
                }
                else
                {
                    this.vanish_timer = 0.0f;
                }
            }
        }
        this.step_timer += Time.deltaTime;
        float slide_time = 0.2f;

        if (this.next_step == Block.STEP.NONE) // 「状態情報なし」の場合
        {
            switch (this.step)
            {
            case Block.STEP.SLIDE:
                if (this.step_timer >= slide_time)
                {
                    // スライド中にブロックが消滅したら、VACANT(消える)状態に移行
                    if (this.vanish_timer == 0.0f)
                    {
                        this.next_step = Block.STEP.VACANT;
                    }
                    else     // vanish_timerが0でないなら、IDLE(待機)状態に移行
                    {
                        this.next_step = Block.STEP.IDLE;
                    }
                }
                break;

            case Block.STEP.IDLE:
                this.GetComponent <Renderer>().enabled = true;
                break;

            case Block.STEP.FALL:
                if (this.position_offset.y <= 0.0f)
                {
                    this.next_step         = Block.STEP.IDLE;
                    this.position_offset.y = 0.0f;
                }
                break;
            }
        }

        // 「次のブロック」の状態が「情報なし」以外である間
        // =「次のブロック」の状態が変更されていた場合
        while (this.next_step != Block.STEP.NONE)
        {
            this.step      = this.next_step;
            this.next_step = Block.STEP.NONE;

            switch (this.step)
            {
            case Block.STEP.IDLE:     // 「待機」状態
                this.position_offset = Vector3.zero;
                // ブロックの表示サイズを通常サイズにする
                this.transform.localScale = Vector3.one * 1.0f;
                break;

            case Block.STEP.GRABBED:     // 「つかまれている」状態
                // ブロックの表示サイズを大きくする
                this.transform.localScale = Vector3.one * 1.2f;
                break;

            case Block.STEP.RELEASED:     // 「離されている」状態
                this.position_offset = Vector3.zero;
                // ブロックの表示サイズを通常サイズにする
                this.transform.localScale = Vector3.one * 1.0f;
                break;

            case Block.STEP.VACANT:
                this.position_offset = Vector3.zero;
                this.setVisible(false);     // ブロックを非表示に
                break;

            case Block.STEP.RESPAWN:
                // 色をランダムに選び、ブロックをその色に設定
                int color_index = Random.Range(0, (int)Block.COLOR.NORMAL_COLOR_NUM);
                this.setColor((Block.COLOR)color_index);
                this.next_step = Block.STEP.IDLE;
                break;

            case Block.STEP.FALL:
                this.setVisible(true);     // ブロックを表示
                this.fall.velocity = 0.0f; // 落下速度をリセット
                break;
            }
            this.step_timer = 0.0f;
        }

        switch (this.step)
        {
        case Block.STEP.GRABBED:     // 「つかまれた」状態
            // 「つかまれた」状態のときは、常にスライド方向をチェック
            this.slide_dir = this.calcSlideDir(mouse_position_xy);
            break;

        case Block.STEP.SLIDE:     // スライド(入れ替え)中
            // ブロックを徐々に移動する処理(難しいので今は分からなくても大丈夫です)
            float rate = this.step_timer / slide_time;
            rate = Mathf.Min(rate, 1.0f);
            rate = Mathf.Sin(rate * Mathf.PI / 2.0f);
            this.position_offset = Vector3.Lerp(this.position_offset_initial, Vector3.zero, rate);
            break;

        case Block.STEP.FALL:
            // 速度に、重力の影響を与える
            this.fall.velocity += Physics.gravity.y * Time.deltaTime * 0.3f;
            // 縦方向の位置を計算
            this.position_offset.y += this.fall.velocity * Time.deltaTime;
            if (this.position_offset.y < 0.0f)     // 落下しきったら
            {
                this.position_offset.y = 0.0f;     // その場に留める
            }
            break;
        }

        // グリッド座標を実座標(シーン上の座標)に変換し、position_offsetを加える
        Vector3 position = BlockRoot.calcBlockPosition(this.i_pos) + this.position_offset;

        // 実際の位置を、新しい位置に変更
        this.transform.position = position;

        this.setColor(this.color);

        if (this.vanish_timer >= 0.0f)
        {
            // 現在のレベルの燃焼時間に設定
            float vanish_time = this.block_root.level_control.getVanishTime();
            Color color0      = Color.Lerp(this.GetComponent <Renderer>().material.color, Color.white, 0.5f); // 現在の色と白との中間色
            Color color1      = Color.Lerp(this.GetComponent <Renderer>().material.color, Color.black, 0.5f); // 現在の色と黒との中間色

            // 着火演出時間の半分を過ぎたら
            if (this.vanish_timer < Block.VANISH_TIME / 2.0f)
            {
                // 透明度(a)を設定
                color0.a = this.vanish_timer / (Block.VANISH_TIME / 2.0f);
                color1.a = color0.a;
                // 半透明マテリアルを適用
                this.GetComponent <Renderer>().material = this.transparent_material;
            }
            // vanish_timerが減るほど1に近づく
            float rate = 1.0f - this.vanish_timer / Block.VANISH_TIME;
            // じわ~っと色を変える
            this.GetComponent <Renderer>().material.color = Color.Lerp(color0, color1, rate);
        }
    }
Ejemplo n.º 9
0
    void Update()
    {
        Vector3 mouse_position;                 // 마우스 위치.

        this.block_root.unprojectMousePosition( // 마우스 위치 획득.
            out mouse_position, Input.mousePosition);
        // 획득한 마우스 위치를 X와 Y만으로 한다.
        Vector2 mouse_position_xy =
            new Vector2(mouse_position.x, mouse_position.y);

        this.step_timer += Time.deltaTime;
        float slide_time = 0.2f;

        if (this.next_step == Block.STEP.NONE)          // '상태정보 없음'의 경우.
        {
            switch (this.step)
            {
            case Block.STEP.SLIDE:
                if (this.step_timer >= slide_time)
                {
                    // vanish_timer(사라질 때까지의 시간)이 0이면.
                    // VACANT(사라지는)상태로 이행.
                    if (this.vanish_timer == 0.0f)
                    {
                        this.next_step = Block.STEP.VACANT;
                        // vanish_timer가 0이 아니면.
                        // IDLE(대기) 상태로 이행.
                    }
                    else
                    {
                        this.next_step = Block.STEP.IDLE;
                    }
                }
                break;
            }
        }



        // '다음 블록' 상태가 '정보 없음' 이외인 동안.
        // ='다음 블록' 상태가 변경된 경우.
        while (this.next_step != Block.STEP.NONE)
        {
            this.step      = this.next_step;
            this.next_step = Block.STEP.NONE;
            switch (this.step)
            {
            case Block.STEP.IDLE:             // '대기' 상태.
                this.position_offset = Vector3.zero;
                // 블록 표시 크기를 보통 크기로 한다.
                this.transform.localScale = Vector3.one * 1.0f;
                break;

            case Block.STEP.GRABBED:             // '잡힌' 상태.
                // 블록 표시 크기를 크게 한다.
                this.transform.localScale = Vector3.one * 1.2f;
                break;

            case Block.STEP.RELEASED:             // '떨어져 있는' 상태.
                this.position_offset = Vector3.zero;
                // 블록 표시 크기를 보통 사이즈로 한다.
                this.transform.localScale = Vector3.one * 1.0f;
                break;

            case Block.STEP.VACANT:
                this.position_offset = Vector3.zero;
                break;
            }
            this.step_timer = 0.0f;
        }


        switch (this.step)
        {
        case Block.STEP.GRABBED:         // 잡힌 상태.
            // 잡힌 상태일 때는 항상 슬라이드 방향을 체크.
            this.slide_dir = this.calcSlideDir(mouse_position_xy);
            break;

        case Block.STEP.SLIDE:         // 슬라이드(교체) 중.
            // 블록을 서서히 이동하는 처리.
            // (어려운 부분이니 지금은 몰라도 괜찮다).
            float rate = this.step_timer / slide_time;
            rate = Mathf.Min(rate, 1.0f);
            rate = Mathf.Sin(rate * Mathf.PI / 2.0f);
            this.position_offset = Vector3.Lerp(
                this.position_offset_initial, Vector3.zero, rate);
            break;
        }



        //그리드 좌표를 실제 좌표(씬의 좌표)로 변환하고,.
        // position_offset을 추가한다.
        Vector3 position =
            BlockRoot.calcBlockPosition(this.i_pos) + this.position_offset;

        // 실제 위치를 새로운 위치로 변경.
        this.transform.position = position;
    }
Ejemplo n.º 10
0
    void Update()
    {
        Vector3 mouse_position;                 // 마우스 위치.

        this.block_root.unprojectMousePosition( // 마우스 위치를 가져온다.
            out mouse_position, Input.mousePosition);
        // 가져온 마우스 위치를 하나의 Vector2에 모은다.
        Vector2 mouse_position_xy = new Vector2(mouse_position.x, mouse_position.y);


        if (this.vanish_timer >= 0.0f)             // 타이머가 0이상이면.
        {
            this.vanish_timer -= Time.deltaTime;   // 타이머의 값을 줄인다.
            if (this.vanish_timer < 0.0f)          // 타이머가 0 미만이면.
            {
                if (this.step != Block.STEP.SLIDE) // 슬라이드 중이 아니라면.
                {
                    this.vanish_timer = -1.0f;
                    this.next_step    = Block.STEP.VACANT;                  // 상태를 '소멸 중'으로.
                }
                else
                {
                    this.vanish_timer = 0.0f;
                }
            }
        }


        this.step_timer += Time.deltaTime;
        float slide_time = 0.2f;

        if (this.next_step == Block.STEP.NONE)          // 상태 정보 없음인 경우.
        {
            switch (this.step)
            {
            case Block.STEP.SLIDE:
                if (this.step_timer >= slide_time)
                {
                    // vanish_timer(사라질 때까지의 시간)가 0이면.
                    // VACANT(사라진)상태로 전환.
                    if (this.vanish_timer == 0.0f)
                    {
                        this.next_step = Block.STEP.VACANT;
                        // vanish_timer가 0이 아니면.
                        // IDLE(대기)상태로 전환.
                    }
                    else
                    {
                        this.next_step = Block.STEP.IDLE;
                    }
                }
                break;

            case Block.STEP.IDLE:
                this.renderer.enabled = true;
                break;

            case Block.STEP.FALL:
                if (this.position_offset.y <= 0.0f)
                {
                    this.next_step         = Block.STEP.IDLE;
                    this.position_offset.y = 0.0f;
                }
                break;
            }
        }



        // '다음 블록'의 상태가 '정보 없음' 이외인 동안.
        // = '다음 블록'의 상태가 변경된 경우.
        while (this.next_step != Block.STEP.NONE)
        {
            this.step      = this.next_step;
            this.next_step = Block.STEP.NONE;
            switch (this.step)
            {
            case Block.STEP.IDLE:             // '대기' 상태.
                this.position_offset = Vector3.zero;
                // 블록의 표시 크기를 일반 크기로 한다.
                this.transform.localScale = Vector3.one * 1.0f;
                break;

            case Block.STEP.GRABBED:             // '잡힌 상태'.
                // 블록 표시 크기를 크게 한다.
                this.transform.localScale = Vector3.one * 1.2f;
                break;

            case Block.STEP.RELEASED:             // '놓은 상태'.
                this.position_offset = Vector3.zero;
                // 블록의 표시 크기를 일반 크기로 한다.
                this.transform.localScale = Vector3.one * 1.0f;
                break;

            case Block.STEP.VACANT:
                this.position_offset = Vector3.zero;
                this.setVisible(false);                 // 블록을 비표시로.
                break;

            case Block.STEP.RESPAWN:
                // 색을 랜덤하게 선택하여 블록을 그 색으로 설정.
                int color_index = Random.Range(
                    0, (int)Block.COLOR.NORMAL_COLOR_NUM);
                this.setColor((Block.COLOR)color_index);
                this.next_step = Block.STEP.IDLE;
                break;

            case Block.STEP.FALL:
                this.setVisible(true);                 // 블록을 표시.
                this.fall.velocity = 0.0f;             // 낙하 속도를 리셋.
                break;
            }
            this.step_timer = 0.0f;
        }


        switch (this.step)
        {
        case Block.STEP.GRABBED:         // '잡힌 상태'.
            // '잡힌 상태'일 때는 항상 슬라이드 방향을 체크.
            this.slide_dir = this.calcSlideDir(mouse_position_xy);
            break;

        case Block.STEP.SLIDE:         // 슬라이드(교체) 중.
            // 블록을 서서히 이동하는 처리.
            // (어려우므로 지금은 몰라도 괜찮다).
            float rate = this.step_timer / slide_time;
            rate = Mathf.Min(rate, 1.0f);
            rate = Mathf.Sin(rate * Mathf.PI / 2.0f);
            this.position_offset = Vector3.Lerp(
                this.position_offset_initial, Vector3.zero, rate);
            break;

        case Block.STEP.FALL:
            // 속도에 중력의 영향을 준다.
            this.fall.velocity += Physics.gravity.y * Time.deltaTime * 0.3f;
            // 세로 방향 위치를 계산.
            this.position_offset.y += this.fall.velocity * Time.deltaTime;
            if (this.position_offset.y < 0.0f)              // 다 내려왔다면.
            {
                this.position_offset.y = 0.0f;              // 그 자리에 머문다.
            }
            break;
        }



        // 그리드 좌표를 실제 좌표(씬의 좌표)로 변환하고.
        // position_offset를 더한다.
        Vector3 position =
            BlockRoot.calcBlockPosition(this.i_pos) + this.position_offset;

        // 실제 위치를 새로운 위치로 변경.
        this.transform.position = position;


        this.setColor(this.color);
        if (this.vanish_timer >= 0.0f)
        {
            Color color0 =             // 현재 색과 흰색의 중간 색.
                           Color.Lerp(this.renderer.material.color, Color.white, 0.5f);
            Color color1 =             // 현재 색과 검은색의 중간 색.
                           Color.Lerp(this.renderer.material.color, Color.black, 0.5f);
            // 발화 연출 시간의 절반을 지났다면.
            if (this.vanish_timer < Block.VANISH_TIME / 2.0f)
            {
                // 투명도(a)를 설정.
                color0.a = this.vanish_timer / (Block.VANISH_TIME / 2.0f);
                color1.a = color0.a;
                // 반투명 머티리얼을 적용.
                this.renderer.material = this.transparent_material;
            }
            // vanish_timer가 줄어들 수록 1에 가까워진다.
            float rate = 1.0f - this.vanish_timer / Block.VANISH_TIME;
            // 서서히 색을 바꾼다.
            this.renderer.material.color = Color.Lerp(color0, color1, rate);
        }
    }
Ejemplo n.º 11
0
    void Update()
    {
        Vector3 mouse_position;                 // 마우스 위치.

        this.block_root.unprojectMousePosition( // 마우스 위치 획득.
            out mouse_position, Input.mousePosition);
        // 획득한 마우스 위치를 X와 Y만으로 한다.
        Vector2 mouse_position_xy =
            new Vector2(mouse_position.x, mouse_position.y);

        // '다음 블록' 상태가 '정보 없음' 이외인 동안.
        // ='다음 블록' 상태가 변경된 경우.

        if (this.vanish_timer >= 0.0f)
        {                                                  // 타이머가 0 이상이면.
            this.vanish_timer -= Time.deltaTime;           // 타이머의 값을 줄인다.
            if (this.vanish_timer < 0.0f)
            {                                              // 타이머가 0 미만이면.
                if (this.step != Block.STEP.SLIDE)
                {                                          // 슬라이드 중이 아니라면.
                    this.vanish_timer = -1.0f;
                    this.next_step    = Block.STEP.VACANT; // 상태를 ‘소멸 중’으로.
                }
                else
                {
                    this.vanish_timer = 0.0f;
                }
            }
        }

        this.step_timer += Time.deltaTime;
        float slide_time = 0.2f;

        if (this.next_step == Block.STEP.NONE)
        { // '상태 정보 없음'의 경우.
            switch (this.step)
            {
            case Block.STEP.SLIDE:
                if (this.step_timer >= slide_time)
                {
                    // 슬라이드 중인 블록이 소멸되면 VACANT(사라진) 상태로 이행.
                    if (this.vanish_timer == 0.0f)
                    {
                        this.next_step = Block.STEP.VACANT;
                        // vanish_timer가 0이 아니면 IDLE(대기) 상태로 이행.
                    }
                    else
                    {
                        this.next_step = Block.STEP.IDLE;
                    }
                }
                break;

            case Block.STEP.IDLE:
                this.GetComponent <Renderer>().enabled = true;
                break;

            case Block.STEP.FALL:
                if (this.position_offset.y <= 0.0f)
                {
                    this.next_step         = Block.STEP.IDLE;
                    this.position_offset.y = 0.0f;
                }
                break;
            }
        }

        while (this.next_step != Block.STEP.NONE)
        {
            this.step      = this.next_step;
            this.next_step = Block.STEP.NONE;
            switch (this.step)
            {
            case Block.STEP.IDLE:     // '대기' 상태.
                this.position_offset = Vector3.zero;
                // 블록 표시 크기를 보통 크기로 한다.
                this.transform.localScale = Vector3.one * 1.0f;
                break;

            case Block.STEP.GRABBED:     // '잡힌' 상태.
                                         // 블록 표시 크기를 크게 한다.
                this.transform.localScale = Vector3.one * 1.2f;
                break;

            case Block.STEP.RELEASED:     // '떨어져 있는' 상태.
                this.position_offset = Vector3.zero;
                // 블록 표시 크기를 보통 사이즈로 한다.
                this.transform.localScale = Vector3.one * 1.0f;
                break;

            case Block.STEP.VACANT:
                this.position_offset = Vector3.zero;
                this.setVisible(false);     // 블록을 표시하지 않게 한다.
                break;

            case Block.STEP.RESPAWN:
                // 색을 랜덤하게 선택하여 블록을 그 색으로 설정.
                //int color_index = Random.Range(
                //0, (int)Block.COLOR.NORMAL_COLOR_NUM);
                //this.setColor((Block.COLOR)color_index);

                int color_index = Random.Range(
                    0, (int)Block.CARD.NORMAL_CARD_NUM);
                this.setColor((Block.CARD)color_index);

                this.next_step = Block.STEP.IDLE;
                break;

            case Block.STEP.FALL:
                this.setVisible(true);     // 블록을 표시.
                this.fall.velocity = 0.0f; // 낙하 속도 리셋.
                break;
            }
            this.step_timer = 0.0f;
        }

        switch (this.step)
        {
        case Block.STEP.GRABBED:     // 잡힌 상태.
                                     // 잡힌 상태일 때는 항상 슬라이드 방향을 체크.
            this.slide_dir = this.calcSlideDir(mouse_position_xy);
            break;

        case Block.STEP.SLIDE:     // 슬라이드(교체) 중.
                                   // 블록을 서서히 이동하는 처리.
            float rate = this.step_timer / slide_time;
            rate = Mathf.Min(rate, 1.0f);
            rate = Mathf.Sin(rate * Mathf.PI / 2.0f);
            this.position_offset = Vector3.Lerp(this.position_offset_initial, Vector3.zero, rate);
            break;

        case Block.STEP.FALL:
            // 속도에 중력의 영향을 부여한다.
            this.fall.velocity += Physics.gravity.y * Time.deltaTime * 0.3f;
            // 세로 방향 위치를 계산.
            this.position_offset.y += this.fall.velocity * Time.deltaTime;
            if (this.position_offset.y < 0.0f)
            {                                  // 다 내려왔다면.
                this.position_offset.y = 0.0f; // 그 자리에 머무른다.
            }
            break;
        }
        // 그리드 좌표를 실제 좌표(씬의 좌표)로 변환하고.
        // position_offset을 추가한다.
        Vector3 position =
            BlockRoot.calcBlockPosition(this.i_pos) + this.position_offset;

        // 실제 위치를 새로운 위치로 변경한다.
        this.transform.position = position;

        this.setColor(this.color);
        if (this.vanish_timer >= 0.0f)
        {
            // 현재 레벨의 연소시간으로 설정.
            float vanish_time = this.block_root.level_control.getVanishTime();

            // 현재 색과 흰색의 중간 색.
            Color color0 = Color.Lerp(this.GetComponent <Renderer>().material.color,
                                      Color.white, 0.5f);
            // 현재 색과 검은색의 중간 색.
            Color color1 = Color.Lerp(this.GetComponent <Renderer>().material.color,
                                      Color.black, 0.5f);
            // 불붙는 연출 시간이 절반을 지났다면.
            if (this.vanish_timer < Block.VANISH_TIME / 2.0f)
            {
                // 투명도(a)를 설정.
                color0.a = this.vanish_timer / (Block.VANISH_TIME / 2.0f);
                color1.a = color0.a;
                // 반투명 머티리얼을 적용.
                this.GetComponent <Renderer>().material = this.transparent_material;
            }
            // vanish_timer가 줄어들수록 1에 가까워진다.
            float rate = 1.0f - this.vanish_timer / Block.VANISH_TIME;
            // 서서히 색을 바꾼다.
            this.GetComponent <Renderer>().material.color = Color.Lerp(color0, color1, rate);
        }

        countBlockDestroy();
    }
Ejemplo n.º 12
0
    public void initialSetUp(int _i) //임시
    {
        int _pattern = 0;
        int _Num     = 0;

        // 그리드의 크기를 9×9로 한다.
        this.blocks =
            new BlockControl[Block.BLOCK_NUM_X, Block.BLOCK_NUM_Y];

        for (int y = 0; y < Block.BLOCK_NUM_Y; y++)
        {     // 처음~마지막행
            for (int x = 0; x < Block.BLOCK_NUM_X; x++)
            { // 왼쪽~오른쪽
              // BlockPrefab의 인스턴스를 씬에 만든다.
                GameObject game_object =
                    Instantiate(this.BlockPrefab) as GameObject;
                // 위에서 만든 블록의 BlockControl 클래스를 가져온다.
                BlockControl block =
                    game_object.GetComponent <BlockControl>();
                // 블록을 그리드에 저장한다.
                this.blocks[x, y] = block;
                // 블록의 위치 정보(그리드 좌표)를 설정한다.
                block.i_pos.x = x;
                block.i_pos.y = y;
                // 각 BlockControl이 연계할 GameRoot는 자신이라고 설정한다.
                block.block_root = this;
                // 그리드 좌표를 실제 위치(씬의 좌표)로 변환한다.
                Vector3 position = BlockRoot.calcBlockPosition(block.i_pos);
                // 씬의 블록 위치를 이동한다.
                block.transform.position = position;
                // 블록의 색을 변경한다.
                //block.setColor((Block.COLOR)color_index);

                // 현재 출현 확률을 바탕으로 색을 결정한다.
                //////////////////
                //color = this.selectBlockColor();
                //block.setColor(color);
                //////////////////

                // 블록의 이름을 설정(후술)한다. 나중에 블록 정보 확인때 필요.
                block.name = "block(" + block.i_pos.x.ToString() +
                             "," + block.i_pos.y.ToString() + ")";

                // 전체 색 중에서 임의로 하나의 색을 선택한다.
                /////////////////////////////
                //color_index =
                //Random.Range(0, (int)Block.COLOR.NORMAL_COLOR_NUM);
                /////////////////////////////

                //전체 패턴중에서 하나를 임의로 선택
                _pattern = Random.Range(0, 4);
                SpriteRenderer Pattern = BlockPrefab.GetComponentInChildren <SpriteRenderer>();

                if (_pattern >= 0 && _pattern < 1)
                {
                    Pattern.sprite = Spade;
                }
                else if (_pattern >= 1 && _pattern < 2)
                {
                    Pattern.sprite = Diamond;
                }
                else if (_pattern >= 2 && _pattern < 3)
                {
                    Pattern.sprite = Heart;
                }
                else if (_pattern >= 3 && _pattern < 4)
                {
                    Pattern.sprite = Clover;
                }

                _Num = Random.Range(0, 14);
                TextMesh Num = BlockPrefab.GetComponentInChildren <TextMesh>();
                if (_Num >= 0 && _pattern < 1)
                {
                    Num.text = "A";
                }
                if (_Num >= 1 && _pattern < 2)
                {
                    Num.text = "2";
                }
                if (_Num >= 2 && _pattern < 3)
                {
                    Num.text = "3";
                }
                if (_Num >= 3 && _pattern < 4)
                {
                    Num.text = "4";
                }
                if (_Num >= 4 && _pattern < 5)
                {
                    Num.text = "5";
                }
                if (_Num >= 5 && _pattern < 6)
                {
                    Num.text = "6";
                }
                if (_Num >= 6 && _pattern < 7)
                {
                    Num.text = "7";
                }
                if (_Num >= 7 && _pattern < 8)
                {
                    Num.text = "8";
                }
                if (_Num >= 8 && _pattern < 9)
                {
                    Num.text = "9";
                }
                if (_Num >= 10 && _pattern < 11)
                {
                    Num.text = "10";
                }
                if (_Num >= 11 && _pattern < 12)
                {
                    Num.text = "J";
                }
                if (_Num >= 12 && _pattern < 13)
                {
                    Num.text = "Q";
                }
                if (_Num >= 13 && _pattern < 14)
                {
                    Num.text = "K";
                }
            }
        }
    }
Ejemplo n.º 13
0
    void    Update()
    {
        // ---------------------------------------------------------------- //
        // 3D 공간에서 마우스 위치 좌표를 구해 둔다.

        Vector3 mouse_position;

        this.block_root.unprojectMousePosition(out mouse_position, Input.mousePosition);

        Vector2 mouse_position_xy = new Vector2(mouse_position.x, mouse_position.y);

        // ---------------------------------------------------------------- //

        // 사라지는 연출 타이머.
        if (this.vanish_timer >= 0.0f)
        {
            this.vanish_timer -= Time.deltaTime;

            if (this.vanish_timer < 0.0f)
            {
                if (this.step != Block.STEP.SLIDE)
                {
                    this.vanish_timer = -1.0f;

                    // 퇴장 연출용 블록을 만든다.
                    this.leave_block_root.createLeaveBlock(this);

                    for (int i = 0; i < this.connected_block.Length; i++)
                    {
                        this.connected_block[i].clear();
                    }

                    // (임시).
                    this.next_step = Block.STEP.VACANT;
                }
                else
                {
                    this.vanish_timer = 0.0f;
                }
            }

            this.vanish_facing_timer += Time.deltaTime;
        }

        // ---------------------------------------------------------------- //
        // 스텝 내 경과시간을 진행한다.

        this.step_timer += Time.deltaTime;

        // ---------------------------------------------------------------- //
        // 다음 상태로 이행할지 검사한다.


        if (this.next_step == Block.STEP.NONE)
        {
            switch (this.step)
            {
            case Block.STEP.IDLE:
            {
            }
            break;

            case Block.STEP.SLIDE:
            {
                if (this.step_timer >= SLIDE_TIME)
                {
                    if (this.vanish_timer == 0.0f)
                    {
                        this.next_step = Block.STEP.VACANT;
                    }
                    else
                    {
                        this.next_step = Block.STEP.IDLE;
                    }
                }
            }
            break;

            case Block.STEP.FALL:
            {
                if (this.position_offset.y <= 0.0f)
                {
                    this.next_step         = Block.STEP.IDLE;
                    this.position_offset.y = 0.0f;
                }
            }
            break;
            }
        }

        // ---------------------------------------------------------------- //
        // 상태가 전환됐을 때의 초기화.

        while (this.next_step != Block.STEP.NONE)
        {
            this.step      = this.next_step;
            this.next_step = Block.STEP.NONE;

            switch (this.step)
            {
            case Block.STEP.IDLE:
            {
                this.setVisible(true);
                this.position_offset     = Vector3.zero;
                this.vanish_spin         = 0.0f;
                this.vanish_facing_timer = 0.0f;
            }
            break;

            case Block.STEP.GRABBED:
            {
                this.setVisible(true);
            }
            break;

            case Block.STEP.SLIDE:
            {
            }
            break;

            case Block.STEP.RELEASED:
            {
                this.setVisible(true);
                this.position_offset = Vector3.zero;
            }
            break;

            case Block.STEP.VACANT:
            {
                this.position_offset = Vector3.zero;
                this.setVisible(false);
            }
            break;

            case Block.STEP.FALL:
            {
                this.setVisible(true);
                this.vanish_spin         = 0.0f;
                this.vanish_facing_timer = 0.0f;
                this.fall.velocity       = 0.0f;
            }
            break;
            }

            this.step_timer = 0.0f;
        }

        // ---------------------------------------------------------------- //
        // 각 상태에서의 실행 처리.

        float scale = 1.0f;

        // 잡힌 스케일.

        if (this.step == Block.STEP.GRABBED)
        {
            this.grab_timer += Time.deltaTime;
        }
        else
        {
            this.grab_timer -= Time.deltaTime;
        }

        this.grab_timer = Mathf.Clamp(this.grab_timer, 0.0f, GRAB_EFFECT_TIME);

        float grab_ratio = Mathf.Clamp01(this.grab_timer / GRAB_EFFECT_TIME);

        scale = Mathf.Lerp(1.0f, 1.3f, grab_ratio);

        //

        this.models_root.transform.localPosition = Vector3.zero;

        if (this.vanish_timer > 0.0f)
        {
            // 다른 블록보다 앞에 표시되도록.
            this.models_root.transform.localPosition = Vector3.back;
        }

        switch (this.step)
        {
        case Block.STEP.IDLE:
        {
        }
        break;

        case Block.STEP.FALL:
        {
            this.fall.velocity     += Physics.gravity.y * Time.deltaTime * 0.3f;
            this.position_offset.y += this.fall.velocity * Time.deltaTime;

            if (this.position_offset.y < 0.0f)
            {
                this.position_offset.y = 0.0f;
            }
        }
        break;

        case Block.STEP.GRABBED:
        {
            // 슬라이드 방향.
            this.slide_dir = this.calcSlideDir(mouse_position_xy);

            // 다른 블록보다 앞쪽에 표시되도록.
            this.models_root.transform.localPosition = Vector3.back;
        }
        break;

        case Block.STEP.SLIDE:
        {
            float ratio = this.step_timer / SLIDE_TIME;

            ratio = Mathf.Min(ratio, 1.0f);
            ratio = Mathf.Sin(ratio * Mathf.PI / 2.0f);

            this.position_offset = Vector3.Lerp(this.position_offset_initial, Vector3.zero, ratio);

            //

            ratio = this.step_timer / SLIDE_TIME;
            ratio = Mathf.Min(ratio, 1.0f);
            ratio = Mathf.Sin(ratio * Mathf.PI);

            if (this.slide_forward)
            {
                scale += Mathf.Lerp(0.0f, 0.5f, ratio);
            }
            else
            {
                scale += Mathf.Lerp(0.0f, -0.5f, ratio);
            }
        }
        break;
        }

        // ---------------------------------------------------------------- //
        // 포지션.

        Vector3 position = BlockRoot.calcBlockPosition(this.i_pos) + this.position_offset;

        this.transform.position = position;

        // ---------------------------------------------------------------- //
        // 사라지는 연출.

        this.models_root.transform.localRotation = Quaternion.identity;

        if (this.vanish_timer >= 0.0f)
        {
            // facing ... 블록의 윗면(돌기가 있는 면)을 앞으로 향하게 회전.
            // vanish ... 빙글빙글 회전.

            float facing_ratio = Mathf.InverseLerp(0.0f, 0.2f, this.vanish_facing_timer);

            facing_ratio = Mathf.Clamp01(facing_ratio);

            float vanish_ratio = Mathf.InverseLerp(0.0f, this.block_root.level_control.getVanishTime(), this.vanish_timer);
            float spin_speed   = vanish_ratio;

            this.vanish_spin += spin_speed * 10.0f;

            if (this.color != Block.COLOR.NECO)
            {
                this.models_root.transform.localRotation *= Quaternion.AngleAxis(-90.0f * facing_ratio, Vector3.right);
                this.models_root.transform.localRotation *= Quaternion.AngleAxis(this.vanish_spin, Vector3.up);
            }
        }

        this.nekoAtama.localScale             = Vector3.one * 1.0f;
        this.models_root.transform.localScale = Vector3.one * scale;

        // ---------------------------------------------------------------- //

        if (this.color == Block.COLOR.NECO)
        {
            float anim_speed = 1.0f;

            if (this.vanish_timer >= 0.0f)
            {
                float vanish_ratio = this.calc_neko_vanish_ratio();

                anim_speed = Mathf.Lerp(1.0f, 1.5f, vanish_ratio);
            }

            this.neko_motion["00_Idle"].speed = anim_speed;
        }
    }
Ejemplo n.º 14
0
    // Update is called once per frame
    void Update()
    {
        Vector3 mouse_position;

        this.block_root.unprojectMousePosition(out mouse_position, Input.mousePosition);

        Vector2 mouse_position_xy = new Vector2(mouse_position.x, mouse_position.y);

        if (this.vanish_timer >= 0.0f)
        {
            this.vanish_timer -= Time.deltaTime;
            if (this.vanish_timer < 0.0f)
            {
                if (this.step != Block.STEP.SLIDE)
                {
                    this.vanish_timer = -1.0f;
                    this.next_step    = Block.STEP.VACANT;
                }
                else
                {
                    this.vanish_timer = 0.0f;
                }
            }
        }

        this.step_timer += Time.deltaTime;
        float slide_time = 0.2f;

        if (this.next_step == Block.STEP.NONE)
        {
            switch (this.step)
            {
            case Block.STEP.SLIDE:
                if (this.step_timer >= slide_time)
                {
                    if (this.vanish_timer == 0.0f)
                    {
                        this.next_step = Block.STEP.VACANT;
                    }
                    else
                    {
                        this.next_step = Block.STEP.IDLE;
                    }
                }
                break;

            case Block.STEP.IDLE:
                GetComponent <Renderer>().enabled = true;
                break;

            case Block.STEP.FALL:
                if (this.position_offset.y <= 0.0f)
                {
                    this.next_step         = Block.STEP.IDLE;
                    this.position_offset.y = 0.0f;
                }
                break;
            }
        }

        while (this.next_step != Block.STEP.NONE)
        {
            this.step      = this.next_step;
            this.next_step = Block.STEP.NONE;

            switch (this.step)
            {
            case Block.STEP.IDLE:
                this.position_offset      = Vector3.zero;
                this.transform.localScale = Vector3.one * 1.0f;
                break;

            case Block.STEP.GRABBED:
                this.transform.localScale = Vector3.one * 1.2f;
                break;

            case Block.STEP.RELEASED:
                this.position_offset      = Vector3.zero;
                this.transform.localScale = Vector3.one * 1.0f;
                break;

            case Block.STEP.VACANT:
                this.position_offset = Vector3.zero;
                this.setVisible(false);
                break;

            case Block.STEP.RESPAWN:
                int color_index = Random.Range(0, (int)Block.COLOR.NORMAL_COLOR_NUM);
                this.setColor((Block.COLOR)color_index);
                this.next_step = Block.STEP.IDLE;
                break;

            case Block.STEP.FALL:
                this.setVisible(true);
                this.fall.velocity = 0.0f;
                break;
            }
            this.step_timer = 0.0f;
        }

        switch (this.step)
        {
        case Block.STEP.GRABBED:
            this.slide_dir = this.calcSlideDir(mouse_position_xy);
            break;

        case Block.STEP.SLIDE:
            float rate = this.step_timer / slide_time;
            rate = Mathf.Min(rate, 1.0f);
            rate = Mathf.Sin(rate * Mathf.PI / 2.0f);
            this.position_offset = Vector3.Lerp(this.position_offset_initial, Vector3.zero, rate);
            break;

        case Block.STEP.FALL:
            this.fall.velocity     += Physics.gravity.y * Time.deltaTime * 0.3f;
            this.position_offset.y += this.fall.velocity * Time.deltaTime;
            if (this.position_offset.y < 0.0f)
            {
                this.position_offset.y = 0.0f;
            }
            break;
        }

        Vector3 position = BlockRoot.calcBlockPosition(this.i_pos) + this.position_offset;

        this.transform.position = position;

        this.setColor(this.color);

        if (this.vanish_timer >= 0.0f)
        {
            Color color0 = Color.Lerp(GetComponent <Renderer>().material.color, Color.white, 0.5f);
            Color color1 = Color.Lerp(GetComponent <Renderer>().material.color, Color.black, 0.5f);

            if (this.vanish_timer < Block.VANISH_TIME / 2.0f)
            {
                color0.a = this.vanish_timer / (Block.VANISH_TIME / 2.0f);
                color1.a = color0.a;
                GetComponent <Renderer>().material = this.transparent_material;
            }
            float rate = 1.0f - this.vanish_timer / Block.VANISH_TIME;
            GetComponent <Renderer>().material.color = Color.Lerp(color0, color1, rate);
        }
    }
Ejemplo n.º 15
0
    // Update is called once per frame
    void Update()
    {
        Vector2 mouse_position;

        block_root.unprojectMousePosition(out mouse_position, Input.mousePosition);


        if (this.vanish_timer >= 0.0f)
        {
            this.vanish_timer -= Time.deltaTime;
            if (this.vanish_timer < 0.0f)
            {
                if (this.step != Block.STEP.slide)
                {
                    this.vanish_timer = -1.0f;
                    this.next_step    = Block.STEP.vacant;
                }
                else
                {
                    this.vanish_timer = 0.0f;
                }
            }
        }

        this.step_timer += Time.deltaTime;
        float slide_time = 0.2f;

        if (this.next_step == Block.STEP.NONE)
        {
            switch (this.step)
            {
            case Block.STEP.slide:
                if (this.step_timer >= slide_time)
                {
                    // 슬라이드 중인 블록이 소멸되면 vacant 상태로 이행
                    if (this.vanish_timer == 0.0f)
                    {
                        this.next_step = Block.STEP.vacant;
                        // vanish_timer가 0 이 아니면 idle 상태로 이행
                    }
                    else
                    {
                        this.next_step = Block.STEP.idle;
                    }
                }
                break;

            case Block.STEP.idle:
                this.GetComponent <Renderer>().enabled = true;
                break;

            case Block.STEP.fall:
                if (this.position_offset.y <= 0.0f)
                {
                    this.next_step         = Block.STEP.idle;
                    this.position_offset.y = 0.0f;
                }
                break;
            }
        }

        while (this.next_step != Block.STEP.NONE)
        {
            this.step      = this.next_step;
            this.next_step = Block.STEP.NONE;

            switch (this.step)
            {
            case Block.STEP.idle:
                this.position_offset      = Vector3.zero;
                this.transform.localScale = Vector3.one * 0.7f;
                break;

            case Block.STEP.grabbed:
                this.transform.localScale = Vector3.one * 1.0f;
                break;

            case Block.STEP.released:
                this.position_offset      = Vector3.zero;
                this.transform.localScale = Vector3.one * 0.7f;
                break;

            case Block.STEP.vacant:
                this.position_offset = Vector3.zero;
                this.setVisible(false);
                break;

            case Block.STEP.respawn:
                // 색을 랜덤하게 선택하여 블록을 선택한 색으로 설정.
                int color_index = Random.Range(0, SizeManager.colorNum);
                this.SetColor((Block.COLOR)color_index);
                this.next_step = Block.STEP.idle;
                break;

            case Block.STEP.fall:
                this.setVisible(true);     // 블록을 표시.
                this.fall.velocity = 0.0f; // 낙하 속도를 리셋.
                break;
            }
            this.step_timer = 0.0f;
        }

        switch (this.step)
        {
        case Block.STEP.grabbed:
            // 잡힌 상태일 때는 항상 슬라이드 방향을 체크
            this.slide_dir = this.calcSlideDir(mouse_position);
            break;

        case Block.STEP.slide:
            // 블록을 서서히 이동하는 처리
            float rate = this.step_timer / slide_time;
            rate = Mathf.Min(rate, 1.0f);
            rate = Mathf.Sin(rate * Mathf.PI / 2.0f);
            this.position_offset = Vector3.Lerp(this.position_offset_initial, Vector3.zero, rate);
            break;

        case Block.STEP.fall:
            // 속도에 중력의 영향을 준다.
            this.fall.velocity += Physics.gravity.y * Time.deltaTime * 1.5f;
            // 세로 방향 위치를 계산.
            this.position_offset.y += this.fall.velocity * Time.deltaTime;
            if (this.position_offset.y < 0.0f)
            {                                  // 다 내려왔다면.
                this.position_offset.y = 0.0f; // 그 자리에 머문다.
            }
            break;
        }

        // 그리드 좌표를 실제 좌표로 변환하고 position_offset을 추가한다
        Vector3 position = BlockRoot.calcBlockPosition(this.i_pos) + this.position_offset;

        // 실제 위치를 새로운 위치로 변경한다
        this.transform.position = position;

        this.SetColor(this.color);

        if (this.vanish_timer >= 0.0f)
        {
            Renderer rd     = this.GetComponent <Renderer>();
            Color    color0 = Color.Lerp(rd.material.color, Color.white, 0.5f);
            Color    color1 = Color.Lerp(rd.material.color, Color.black, 0.5f);

            // 불붙는 연출 시간이 절반을 지났다면,
            if (this.vanish_timer < Block.VANISH_TIME / 2.0f)
            {
                // 투명도(a)를 설정
                color0.a = this.vanish_timer / (Block.VANISH_TIME / 2.0f);
                color1.a = color0.a;

                rd.material = this.transparent_material;
            }
            // vanish_timer가 줄어들수록 1에 가까워진다
            float rate = 1.0f - this.vanish_timer / Block.VANISH_TIME;
            //서서히 색을 바꾼다
            rd.material.color = Color.Lerp(color0, color1, rate);
        }
    }
Ejemplo n.º 16
0
    } // 다음 블록을 대기중으로.

    void Update()
    {                                                                                    // 블록이 잡혔을 때에 블록을 크게 하고 그렇지 않을 때는 원래대로 돌아감
        Vector3 mouse_position;                                                          // 마우스 위치.

        this.block_root.unprojectMousePosition(out mouse_position, Input.mousePosition); // 마우스 위치 획득.
        Vector2 mouse_position_xy = new Vector2(mouse_position.x, mouse_position.y);     // 획득한 마우스 위치를 X와 Y만으로 한다.

        if (this.vanish_timer >= 0.0f)
        {                                                  // 타이머가 0 이상이면.
            this.vanish_timer -= Time.deltaTime;           // 타이머의 값을 줄인다.
            if (this.vanish_timer < 0.0f)
            {                                              // 타이머가 0 미만이면.
                if (this.step != Block.STEP.SLIDE)
                {                                          // 슬라이드 중이 아니라면.
                    this.vanish_timer = -1.0f;
                    this.next_step    = Block.STEP.VACANT; // 상태를 ‘소멸 중’으로.
                }
                else
                {
                    this.vanish_timer = 0.0f;
                }
            }
        }

        this.step_timer += Time.deltaTime;
        float slide_time = 0.2f;

        if (this.next_step == Block.STEP.NONE)
        { // '상태 정보 없음'의 경우.
            switch (this.step)
            {
            case Block.STEP.SLIDE:
                if (this.step_timer >= slide_time)
                {     // 슬라이드 중인 블록이 소멸되면 VACANT(사라진) 상태로 이행.
                    if (this.vanish_timer == 0.0f)
                    {
                        this.next_step = Block.STEP.VACANT;
                    }
                    else
                    {     // vanish_timer가 0이 아니면 IDLE(대기) 상태로 이행.
                        this.next_step = Block.STEP.IDLE;
                    }
                }
                break;

            case Block.STEP.IDLE:
                this.GetComponent <Renderer>().enabled = true;
                break;

            case Block.STEP.FALL:
                if (this.position_offset.y <= 0.0f)
                {
                    this.next_step         = Block.STEP.IDLE;
                    this.position_offset.y = 0.0f;
                }
                break;
            }
        }

        while (this.next_step != Block.STEP.NONE)
        { // '다음 블록' 상태가 '정보 없음' 이외인 동안. => '다음 블록' 상태가 변경된 경우.
            this.step      = this.next_step;
            this.next_step = Block.STEP.NONE;
            switch (this.step)
            {
            case Block.STEP.IDLE:     // '대기' 상태.
                this.position_offset      = Vector3.zero;
                this.transform.localScale = Vector3.one * 1.0f;
                break;                // 블록 표시 크기를 보통 크기로 한다.

            case Block.STEP.GRABBED:  // '잡힌' 상태.
                this.transform.localScale = Vector3.one * 1.2f;
                break;                // 블록 표시 크기를 크게 한다.

            case Block.STEP.RELEASED: // '떨어져 있는' 상태.
                this.position_offset      = Vector3.zero;
                this.transform.localScale = Vector3.one * 1.0f;
                break;

            case Block.STEP.VACANT:
                this.position_offset = Vector3.zero;
                if (GameObject.Find("GameRoot").GetComponent <BlockRoot>().playerMoved)
                {
                    if (this.color == Block.COLOR.ATTACK)     //공격
                    {
                        GameManager.instance.attackPoint++;
                    }
                    if (this.color == Block.COLOR.SKILL)     // 가드
                    {
                        GameManager.instance.skillPoint++;
                    }
                    if (this.color == Block.COLOR.UP)     // 상
                    {
                        GameManager.instance.moveFrontPoint++;
                    }
                    if (this.color == Block.COLOR.DOWN)     //하
                    {
                        GameManager.instance.moveBackPoint++;
                    }
                    if (this.color == Block.COLOR.LEFT)     //좌
                    {
                        GameManager.instance.moveLeftPoint++;
                    }
                    if (this.color == Block.COLOR.RIGHT)     //우
                    {
                        GameManager.instance.moveRightPoint++;
                    }
                }
                this.setVisible(false);     // 블록을 표시하지 않게 한다.
                break;

            case Block.STEP.RESPAWN:
                int color_index = Random.Range(0, (int)Block.COLOR.NORMAL_COLOR_NUM);    // 색을랜덤하게선택하여블록을그색으로설정.
                this.setColor((Block.COLOR)color_index);
                this.next_step = Block.STEP.IDLE;
                break;

            case Block.STEP.FALL:
                this.setVisible(true);     // 블록을표시.
                this.fall.velocity = 0.0f; // 낙하속도리셋.
                break;
            } // 블록 표시 크기를 보통 사이즈로 한다.
            this.step_timer = 0.0f;
        } // 그리드 좌표를 실제 좌표(씬의 좌표)로 변환하고.

        switch (this.step)
        {
        case Block.STEP.GRABBED:                       // 잡힌 상태.
            this.slide_dir = this.calcSlideDir(mouse_position_xy);
            break;                                     // 잡힌 상태일 때는 항상 슬라이드 방향을 체크.

        case Block.STEP.SLIDE:                         // 슬라이드(교체) 중.
            float rate = this.step_timer / slide_time; // 블록을 서서히 이동하는 처리.
            rate = Mathf.Min(rate, 1.0f);
            rate = Mathf.Sin(rate * Mathf.PI / 2.0f);
            this.position_offset = Vector3.Lerp(this.position_offset_initial, Vector3.zero, rate);
            break;

        case Block.STEP.FALL:
            this.fall.velocity     += Physics.gravity.y * 4.0f * Time.deltaTime * 0.3f; // 속도에중력의영향을부여한다.
            this.position_offset.y += this.fall.velocity * Time.deltaTime;              // 세로방향위치를계산.
            if (this.position_offset.y < 0.0f)
            {                                                                           // 다내려왔다면.
                this.position_offset.y = 0.0f;                                          // 그자리에머무른다.
            }
            break;
        }
        Vector3 position = BlockRoot.calcBlockPosition(this.i_pos) + this.position_offset; // position_offset을 추가한다.

        this.transform.position = position;                                                // 실제 위치를 새로운 위치로 변경한다.
        this.setColor(this.color);
        if (this.vanish_timer >= 0.0f)
        {
            float vanish_time = this.block_root.level_control.getVanishTime();
            Color color0      = Color.Lerp(this.GetComponent <Renderer>().material.color, Color.white, 0.5f); // 현재 색과 흰색의 중간 색.
            Color color1      = Color.Lerp(this.GetComponent <Renderer>().material.color, Color.black, 0.5f); // 현재 색과 검은색의 중간 색.
            if (this.vanish_timer < Block.VANISH_TIME / 2.0f)
            {                                                                                                 // 불붙는 연출 시간이 절반을 지났다면.
                color0.a = this.vanish_timer / (Block.VANISH_TIME / 2.0f);                                    // 투명도(a)를 설정.
                color1.a = color0.a;
                this.GetComponent <Renderer>().material = this.transparent_material;
            } // 반투명 머티리얼을 적용.
            float rate = 1.0f - this.vanish_timer / Block.VANISH_TIME; // vanish_timer가 줄어들수록 1에 가까워진다.
            this.GetComponent <Renderer>().material.color = Color.Lerp(color0, color1, rate); // 서서히 색을 바꾼다.
            //텍스쳐 수정
            //this.GetComponent<MeshRenderer>().material.mainTexture = Resources.Load("Sword_Square") as Texture;
        }
    }