// 设置高度
    public void     SetHeight(int height)
    {
        StackBlock.PlaceIndex place;

        place.x = this.lx;
        place.y = StackBlockControl.GROUND_LINE - 1 + height;

        this.transform.position = StackBlockControl.calcIndexedPosition(place);
    }
Beispiel #2
0
    // 从from_block 拷贝颜色和位置等信息
    public void     relayFrom(StackBlock from_block)
    {
        this.setColorType(from_block.color_type);

        this.step                = from_block.step;
        this.next_step           = from_block.next_step;
        this.step_timer          = from_block.step_timer;
        this.swap_action         = from_block.swap_action;
        this.color_change_action = from_block.color_change_action;

        this.velocity = from_block.velocity;

        // 为了使其全局的位置不发生变化,计算偏移植
        this.position_offset = StackBlockControl.calcIndexedPosition(from_block.place) + from_block.position_offset - StackBlockControl.calcIndexedPosition(this.place);

        //this.position_offset = from_block.transform.position - StackBlockControl.calcIndexedPosition(this.place);
        // 如果按上面这样做,旋转的中心就会受到偏移的影响,这样是不对的
    }
Beispiel #3
0
    // from_block から色や位置などをコピーする.
    public void     relayFrom(StackBlock from_block)
    {
        this.setColorType(from_block.color_type);

        this.step                = from_block.step;
        this.next_step           = from_block.next_step;
        this.step_timer          = from_block.step_timer;
        this.swap_action         = from_block.swap_action;
        this.color_change_action = from_block.color_change_action;

        this.velocity = from_block.velocity;

        // グローバルの位置がかわらないよう、オフセットを計算する.
        this.position_offset = StackBlockControl.calcIndexedPosition(from_block.place) + from_block.position_offset - StackBlockControl.calcIndexedPosition(this.place);

        //this.position_offset = from_block.transform.position - StackBlockControl.calcIndexedPosition(this.place);
        // 上こちらにすると、回転の中心をずらしたことの影響を受けてしまうのでだめ.
    }
Beispiel #4
0
    void    Update()
    {
        this.step_timer += Time.deltaTime;

        const float vanish_time = 1.0f;

        // -------------------------------------------- //
        // 检测是否迁移到下一状态

        switch (this.step)
        {
        case STEP.VANISHING:
        {
            if (this.step_timer > vanish_time)
            {
                this.next_step = STEP.VACANT;
            }
        }
        break;

        case STEP.FALL:
        {
            // 落地后结束
            if (this.position_offset.y == 0.0f)
            {
                this.next_step = STEP.IDLE;
            }
        }
        break;
        }

        // -------------------------------------------- //
        // 状态迁移时的初始化

        if (this.next_step != STEP.NONE)
        {
            switch (this.next_step)
            {
            case STEP.VACANT:
            {
                this.setColorType(COLOR_TYPE.GRAY);
            }
            break;

            case STEP.FALL:
            {
                this.velocity = Vector3.zero;
            }
            break;

            case STEP.VANISHING:
            {
                this.shake_start();

                this.stack_control.scene_control.vanish_fx_control.createEffect(this);
            }
            break;
            }

            this.step      = this.next_step;
            this.next_step = STEP.NONE;

            this.step_timer = 0.0f;
        }

        // -------------------------------------------- //
        // 各个状态的执行处理

        switch (this.step)
        {
        case STEP.VANISHING:
        {
            // 方块的颜色按照
            //
            // 原来的颜色→红→灰色
            //
            // 的顺序变化

            float rate;

            if (this.step_timer < vanish_time * 0.1f)
            {
                rate = this.step_timer / (vanish_time * 0.1f);
            }
            else if (this.step_timer < vanish_time * 0.3f)
            {
                rate = 1.0f;
            }
            else if (this.step_timer < vanish_time * 0.6f)
            {
                this.setColorType(COLOR_TYPE.RED);

                rate = (this.step_timer - vanish_time * 0.3f) / (vanish_time * 0.3f);
            }
            else
            {
                rate = 1.0f;
            }

            this.GetComponent <Renderer>().material.SetFloat("_BlendRate", rate);
        }
        break;
        }

        // -------------------------------------------------------------------------------- //
        // 网格上的位置(一般是固定的),旋转时初始化

        this.transform.position = StackBlockControl.calcIndexedPosition(this.place);
        this.transform.rotation = Quaternion.identity;

        // -------------------------------------------- //
        // 滑动(偏移植的补间)

        if (this.step == STEP.FALL)
        {
            this.velocity.y += -9.8f * Time.deltaTime;

            this.position_offset.y += this.velocity.y * Time.deltaTime;

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

            // 为了避免超过下方的方块
            // (处理的顺序不局限于从下到上,不够严谨)
            //
            if (this.place.y < StackBlockControl.BLOCK_NUM_Y - 1)
            {
                StackBlock under = this.stack_control.blocks[this.place.x, this.place.y + 1];

                if (this.position_offset.y < under.position_offset.y)
                {
                    this.position_offset.y = under.position_offset.y;
                    this.velocity.y        = under.velocity.y;
                }
            }
        }
        else
        {
            float position_offset_prev = this.position_offset.y;

            if (Mathf.Abs(this.position_offset.y) < 0.1f)
            {
                // 当偏移值足够小就结束

                this.position_offset.y = 0.0f;
            }
            else
            {
                if (this.position_offset.y > 0.0f)
                {
                    this.position_offset.y -= OFFSET_REVERT_SPEED * Time.deltaTime;
                    this.position_offset.y  = Mathf.Max(0.0f, this.position_offset.y);
                }
                else
                {
                    this.position_offset.y -= -OFFSET_REVERT_SPEED * Time.deltaTime;
                    this.position_offset.y  = Mathf.Min(0.0f, this.position_offset.y);
                }
            }

            // 为了执行上方落下的方块停止时的处理,提前计算出速度
            this.velocity.y = (this.position_offset.y - position_offset_prev) / Time.deltaTime;
        }

        this.transform.Translate(this.position_offset);

        // -------------------------------------------- //
        // 交换动作

        this.swap_action.execute(this);

        // 蛋糕不会旋转
        if (this.isCakeBlock())
        {
            this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, 0.0f);

            this.transform.rotation = Quaternion.identity;
        }

        // -------------------------------------------- //
        // 改变颜色

        this.color_change_action.execute(this);

        if (this.color_change_action.is_active)
        {
            // 旋转到一半的时候改变颜色

            if (this.color_change_action.rate > 0.5f)
            {
                this.setColorType(this.color_change_action.target_color);
            }
        }

        // -------------------------------------------- //
        // 方块消失时的振动

        this.shake_execute();
    }
Beispiel #5
0
    void    Update()
    {
        this.step_timer += Time.deltaTime;

        const float vanish_time = 1.0f;

        // -------------------------------------------- //
        // 次の状態に移るかどうかを、チェックする.

        switch (this.step)
        {
        case STEP.VANISHING:
        {
            if (this.step_timer > vanish_time)
            {
                this.next_step = STEP.VACANT;
            }
        }
        break;

        case STEP.FALL:
        {
            // 着地したらおしまい.
            if (this.position_offset.y == 0.0f)
            {
                this.next_step = STEP.IDLE;
            }
        }
        break;
        }

        // -------------------------------------------- //
        // 状態が遷移したときの初期化.

        if (this.next_step != STEP.NONE)
        {
            switch (this.next_step)
            {
            case STEP.VACANT:
            {
                this.setColorType(COLOR_TYPE.GRAY);
            }
            break;

            case STEP.FALL:
            {
                this.velocity = Vector3.zero;
            }
            break;

            case STEP.VANISHING:
            {
                this.shake_start();

                this.stack_control.scene_control.vanish_fx_control.createEffect(this);
            }
            break;
            }

            this.step      = this.next_step;
            this.next_step = STEP.NONE;

            this.step_timer = 0.0f;
        }

        // -------------------------------------------- //
        // 各状態での実行処理.

        switch (this.step)
        {
        case STEP.VANISHING:
        {
            // ブロックの色を
            //
            // 元の色→赤→灰色
            //
            // に変える.

            float rate;

            if (this.step_timer < vanish_time * 0.1f)
            {
                rate = this.step_timer / (vanish_time * 0.1f);
            }
            else if (this.step_timer < vanish_time * 0.3f)
            {
                rate = 1.0f;
            }
            else if (this.step_timer < vanish_time * 0.6f)
            {
                this.setColorType(COLOR_TYPE.RED);

                rate = (this.step_timer - vanish_time * 0.3f) / (vanish_time * 0.3f);
            }
            else
            {
                rate = 1.0f;
            }

            this.GetComponent <Renderer>().material.SetFloat("_BlendRate", rate);
        }
        break;
        }

        // -------------------------------------------------------------------------------- //
        // マス目上の位置(常に固定)、回転は0で初期化.

        this.transform.position = StackBlockControl.calcIndexedPosition(this.place);
        this.transform.rotation = Quaternion.identity;

        // -------------------------------------------- //
        // スライド(オフセットの補間).

        if (this.step == STEP.FALL)
        {
            this.velocity.y += -9.8f * Time.deltaTime;

            this.position_offset.y += this.velocity.y * Time.deltaTime;

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

            // 下にあるブロックを追い抜いてしまわないように.
            // (処理の順番が下→上とも限らないので、厳密ではない).
            //
            if (this.place.y < StackBlockControl.BLOCK_NUM_Y - 1)
            {
                StackBlock under = this.stack_control.blocks[this.place.x, this.place.y + 1];

                if (this.position_offset.y < under.position_offset.y)
                {
                    this.position_offset.y = under.position_offset.y;
                    this.velocity.y        = under.velocity.y;
                }
            }
        }
        else
        {
            float position_offset_prev = this.position_offset.y;

            if (Mathf.Abs(this.position_offset.y) < 0.1f)
            {
                // オフセットが十分小さくなったらおしまい.

                this.position_offset.y = 0.0f;
            }
            else
            {
                if (this.position_offset.y > 0.0f)
                {
                    this.position_offset.y -= OFFSET_REVERT_SPEED * Time.deltaTime;
                    this.position_offset.y  = Mathf.Max(0.0f, this.position_offset.y);
                }
                else
                {
                    this.position_offset.y -= -OFFSET_REVERT_SPEED * Time.deltaTime;
                    this.position_offset.y  = Mathf.Min(0.0f, this.position_offset.y);
                }
            }

            // 上から落ちてくるブロックがぶつかったときのために、速度を計算しておく.
            this.velocity.y = (this.position_offset.y - position_offset_prev) / Time.deltaTime;
        }

        this.transform.Translate(this.position_offset);

        // -------------------------------------------- //
        // スワップ動作.

        this.swap_action.execute(this);

        // ケーキは回転しない.
        if (this.isCakeBlock())
        {
            this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, 0.0f);

            this.transform.rotation = Quaternion.identity;
        }

        // -------------------------------------------- //
        // カラーチェンジ.

        this.color_change_action.execute(this);

        if (this.color_change_action.is_active)
        {
            // 半周回ったところで色が変わる.

            if (this.color_change_action.rate > 0.5f)
            {
                this.setColorType(this.color_change_action.target_color);
            }
        }

        // -------------------------------------------- //
        // ブロックが消えるときの振動.

        this.shake_execute();
    }
Beispiel #6
0
    void    Update()
    {
        this.step_timer += Time.deltaTime;

        // 检测状态迁移

        if (this.next_step == STEP.NONE)
        {
            switch (this.step)
            {
            case STEP.CARRY_UP:
            {
                if (this.position_offset.y == 0.0f)
                {
                    this.next_step = STEP.CARRY;
                }
            }
            break;

            case STEP.DROP_DOWN:
            {
                if (this.position_offset.y == 0.0f)
                {
                    this.player.scene_control.stack_control.endDropBlockAction(this.place.x);

                    this.next_step = STEP.HIDE;
                }
            }
            break;
            }
        }

        // 状态迁移时的初始化

        if (this.next_step != STEP.NONE)
        {
            switch (this.next_step)
            {
            case STEP.HIDE:
            {
                this.GetComponent <Renderer>().enabled = false;
            }
            break;

            case STEP.CARRY_UP:
            {
                // 从隐藏状态开始时,算出现在的位置
                if (this.step == STEP.HIDE)
                {
                    this.transform.position = StackBlockControl.calcIndexedPosition(this.place);
                }

                Vector3 base_position = this.player.transform.position;

                base_position.y += Block.SIZE_Y;

                this.position_offset = this.transform.position - base_position;

                this.setVisible(true);
            }
            break;

            case STEP.DROP_DOWN:
            {
                Vector3 base_position = StackBlockControl.calcIndexedPosition(this.place);

                this.position_offset = this.transform.position - base_position;
            }
            break;
            }

            this.step      = this.next_step;
            this.next_step = STEP.NONE;

            this.step_timer = 0.0f;
        }

        // 各个状态的执行

        Vector3 position = this.transform.position;

        switch (this.step)
        {
        case STEP.CARRY:
        case STEP.CARRY_UP:
        {
            position.x = this.player.transform.position.x;
            position.y = this.player.transform.position.y + Block.SIZE_Y;
            position.z = 0.0f;
        }
        break;

        case STEP.DROP_DOWN:
        {
            position = StackBlockControl.calcIndexedPosition(this.place);
        }
        break;
        }

        // 对偏移值进行补间

        if (Mathf.Abs(this.position_offset.y) < 0.1f)
        {
            this.position_offset.y = 0.0f;
        }
        else
        {
            const float speed = 0.2f;

            if (this.position_offset.y > 0.0f)
            {
                this.position_offset.y -= speed * (60.0f * Time.deltaTime);

                this.position_offset.y = Mathf.Max(this.position_offset.y, 0.0f);
            }
            else
            {
                this.position_offset.y -= -speed * (60.0f * Time.deltaTime);

                this.position_offset.y = Mathf.Min(this.position_offset.y, 0.0f);
            }
        }

        position.y += this.position_offset.y;

        this.transform.position = position;
    }
Beispiel #7
0
    void    Update()
    {
        this.step_timer += Time.deltaTime;

        // 状態遷移のチェック.

        if (this.next_step == STEP.NONE)
        {
            switch (this.step)
            {
            case STEP.CARRY_UP:
            {
                if (this.position_offset.y == 0.0f)
                {
                    this.next_step = STEP.CARRY;
                }
            }
            break;

            case STEP.DROP_DOWN:
            {
                if (this.position_offset.y == 0.0f)
                {
                    this.player.scene_control.stack_control.endDropBlockAction(this.place.x);

                    this.next_step = STEP.HIDE;
                }
            }
            break;
            }
        }

        // 状態遷移時の初期化.

        if (this.next_step != STEP.NONE)
        {
            switch (this.next_step)
            {
            case STEP.HIDE:
            {
                this.GetComponent <Renderer>().enabled = false;
            }
            break;

            case STEP.CARRY_UP:
            {
                // 非表示状態から始まったときは、現在位置を求めておく.
                if (this.step == STEP.HIDE)
                {
                    this.transform.position = StackBlockControl.calcIndexedPosition(this.place);
                }

                Vector3 base_position = this.player.transform.position;

                base_position.y += Block.SIZE_Y;

                this.position_offset = this.transform.position - base_position;

                this.setVisible(true);
            }
            break;

            case STEP.DROP_DOWN:
            {
                Vector3 base_position = StackBlockControl.calcIndexedPosition(this.place);

                this.position_offset = this.transform.position - base_position;
            }
            break;
            }

            this.step      = this.next_step;
            this.next_step = STEP.NONE;

            this.step_timer = 0.0f;
        }

        // 各状態の実行.

        Vector3 position = this.transform.position;

        switch (this.step)
        {
        case STEP.CARRY:
        case STEP.CARRY_UP:
        {
            position.x = this.player.transform.position.x;
            position.y = this.player.transform.position.y + Block.SIZE_Y;
            position.z = 0.0f;
        }
        break;

        case STEP.DROP_DOWN:
        {
            position = StackBlockControl.calcIndexedPosition(this.place);
        }
        break;
        }

        // オフセットを補間する.

        if (Mathf.Abs(this.position_offset.y) < 0.1f)
        {
            this.position_offset.y = 0.0f;
        }
        else
        {
            const float speed = 0.2f;

            if (this.position_offset.y > 0.0f)
            {
                this.position_offset.y -= speed * (60.0f * Time.deltaTime);

                this.position_offset.y = Mathf.Max(this.position_offset.y, 0.0f);
            }
            else
            {
                this.position_offset.y -= -speed * (60.0f * Time.deltaTime);

                this.position_offset.y = Mathf.Min(this.position_offset.y, 0.0f);
            }
        }

        position.y += this.position_offset.y;

        this.transform.position = position;
    }