コード例 #1
0
ファイル: VanishEffectControl.cs プロジェクト: hafewa/U3Dtest
    public void     createEffect(StackBlock block)
    {
        GameObject fx_prefab = null;

        switch (block.color_type)
        {
        case Block.COLOR_TYPE.CYAN:             fx_prefab = eff_blue;   break;

        case Block.COLOR_TYPE.YELLOW:   fx_prefab = eff_yellow; break;

        case Block.COLOR_TYPE.ORANGE:   fx_prefab = eff_orange; break;

        case Block.COLOR_TYPE.MAGENTA:  fx_prefab = eff_purple; break;

        case Block.COLOR_TYPE.GREEN:    fx_prefab = eff_green;  break;
        }

        if (fx_prefab != null)
        {
            GameObject go = Instantiate(fx_prefab) as GameObject;

            go.AddComponent <FruitEffect>();

            go.transform.position = block.transform.position + Vector3.back * 1.0f;
        }
    }
コード例 #2
0
ファイル: StackBlockControl.cs プロジェクト: hafewa/U3Dtest
    // すべてのブロックの色を選ぶ.
    public void             setColorToAllBlock()
    {
        // places ... 色を選ぶブロックの順番を格納するための配列.
        //
        // place[0] 最初に色を選ぶブロック(の場所).
        // place[1] 2番目に色を選ぶブロック.
        // place[2] 3番目に色を選ぶブロック.
        //            :
        //

        List <StackBlock.PlaceIndex> places = new List <StackBlock.PlaceIndex>();

        // とりあえず左上から順番に並べる.

        for (int y = GROUND_LINE; y < BLOCK_NUM_Y; y++)
        {
            for (int x = 0; x < BLOCK_NUM_X; x++)
            {
                StackBlock.PlaceIndex place;

                place.x = x;
                place.y = y;

                places.Add(place);
            }
        }
        #if true
        // 順番をシャッフルする.
        // ここをコメントアウトすると、スタート時のブロックの並びが
        // 左上から順番っぽくなってしまいます.
        for (int i = 0; i < places.Count - 1; i++)
        {
            int j = Random.Range(i + 1, places.Count);

            StackBlock.PlaceIndex tmp = places[i];

            places[i] = places[j];
            places[j] = tmp;
        }
        // 書籍のコードはこちら.

        /*for(int i = 0;i < places.size() - 1;i++) {
         *
         *      int j = Random.Range(i + 1, places.size());
         *
         *      places.swap(i, j);
         * }*/
        #endif
        this.block_feeder.connect_arrow_num = 1;

        foreach (StackBlock.PlaceIndex place in places)
        {
            StackBlock block = this.blocks[place.x, place.y];

            block.setColorType(this.block_feeder.getNextColorStart(place.x, place.y));
            block.setVisible(true);
        }
    }
コード例 #3
0
    // 选择所有的方块颜色
    public void             setColorToAllBlock()
    {
        // places ⋯⋯ 该数组用于存储选择了某种颜色的方块顺序
        //
        // place[0] 最开始选择了颜色的方块(的位置)
        // place[1] 第2个选择了颜色的方块
        // place[2] 第3个选择了颜色的方块
        //            :
        //

        List <StackBlock.PlaceIndex> places = new List <StackBlock.PlaceIndex>();

        // 暂时从左上开始按顺序排列

        for (int y = GROUND_LINE; y < BLOCK_NUM_Y; y++)
        {
            for (int x = 0; x < BLOCK_NUM_X; x++)
            {
                StackBlock.PlaceIndex place;

                place.x = x;
                place.y = y;

                places.Add(place);
            }
        }
        #if true
        // 随机打乱顺序
        // 如果将这里注释掉,开始时方块将
        // 从左上开始按顺序排列
        for (int i = 0; i < places.Count - 1; i++)
        {
            int j = Random.Range(i + 1, places.Count);

            StackBlock.PlaceIndex tmp = places[i];

            places[i] = places[j];
            places[j] = tmp;
        }
        // 书中的代码是这一段

        /*for(int i = 0;i < places.size() - 1;i++) {
         *
         *      int j = Random.Range(i + 1, places.size());
         *
         *      places.swap(i, j);
         * }*/
        #endif
        this.block_feeder.connect_arrow_num = 1;

        foreach (StackBlock.PlaceIndex place in places)
        {
            StackBlock block = this.blocks[place.x, place.y];

            block.setColorType(this.block_feeder.getNextColorStart(place.x, place.y));
            block.setVisible(true);
        }
    }
コード例 #4
0
ファイル: UndoStack.cs プロジェクト: relimited/Craft
 private void EnsureSpace()
 {
     if (undoStackPointer >= undoDataStack.Length)
     {
         var newDataStack = new StackBlock[undoDataStack.Length * 2];
         Array.Copy(undoDataStack, newDataStack, undoDataStack.Length);
         undoDataStack = newDataStack;
     }
 }
コード例 #5
0
ファイル: UndoStack.cs プロジェクト: relimited/Craft
        internal void MaybeSave(Restorable <T> restorable)
        {
            if (restorable.LastSaveFrame != framepointer)
            {
//#if DEBUG
//                Trace.WriteLine(string.Format("Save {0} <- {1}", undoStackPointer, restorable.RealValue));
//#endif
                EnsureSpace();
                undoDataStack[undoStackPointer] = new StackBlock(restorable);
                undoStackPointer        += 1;
                restorable.LastSaveFrame = framepointer;
            }
        }
コード例 #6
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);
        // 上こちらにすると、回転の中心をずらしたことの影響を受けてしまうのでだめ.
    }
コード例 #7
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);
        // 如果按上面这样做,旋转的中心就会受到偏移的影响,这样是不对的
    }
コード例 #8
0
    // ---------------------------------------------------------------- //

    //画面上的方块被按下时(玩家的操作)的处理
    public void     onDropBlock(StackBlock block)
    {
#if true
        do
        {
            if (!block.isCakeBlock())
            {
                break;
            }

            if (!this.cake.is_enable)
            {
                break;
            }

            //

            this.clearCake();
        } while(false);
#else
        // 蛋糕在画面下方出现(根据玩家操作)时
        // 必须增加蛋糕的出现数量
        // (如果不这样做的话可能会导致蛋糕再也不出现)
        if (block.isCakeBlock())
        {
            if (this.cake.is_enable)
            {
                this.cake.is_enable  = true;
                this.cake.is_active  = false;
                this.cake.x          = block.place.x;
                this.cake.color_type = block.color_type;
            }
        }

        if (this.cake.is_enable && !this.cake.is_active)
        {
            this.cake.out_count++;
        }
#endif
    }
コード例 #9
0
    // ---------------------------------------------------------------- //

    //ブロックが(プレイヤーの操作で)画面下に押し出された時の処理.
    public void     onDropBlock(StackBlock block)
    {
#if true
        do
        {
            if (!block.isCakeBlock())
            {
                break;
            }

            if (!this.cake.is_enable)
            {
                break;
            }

            //

            this.clearCake();
        } while(false);
#else
        // ケーキが(プレイヤーの操作によって)画面下に押し出されたときは
        // ケーキの出現数を増やしておく.
        // (そうしないといつまでたってもケーキが画面に出てこなくなる時があるので).
        if (block.isCakeBlock())
        {
            if (this.cake.is_enable)
            {
                this.cake.is_enable  = true;
                this.cake.is_active  = false;
                this.cake.x          = block.place.x;
                this.cake.color_type = block.color_type;
            }
        }

        if (this.cake.is_enable && !this.cake.is_active)
        {
            this.cake.out_count++;
        }
#endif
    }
コード例 #10
0
    // 开始方块的上下替换
    static public void              beginSwapAction(StackBlock upper_block, StackBlock under_block)
    {
        Block.COLOR_TYPE upper_color;
        StackBlock.STEP  upper_step;
        RotateAction     upper_color_change;

        upper_color        = upper_block.color_type;
        upper_step         = upper_block.step;
        upper_color_change = upper_block.color_change_action;

        upper_block.setColorType(under_block.color_type);
        upper_block.step = under_block.step;
        upper_block.color_change_action = under_block.color_change_action;

        under_block.setColorType(upper_color);
        under_block.step = upper_step;
        under_block.color_change_action = upper_color_change;

        // 开始旋转
        upper_block.swap_action.start(RotateAction.TYPE.SWAP_UP);
        under_block.swap_action.start(RotateAction.TYPE.SWAP_DOWN);
    }
コード例 #11
0
    // 取得下一个方块的颜色(画面下方新出现的方块)
    public Block.COLOR_TYPE getNextColorAppearFromBottom(int x)
    {
        StackBlock[,]           blocks = this.control.blocks;
        Block.COLOR_TYPE color_type = Block.NORMAL_COLOR_FIRST;

        this.init_candidates();

        //

        int y;

        for (y = (int)StackBlockControl.BLOCK_NUM_Y - 1 - 1; y >= 0; y--)
        {
            StackBlock block = blocks[x, y];

            if (block.isConnectable())
            {
                break;
            }
        }

        if (y >= 0)
        {
            Block.COLOR_TYPE erase_color = blocks[x, y].color_type;

            for (int i = 0; i < candidates.Count; i++)
            {
                if (candidates[i] == erase_color)
                {
                    candidates.RemoveAt(i);
                    break;
                }
            }
        }

        color_type = candidates[Random.Range(0, candidates.Count)];

        return(color_type);
    }
コード例 #12
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();
    }
コード例 #13
0
ファイル: StackBlockControl.cs プロジェクト: hafewa/U3Dtest
    // ---------------------------------------------------------------- //

    public void     create()
    {
        //

        this.blocks = new StackBlock[BLOCK_NUM_X, BLOCK_NUM_Y];

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

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

                block.place.x = x;
                block.place.y = y;

                this.blocks[x, y] = block;

                block.setUnused();

                block.stack_control = this;
            }
        }

        //

        this.is_color_enable = new bool[Block.NORMAL_COLOR_NUM];

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

        // ピンクは封印
        this.is_color_enable[(int)Block.COLOR_TYPE.PINK] = false;

        //

        this.connect_checker = new ConnectChecker();

        this.connect_checker.stack_control = this;
        this.connect_checker.blocks        = this.blocks;
        this.connect_checker.create();

        this.block_feeder         = new BlockFeeder();
        this.block_feeder.control = this;
        this.block_feeder.create();

        //

        this.setColorToAllBlock();

        //

        this.combo.is_now_combo        = false;
        this.combo.combo_count_last    = 0;
        this.combo.combo_count_current = 0;

        this.eliminate_count   = 0;
        this.eliminate_to_fall = ELIMINATE_TO_FALL_INIT;
        this.eliminate_to_cake = ELIMINATE_TO_CAKE_INIT;


        this.is_scroll_enable        = true;
        this.is_connect_check_enable = true;
    }
コード例 #14
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();
    }
コード例 #15
0
    public void             update()
    {
        this.is_swap_end_frame = false;

        // ---------------------------------------------------------------- //
        #if false
        // 按下“0”后,从上方落下方块
        if (Input.GetKeyDown(KeyCode.Keypad0))
        {
            this.blockFallRequest();
        }


        // 按下“1”后,颜色改变
        if (Input.GetKeyDown(KeyCode.Keypad1))
        {
            this.startColorChange();
        }

        // 按下“2”后,重新开始
        if (Input.GetKeyDown(KeyCode.Keypad2))
        {
            for (int y = 0; y < BLOCK_NUM_Y; y++)
            {
                for (int x = 0; x < BLOCK_NUM_X; x++)
                {
                    StackBlock block = this.blocks[x, y];

                    block.setUnused();
                }
            }

            this.setColorToAllBlock();
        }

        // 按下“8”后,放大招
        if (Input.GetKeyDown(KeyCode.Keypad8))
        {
            for (int x = 0; x < BLOCK_NUM_X; x++)
            {
                for (int y = GROUND_LINE - this.fall_count; y < BLOCK_NUM_Y; y++)
                {
                    StackBlock block = this.blocks[x, y];

                    block.beginVanishAction();
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.Keypad9))
        {
            //this.CheckConnect();
            //this.block_feeder.beginFeeding();

            for (int x = 0; x < BLOCK_NUM_X; x++)
            {
                StackBlock block = this.blocks[x, BLOCK_NUM_Y - 1];

                block.beginIdle(this.block_feeder.getNextColorAppearFromBottom(x));
            }
        }
        #endif

        // ---------------------------------------------------------------- //
        // 如果有空的方块(连锁后变成灰色),开始交换

        for (int x = 0; x < BLOCK_NUM_X; x++)
        {
            for (int y = GROUND_LINE; y < BLOCK_NUM_Y - 1; y++)
            {
                StackBlock upper_block = this.blocks[x, y];
                StackBlock under_block = this.blocks[x, y + 1];

                do
                {
                    if (!(upper_block.isVacant() && !under_block.isVacant()))
                    {
                        break;
                    }

                    if (upper_block.isNowSwapAction() || under_block.isNowSwapAction())
                    {
                        break;
                    }

                    //

                    StackBlock.beginSwapAction(upper_block, under_block);

                    this.scene_control.playSe(SceneControl.SE.SWAP);
                } while(false);
            }
        }

        // ---------------------------------------------------------------- //
        // 如果空的方块到达最下面一列,设置为新的颜色

        for (int x = 0; x < BLOCK_NUM_X; x++)
        {
            StackBlock block = this.blocks[x, BLOCK_NUM_Y - 1];

            if (!block.isVacant())
            {
                continue;
            }

            if (block.isNowSwapAction())
            {
                continue;
            }

            block.beginIdle(this.block_feeder.getNextColorAppearFromBottom(x));
        }


        // ---------------------------------------------------------------- //
        // 检测结束交换瞬间的状态

        // 由于要对“结束的瞬间”进行处理,提前保存前一帧的结果

        bool is_has_swap_block_prev = this.is_has_swap_block;

        this.is_has_swap_block = false;

        foreach (StackBlock block in this.blocks)
        {
            if (block.isVanishAfter())
            {
                this.is_has_swap_block = true;
                break;
            }
        }

        if (is_has_swap_block_prev && !this.is_has_swap_block)
        {
            this.is_swap_end_frame = true;
        }

        // ---------------------------------------------------------------- //
        // 方块从上方掉落下来

        do
        {
            if (this.fall_request <= 0)
            {
                break;
            }

            if (this.fall_count >= FALL_LINE_NUM)
            {
                break;
            }

            int y = GROUND_LINE - 1 - this.fall_count;

            Block.COLOR_TYPE[] colors = this.block_feeder.getNextColorsAppearFromTop(y);

            for (int x = 0; x < BLOCK_NUM_X; x++)
            {
                StackBlock block = this.blocks[x, y];

                block.beginFallAction(colors[x]);
            }

            this.fall_count++;
            this.fall_request--;
        } while(false);

        // ---------------------------------------------------------------- //
        // 完全落下后,全体滚动

        this.scroll_control();

        // ---------------------------------------------------------------- //
        // 检测连锁

        if (this.is_swap_end_frame)
        {
            this.CheckConnect();
        }

        // ---------------------------------------------------------------- //
        // 方块从蛋糕上方落下时,蛋糕将往上运动
        // (贴心设计)

        if (this.block_feeder.cake.is_enable)
        {
            for (int y = StackBlockControl.GROUND_LINE + 1; y < StackBlockControl.BLOCK_NUM_Y; y++)
            {
                int x = this.block_feeder.cake.x;

                if (!this.blocks[x, y].isCakeBlock())
                {
                    continue;
                }

                // 放下的方块在落地前,最上方的方块是不显示的
                // 这个不显示的时间短内忽略跳过
                if (!this.blocks[x, y - 1].isVisible())
                {
                    continue;
                }

                // 连锁后的方块即时残留着也会被交换
                // (具体来说,因为VanishAction过程中颜色会改变所以必须忽略)
                if (this.blocks[x, y - 1].isVanishAfter())
                {
                    continue;
                }

                //

                StackBlock.beginSwapAction(this.blocks[x, y - 1], this.blocks[x, y]);
            }
        }
    }
コード例 #16
0
    // 方块落下结束时的滚动控制
    private void    scroll_control()
    {
        do
        {
            if (this.fall_count <= 0)
            {
                break;
            }

            //

            bool is_has_fall_block = false;

            for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++)
            {
                StackBlock block = this.blocks[x, StackBlockControl.GROUND_LINE - 1];

                if (block.isNowFallAction())
                {
                    is_has_fall_block = true;
                    break;
                }
            }

            if (!is_has_fall_block)
            {
                if (this.is_scroll_enable)
                {
                    // 蛋糕滚动到区域外时的处理
                    if (this.block_feeder.cake.is_enable)
                    {
                        StackBlock block = this.blocks[this.block_feeder.cake.x, StackBlockControl.BLOCK_NUM_Y - 1];

                        if (block.isCakeBlock())
                        {
                            this.block_feeder.onDropBlock(block);
                        }
                    }

                    // 中间的方块逐列往下偏移
                    for (int y = StackBlockControl.BLOCK_NUM_Y - 1; y >= StackBlockControl.GROUND_LINE; y--)
                    {
                        for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++)
                        {
                            this.blocks[x, y].relayFrom(this.blocks[x, y - 1]);
                        }
                    }

                    // 如果有多行方块落下,则逐行向下偏移
                    if (this.fall_count >= 2)
                    {
                        for (int y = StackBlockControl.GROUND_LINE - 1; y > StackBlockControl.GROUND_LINE - 1 - (this.fall_count - 1); y--)
                        {
                            for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++)
                            {
                                this.blocks[x, y].relayFrom(this.blocks[x, y - 1]);
                            }
                        }
                    }

                    // 如果有多行方块正在落下,最上面一行不显示
                    for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++)
                    {
                        this.blocks[x, StackBlockControl.GROUND_LINE - 1 - (this.fall_count - 1)].setUnused();
                    }
                }

                this.fall_count--;

                this.scene_control.heightGain();

                this.scene_control.playSe(SceneControl.SE.JUMP);
                this.scene_control.playSe(SceneControl.SE.LANDING);
            }
        } while(false);
    }
コード例 #17
0
    // 改变方块的颜色(变为特定的颜色)
    // 吃下蛋糕后的效果
    public void     startColorChange()
    {
        int color_index = 0;

        var after_color = new Block.COLOR_TYPE[2];

        // ------------------------------------------------ //
        // 尽量旋转,并且随机旋转两种颜色

        List <int> candidates = new List <int>();

        for (int i = 0; i < Block.NORMAL_COLOR_NUM; i++)
        {
            // 和上次颜色相同因此不能作为候选值
            if (i == this.change_color_index0 || i == this.change_color_index1)
            {
                continue;
            }
            if (!this.is_color_enable[i])
            {
                continue;
            }

            //

            candidates.Add(i);
        }

        // 从0 到 N - 1 中随机选取两个不重复的数
        // 选择
        // color0 =  0 到 N - 2 范围内的随机数
        // color1 = color0 到 N - 1 范围内的随机数
        //

        this.change_color_index0 = Random.Range(0, candidates.Count - 1);
        this.change_color_index1 = Random.Range(this.change_color_index0 + 1, candidates.Count);

        this.change_color_index0 = candidates[this.change_color_index0];
        this.change_color_index1 = candidates[this.change_color_index1];

        // ------------------------------------------------ //
        // 改变方块的颜色

        after_color[0] = (Block.COLOR_TYPE)change_color_index0;
        after_color[1] = (Block.COLOR_TYPE)change_color_index1;

        for (int x = 0; x < BLOCK_NUM_X; x++)
        {
            for (int y = GROUND_LINE - this.fall_count; y < BLOCK_NUM_Y; y++)
            {
                StackBlock block = this.blocks[x, y];

                if (block.isVacant())
                {
                    continue;
                }

                // 如果最开始的颜色和变更后颜色数组中存在相同值则忽略
                if (System.Array.Exists(after_color, c => c == block.color_type))
                {
                    continue;
                }

                if (!block.isNormalColorBlock())
                {
                    continue;
                }

                // 开始改变颜色

                Block.COLOR_TYPE target_color;

                target_color = after_color[color_index % after_color.Length];

                block.beginColorChangeAction(target_color);

                color_index++;
            }
        }
    }
コード例 #18
0
ファイル: StackBlockControl.cs プロジェクト: hafewa/U3Dtest
    public void             update()
    {
        this.is_swap_end_frame = false;

        // ---------------------------------------------------------------- //
        #if false
        // "0" を押すと、上からブロックが降ってくる.
        if (Input.GetKeyDown(KeyCode.Keypad0))
        {
            this.blockFallRequest();
        }


        // "1" を押すと、カラーチェンジ.
        if (Input.GetKeyDown(KeyCode.Keypad1))
        {
            this.startColorChange();
        }

        // "2" を押すと、リスタート.
        if (Input.GetKeyDown(KeyCode.Keypad2))
        {
            for (int y = 0; y < BLOCK_NUM_Y; y++)
            {
                for (int x = 0; x < BLOCK_NUM_X; x++)
                {
                    StackBlock block = this.blocks[x, y];

                    block.setUnused();
                }
            }

            this.setColorToAllBlock();
        }

        // "8" を押すと、メガクラッシュ.
        if (Input.GetKeyDown(KeyCode.Keypad8))
        {
            for (int x = 0; x < BLOCK_NUM_X; x++)
            {
                for (int y = GROUND_LINE - this.fall_count; y < BLOCK_NUM_Y; y++)
                {
                    StackBlock block = this.blocks[x, y];

                    block.beginVanishAction();
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.Keypad9))
        {
            //this.CheckConnect();
            //this.block_feeder.beginFeeding();

            for (int x = 0; x < BLOCK_NUM_X; x++)
            {
                StackBlock block = this.blocks[x, BLOCK_NUM_Y - 1];

                block.beginIdle(this.block_feeder.getNextColorAppearFromBottom(x));
            }
        }
        #endif

        // ---------------------------------------------------------------- //
        // 空のブロック(連鎖した後の灰色)があったら、スワップ動作を開始する.

        for (int x = 0; x < BLOCK_NUM_X; x++)
        {
            for (int y = GROUND_LINE; y < BLOCK_NUM_Y - 1; y++)
            {
                StackBlock upper_block = this.blocks[x, y];
                StackBlock under_block = this.blocks[x, y + 1];

                do
                {
                    if (!(upper_block.isVacant() && !under_block.isVacant()))
                    {
                        break;
                    }

                    if (upper_block.isNowSwapAction() || under_block.isNowSwapAction())
                    {
                        break;
                    }

                    //

                    StackBlock.beginSwapAction(upper_block, under_block);

                    this.scene_control.playSe(SceneControl.SE.SWAP);
                } while(false);
            }
        }

        // ---------------------------------------------------------------- //
        // 空のブロックが一番下の列に到達したら、新たな色をセットする.

        for (int x = 0; x < BLOCK_NUM_X; x++)
        {
            StackBlock block = this.blocks[x, BLOCK_NUM_Y - 1];

            if (!block.isVacant())
            {
                continue;
            }

            if (block.isNowSwapAction())
            {
                continue;
            }

            block.beginIdle(this.block_feeder.getNextColorAppearFromBottom(x));
        }


        // ---------------------------------------------------------------- //
        // スワップ動作が終了した瞬間がどうかを調べる.

        // 『終了した瞬間』を拾いたいので、前のフレームの結果を保存しておく.

        bool is_has_swap_block_prev = this.is_has_swap_block;

        this.is_has_swap_block = false;

        foreach (StackBlock block in this.blocks)
        {
            if (block.isVanishAfter())
            {
                this.is_has_swap_block = true;
                break;
            }
        }

        if (is_has_swap_block_prev && !this.is_has_swap_block)
        {
            this.is_swap_end_frame = true;
        }

        // ---------------------------------------------------------------- //
        // 上からブロックが降ってくる.

        do
        {
            if (this.fall_request <= 0)
            {
                break;
            }

            if (this.fall_count >= FALL_LINE_NUM)
            {
                break;
            }

            int y = GROUND_LINE - 1 - this.fall_count;

            Block.COLOR_TYPE[] colors = this.block_feeder.getNextColorsAppearFromTop(y);

            for (int x = 0; x < BLOCK_NUM_X; x++)
            {
                StackBlock block = this.blocks[x, y];

                block.beginFallAction(colors[x]);
            }

            this.fall_count++;
            this.fall_request--;
        } while(false);

        // ---------------------------------------------------------------- //
        // 落下が終了したら、全体をスクロール.

        this.scroll_control();

        // ---------------------------------------------------------------- //
        // 連鎖チェック.

        if (this.is_swap_end_frame)
        {
            this.CheckConnect();
        }

        // ---------------------------------------------------------------- //
        // ケーキの上にブロックが落下したときは、ケーキが上がってくる.
        // (親切設計).

        if (this.block_feeder.cake.is_enable)
        {
            for (int y = StackBlockControl.GROUND_LINE + 1; y < StackBlockControl.BLOCK_NUM_Y; y++)
            {
                int x = this.block_feeder.cake.x;

                if (!this.blocks[x, y].isCakeBlock())
                {
                    continue;
                }

                // ドロップしたブロックが着地するまで、一番上のブロックは非表示になっている.
                // その非表示の間はスキップ.
                if (!this.blocks[x, y - 1].isVisible())
                {
                    continue;
                }

                // 連鎖後のブロックはほっといてもスワップされる.
                // (というより VanishAction の途中でカラーがかわってしまうからスキップしない
                //  とまずい).
                if (this.blocks[x, y - 1].isVanishAfter())
                {
                    continue;
                }

                //

                StackBlock.beginSwapAction(this.blocks[x, y - 1], this.blocks[x, y]);
            }
        }
    }
コード例 #19
0
    void Update()
    {
        StackBlockControl stack_control = this.scene_control.stack_control;

        this.step_timer += Time.deltaTime;

        // ---------------------------------------------------------------- //
#if false
        // 按下“3”后,能量减少
        if (Input.GetKey(KeyCode.Keypad3))
        {
            this.addLife(-1);
        }
        // 按下“4”后,能量增加
        if (Input.GetKey(KeyCode.Keypad4))
        {
            this.addLife(1);
        }
#endif

        // 饥饿达到一定程度后,游戏结束
        if (this.life <= LIFE_MIN)
        {
            this.next_step = STEP.HUNGRY;
        }

        //
        // 检测是否移到下一个状态
        switch (this.step)
        {
        case STEP.NORMAL:
        case STEP.EATING:
        {
            // 举起

            if (this.next_step == STEP.NONE)
            {
                do
                {
                    if (!this.is_carry_input())
                    {
                        break;
                    }

                    // 脚下的方块
                    StackBlock ground_block = stack_control.blocks[this.lx, StackBlockControl.GROUND_LINE];

                    // 灰色的方块不能被举起
                    if (!ground_block.isCarriable())
                    {
                        break;
                    }

                    // 正在执行交换的方块不能被举起
                    if (ground_block.isNowSwapAction())
                    {
                        break;
                    }

                    //

                    // 将举起的方块的颜色设置为和脚下方块相同
                    this.carry_block.setColorType(ground_block.color_type);
                    this.carry_block.startCarry(this.lx);

                    stack_control.pickBlock(this.lx);

                    //

                    this.GetComponent <AudioSource>().PlayOneShot(this.audio_pick);

                    this.next_step = STEP.CARRY;
                } while(false);
            }

            if (this.next_step == STEP.NONE)
            {
                if (this.step == STEP.EATING)
                {
                    if (this.step_timer > 3.0f)
                    {
                        this.next_step = STEP.NORMAL;
                    }
                }
            }
        }
        break;

        case STEP.CARRY:
        {
            if (this.is_carry_input())
            {
                // 放下

                if (this.carry_block.isCakeBlock())
                {
                    // 如果举起的时蛋糕,
                    // 吃掉 & 改变颜色

                    this.carry_block.startHide();

                    stack_control.onEatCake();

                    this.addLife(LIFE_ADD_CAKE);

                    this.GetComponent <AudioSource>().PlayOneShot(scene_control.audio_clips[(int)SceneControl.SE.EATING]);

                    //

                    this.next_step = STEP.EATING;
                }
                else
                {
                    // 如果举起的是普通的方块,则放下

                    this.drop_block();

                    this.addLife(LIFE_SUB);

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

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

        if (this.next_step != STEP.NONE)
        {
            switch (this.next_step)
            {
            case STEP.NORMAL:
            {
            }
            break;

            case STEP.HUNGRY:
            {
            }
            break;

            case STEP.GOAL_ACT:
            {
                this.SetHeight(-1);
            }
            break;
            }

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

            this.step_timer = 0.0f;
        }

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

        switch (this.step)
        {
        case STEP.NORMAL:
        case STEP.CARRY:
        case STEP.EATING:
        {
            int lx = this.lx;

            // 左右移动

            do
            {
                // 举起,放下过程中不能左右移动
                //
                // 如果习惯于这种操作,有时可能会无法移动影响了游戏操作
                // 屏蔽
                //

                /*if(this.carry_block.isMoving()) {
                 *
                 *      break;
                 * }*/

                //

                if (!this.is_controlable)
                {
                    break;
                }

                if (Input.GetKeyDown(KeyCode.LeftArrow))
                {
                    lx--;
                }
                else if (Input.GetKeyDown(KeyCode.RightArrow))
                {
                    lx++;
                }
                else
                {
                    break;
                }

                lx = Mathf.Clamp(lx, 0, StackBlockControl.BLOCK_NUM_X - 1);

                this.GetComponent <AudioSource>().PlayOneShot(this.audio_walk);

                this.SetLinedPosition(lx);
            } while(false);
        }
        break;
        }

        // ---------------------------------------------------------------- //
        // 控制纹理模式

        switch (this.step)
        {
        default:
        case STEP.NORMAL:
        {
            // 左→闭上眼睛→右→闭上眼睛→循环

            int texture_index;

            texture_index  = (int)(this.step_timer * 8.0f);
            texture_index %= 4;

            if (texture_index % 2 == 0)
            {
                // 闭上眼睛
                texture_index = 0;
            }
            else
            {
                // 右,左
                texture_index = (texture_index / 2) % 2 + 1;
            }

            this.sprite.SetTexture(this.textures_normal[texture_index]);
        }
        break;

        case STEP.CARRY:
        {
            int texture_index;

            texture_index  = (int)(this.step_timer * 8.0f);
            texture_index %= 4;

            if (texture_index % 2 == 0)
            {
                texture_index = 0;
            }
            else
            {
                texture_index = (texture_index / 2) % 2 + 1;
            }

            this.sprite.SetTexture(this.textures_carry[texture_index]);
        }
        break;

        case STEP.EATING:
        {
            int texture_index = ((int)(this.step_timer / 0.1f)) % this.textures_eating.Length;

            this.sprite.SetTexture(this.textures_eating[texture_index]);
        }
        break;

        case STEP.HUNGRY:
        {
            this.sprite.SetTexture(this.texture_hungry);
        }
        break;

        case STEP.GOAL_ACT:
        {
            const float time0 = 0.5f;
            const float time1 = 0.5f;

            float time_all = time0 + time1;

            float t = Mathf.Repeat(this.step_timer, time_all);

            if (t < time0)
            {
                this.sprite.SetTexture(this.textures_carry[1]);
            }
            else
            {
                t -= time0;

                int texture_index = ((int)(t / 0.1f)) % this.textures_eating.Length;

                this.sprite.SetTexture(this.textures_eating[texture_index]);
            }
        }
        break;
        }
    }
コード例 #20
0
ファイル: StackBlockControl.cs プロジェクト: hafewa/U3Dtest
    // ブロックの落下が終了したときの、スクロール制御.
    private void    scroll_control()
    {
        do
        {
            if (this.fall_count <= 0)
            {
                break;
            }

            //

            bool is_has_fall_block = false;

            for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++)
            {
                StackBlock block = this.blocks[x, StackBlockControl.GROUND_LINE - 1];

                if (block.isNowFallAction())
                {
                    is_has_fall_block = true;
                    break;
                }
            }

            if (!is_has_fall_block)
            {
                if (this.is_scroll_enable)
                {
                    // ケーキがスクロールアウトしたときの処理.
                    if (this.block_feeder.cake.is_enable)
                    {
                        StackBlock block = this.blocks[this.block_feeder.cake.x, StackBlockControl.BLOCK_NUM_Y - 1];

                        if (block.isCakeBlock())
                        {
                            this.block_feeder.onDropBlock(block);
                        }
                    }

                    // 地中のブロックを一列づつ下にずらす.
                    for (int y = StackBlockControl.BLOCK_NUM_Y - 1; y >= StackBlockControl.GROUND_LINE; y--)
                    {
                        for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++)
                        {
                            this.blocks[x, y].relayFrom(this.blocks[x, y - 1]);
                        }
                    }

                    // 落下中のラインが複数あったとき、落下中のラインを一つづつずらす.
                    if (this.fall_count >= 2)
                    {
                        for (int y = StackBlockControl.GROUND_LINE - 1; y > StackBlockControl.GROUND_LINE - 1 - (this.fall_count - 1); y--)
                        {
                            for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++)
                            {
                                this.blocks[x, y].relayFrom(this.blocks[x, y - 1]);
                            }
                        }
                    }

                    // 落下中のラインの、一番上のラインを非表示にする.
                    for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++)
                    {
                        this.blocks[x, StackBlockControl.GROUND_LINE - 1 - (this.fall_count - 1)].setUnused();
                    }
                }

                this.fall_count--;

                this.scene_control.heightGain();

                this.scene_control.playSe(SceneControl.SE.JUMP);
                this.scene_control.playSe(SceneControl.SE.LANDING);
            }
        } while(false);
    }
コード例 #21
0
ファイル: StackBlockControl.cs プロジェクト: hafewa/U3Dtest
    // ブロックの色が変わる(特定の色だけになる).
    // ケーキを食べたときの効果.
    public void     startColorChange()
    {
        int color_index = 0;

        var after_color = new Block.COLOR_TYPE[2];

        // ------------------------------------------------ //
        // なるべく前回と違う、かつランダムに色をふたつ選ぶ.

        List <int> candidates = new List <int>();

        for (int i = 0; i < Block.NORMAL_COLOR_NUM; i++)
        {
            // 前回と同じ色は候補からはずす.
            if (i == this.change_color_index0 || i == this.change_color_index1)
            {
                continue;
            }
            if (!this.is_color_enable[i])
            {
                continue;
            }

            //

            candidates.Add(i);
        }

        // 0 ~ N - 1 の乱数を重複なくふたつ選ぶため、
        //
        // color0 = 0 ~ N - 2 の範囲の乱数.
        // color1 = color0 ~ N - 1 の範囲の乱数.
        //
        // を選ぶ.
        this.change_color_index0 = Random.Range(0, candidates.Count - 1);
        this.change_color_index1 = Random.Range(this.change_color_index0 + 1, candidates.Count);

        this.change_color_index0 = candidates[this.change_color_index0];
        this.change_color_index1 = candidates[this.change_color_index1];

        // ------------------------------------------------ //
        // ブロックの色を変える.

        after_color[0] = (Block.COLOR_TYPE)change_color_index0;
        after_color[1] = (Block.COLOR_TYPE)change_color_index1;

        for (int x = 0; x < BLOCK_NUM_X; x++)
        {
            for (int y = GROUND_LINE - this.fall_count; y < BLOCK_NUM_Y; y++)
            {
                StackBlock block = this.blocks[x, y];

                if (block.isVacant())
                {
                    continue;
                }

                // 最初からカラーチェンジ後のカラーだった場合はスキップ.
                if (System.Array.Exists(after_color, c => c == block.color_type))
                {
                    continue;
                }

                if (!block.isNormalColorBlock())
                {
                    continue;
                }

                // カラーチェンジを開始する.

                Block.COLOR_TYPE target_color;

                target_color = after_color[color_index % after_color.Length];

                block.beginColorChangeAction(target_color);

                color_index++;
            }
        }
    }
コード例 #22
0
ファイル: RotateAction.cs プロジェクト: hafewa/U3Dtest
    // 回転動作の実行.
    public void     execute(StackBlock block)
    {
        float x_angle = 0.0f;
        float rotate_time;

        if (this.type == RotateAction.TYPE.COLOR_CHANGE)
        {
            rotate_time = 0.5f;
        }
        else
        {
            rotate_time = RotateAction.rotate_time_swap;
        }

        if (this.is_active)
        {
            this.timer += Time.deltaTime;

            // 終了チェック.

            if (this.timer > rotate_time)
            {
                this.timer     = rotate_time;
                this.is_active = false;
            }

            // 回転の中心.

            Vector3 rotation_center = Vector3.zero;

            if (this.is_active)
            {
                switch (this.type)
                {
                case RotateAction.TYPE.SWAP_UP:
                {
                    rotation_center.y = -Block.SIZE_Y / 2.0f;
                }
                break;

                case RotateAction.TYPE.SWAP_DOWN:
                {
                    rotation_center.y = Block.SIZE_Y / 2.0f;
                }
                break;

                case RotateAction.TYPE.COLOR_CHANGE:
                {
                    rotation_center.y = 0.0f;
                }
                break;
                }

                // 角度.

                this.rate = this.timer / rotate_time;

                this.rate = Mathf.Lerp(-Mathf.PI / 2.0f, Mathf.PI / 2.0f, this.rate);
                this.rate = (Mathf.Sin(this.rate) + 1.0f) / 2.0f;

                x_angle = Mathf.Lerp(-180.0f, 0.0f, this.rate);
            }

            // rotation_center を中心に、相対的に回転する.
            block.transform.Translate(rotation_center);
            block.transform.Rotate(Vector3.right, x_angle);
            block.transform.Translate(-rotation_center);
        }
    }
コード例 #23
0
    public void             execute()
    {
        StackBlockControl stack_control = this.scene_control.stack_control;
        PlayerControl     player        = this.scene_control.player_control;
        BGControl         bg            = this.scene_control.bg_control;

        this.step_timer_prev = this.step_timer;
        this.step_timer     += Time.deltaTime;

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

        switch (this.step)
        {
        case STEP.START:
        {
            this.next_step = STEP.WAIT_SWAP_END;
        }
        break;

        case STEP.WAIT_SWAP_END:
        {
            bool is_has_moving_block = false;

            foreach (StackBlock block in stack_control.blocks)
            {
                if (block.step != StackBlock.STEP.IDLE || block.next_step != StackBlock.STEP.NONE)
                {
                    is_has_moving_block = true;
                    break;
                }

                if (block.position_offset.y != 0.0f)
                {
                    is_has_moving_block = true;
                    break;
                }
            }

            if (!is_has_moving_block)
            {
                this.next_step = STEP.WAIT_SWAP_END_AFTER;
            }
        }
        break;

        case STEP.WAIT_SWAP_END_AFTER:
        {
            if (this.step_timer > 1.0f)
            {
                this.next_step = STEP.FALL;
            }
        }
        break;

        case STEP.FALL:
        {
            bool is_has_fall_block = false;

            for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++)
            {
                StackBlock block = stack_control.blocks[x, StackBlockControl.GROUND_LINE - 1];

                if (block.isNowFallAction())
                {
                    is_has_fall_block = true;
                    break;
                }
            }

            if (!is_has_fall_block)
            {
                this.next_step = STEP.COLOR_CHANGE;
            }
        }
        break;

        case STEP.COLOR_CHANGE:
        {
            if (this.step_timer > 1.0f && player.lx == PLAYER_EATING_POSITION)
            {
                this.begin_wait_step(1.0f, STEP.MESSAGE);
            }
        }
        break;

        case STEP.WAIT:
        {
            if (this.step_timer > this.wait.duration)
            {
                this.next_step = this.wait.next_step;
            }
        }
        break;
        }

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

        if (this.next_step != STEP.NONE)
        {
            switch (this.next_step)
            {
            case STEP.START:
            {
                player.setControlable(false);
            }
            break;

            case STEP.FALL:
            {
                player.dropBlock();

                bg.setHeightRateDirect(1.0f);

                stack_control.is_scroll_enable = false;
                stack_control.fall_request     = 0;
                stack_control.blockFallRequest();

                for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++)
                {
                    stack_control.blocks[x, StackBlockControl.GROUND_LINE - 1].beginColorChangeAction(Block.COLOR_TYPE.CYAN);
                }

                //

                this.pat_count = 0;
            }
            break;

            case STEP.COLOR_CHANGE:
            {
                this.color_change_count = 0;

                player.SetHeight(-1);
            }
            break;

            case STEP.MESSAGE:
            {
                this.message_color = Block.NORMAL_COLOR_FIRST;

                player.beginGoalAct();

                scene_control.playSe(SceneControl.SE.CLEAR);
            }
            break;
            }

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

            this.step_timer_prev = -1.0f;
            this.step_timer      = 0.0f;
        }

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

        switch (this.step)
        {
        case STEP.COLOR_CHANGE:
        {
            if (this.color_change_count < StackBlockControl.BLOCK_NUM_Y - StackBlockControl.GROUND_LINE)
            {
                float delay = 0.05f;

                if (Mathf.FloorToInt(this.step_timer_prev / delay) < Mathf.FloorToInt(this.step_timer / delay))
                {
                    int y = StackBlockControl.GROUND_LINE + this.color_change_count;

                    for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++)
                    {
                        stack_control.blocks[x, y].beginColorChangeAction(Block.COLOR_TYPE.CYAN);
                    }

                    this.color_change_count++;
                }
            }

            if (player.lx != PLAYER_EATING_POSITION)
            {
                float delay = 0.5f;

                if (this.step_timer > delay * 2.0f)
                {
                    if (Mathf.FloorToInt(this.step_timer_prev / delay) < Mathf.FloorToInt(this.step_timer / delay))
                    {
                        if (player.lx > PLAYER_EATING_POSITION)
                        {
                            player.SetLinedPosition(player.lx - 1);
                        }
                        else
                        {
                            player.SetLinedPosition(player.lx + 1);
                        }
                    }
                }
            }
        }
        break;

        case STEP.MESSAGE:
        {
            float duration = 2.0f;

            if (this.step_timer >= duration)
            {
                if (Mathf.FloorToInt(this.step_timer_prev / duration) < Mathf.FloorToInt(this.step_timer / duration))
                {
                    do
                    {
                        this.message_color = Block.getNextNormalColor(this.message_color);
                    } while(this.message_color == Block.COLOR_TYPE.CYAN);

                    this.apply_pattern_to_block(this.message[this.pat_count], this.message_color, Block.COLOR_TYPE.CYAN);

                    this.pat_count = (this.pat_count + 1) % this.message.Length;
                }
            }
        }
        break;
        }

        // ---------------------------------------------------------------- //
    }
コード例 #24
0
ファイル: PlayerControl.cs プロジェクト: hafewa/U3Dtest
    void Update()
    {
        StackBlockControl stack_control = this.scene_control.stack_control;

        this.step_timer += Time.deltaTime;

        // ---------------------------------------------------------------- //
#if false
        // "3" を押すと、エネルギー減少.
        if (Input.GetKey(KeyCode.Keypad3))
        {
            this.addLife(-1);
        }
        // "4" を押すと、エネルギー減少.
        if (Input.GetKey(KeyCode.Keypad4))
        {
            this.addLife(1);
        }
#endif

        // 腹ペコになったら、ゲームオーバー.
        if (this.life <= LIFE_MIN)
        {
            this.next_step = STEP.HUNGRY;
        }

        //
        // 次の状態に移るかどうかを、チェックする.
        switch (this.step)
        {
        case STEP.NORMAL:
        case STEP.EATING:
        {
            // 持ち上げ.

            if (this.next_step == STEP.NONE)
            {
                do
                {
                    if (!this.is_carry_input())
                    {
                        break;
                    }

                    // 足元のブロック.
                    StackBlock ground_block = stack_control.blocks[this.lx, StackBlockControl.GROUND_LINE];

                    // 灰色のブロックは持ち上げられない.
                    if (!ground_block.isCarriable())
                    {
                        break;
                    }

                    // スワップ動作中は持ち上げられない.
                    if (ground_block.isNowSwapAction())
                    {
                        break;
                    }

                    //

                    // キャリーブロックを、足元のブロックと同じ色にする.
                    this.carry_block.setColorType(ground_block.color_type);
                    this.carry_block.startCarry(this.lx);

                    stack_control.pickBlock(this.lx);

                    //

                    this.GetComponent <AudioSource>().PlayOneShot(this.audio_pick);

                    this.next_step = STEP.CARRY;
                } while(false);
            }

            if (this.next_step == STEP.NONE)
            {
                if (this.step == STEP.EATING)
                {
                    if (this.step_timer > 3.0f)
                    {
                        this.next_step = STEP.NORMAL;
                    }
                }
            }
        }
        break;

        case STEP.CARRY:
        {
            if (this.is_carry_input())
            {
                // ぽい捨て.

                if (this.carry_block.isCakeBlock())
                {
                    // 持ち上げていたのがケーキだったら、
                    // もぐもぐ&カラーチェンジ.

                    this.carry_block.startHide();

                    stack_control.onEatCake();

                    this.addLife(LIFE_ADD_CAKE);

                    this.GetComponent <AudioSource>().PlayOneShot(scene_control.audio_clips[(int)SceneControl.SE.EATING]);

                    //

                    this.next_step = STEP.EATING;
                }
                else
                {
                    // 持ち上げていたのが普通のブロックだったら、ぽい捨て.

                    this.drop_block();

                    this.addLife(LIFE_SUB);

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

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

        if (this.next_step != STEP.NONE)
        {
            switch (this.next_step)
            {
            case STEP.NORMAL:
            {
            }
            break;

            case STEP.HUNGRY:
            {
            }
            break;

            case STEP.GOAL_ACT:
            {
                this.SetHeight(-1);
            }
            break;
            }

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

            this.step_timer = 0.0f;
        }

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

        switch (this.step)
        {
        case STEP.NORMAL:
        case STEP.CARRY:
        case STEP.EATING:
        {
            int lx = this.lx;

            // 左右移動.

            do
            {
                // 持ち上げ、ぽい捨て中は左右に移動できない.
                //
                // 慣れてくると、少しでも動けないときがあるのがストレスになるので
                // 封印
                //

                /*if(this.carry_block.isMoving()) {
                 *
                 *      break;
                 * }*/

                //

                if (!this.is_controlable)
                {
                    break;
                }

                if (Input.GetKeyDown(KeyCode.LeftArrow))
                {
                    lx--;
                }
                else if (Input.GetKeyDown(KeyCode.RightArrow))
                {
                    lx++;
                }
                else
                {
                    break;
                }

                lx = Mathf.Clamp(lx, 0, StackBlockControl.BLOCK_NUM_X - 1);

                this.GetComponent <AudioSource>().PlayOneShot(this.audio_walk);

                this.SetLinedPosition(lx);
            } while(false);
        }
        break;
        }

        // ---------------------------------------------------------------- //
        // テクスチャーパターンのコントロール.

        switch (this.step)
        {
        default:
        case STEP.NORMAL:
        {
            // 左→目閉じる→右→目閉じる→ループ.

            int texture_index;

            texture_index  = (int)(this.step_timer * 8.0f);
            texture_index %= 4;

            if (texture_index % 2 == 0)
            {
                // 目を閉じる.
                texture_index = 0;
            }
            else
            {
                // 右、左
                texture_index = (texture_index / 2) % 2 + 1;
            }

            this.sprite.SetTexture(this.textures_normal[texture_index]);
        }
        break;

        case STEP.CARRY:
        {
            int texture_index;

            texture_index  = (int)(this.step_timer * 8.0f);
            texture_index %= 4;

            if (texture_index % 2 == 0)
            {
                texture_index = 0;
            }
            else
            {
                texture_index = (texture_index / 2) % 2 + 1;
            }

            this.sprite.SetTexture(this.textures_carry[texture_index]);
        }
        break;

        case STEP.EATING:
        {
            int texture_index = ((int)(this.step_timer / 0.1f)) % this.textures_eating.Length;

            this.sprite.SetTexture(this.textures_eating[texture_index]);
        }
        break;

        case STEP.HUNGRY:
        {
            this.sprite.SetTexture(this.texture_hungry);
        }
        break;

        case STEP.GOAL_ACT:
        {
            const float time0 = 0.5f;
            const float time1 = 0.5f;

            float time_all = time0 + time1;

            float t = Mathf.Repeat(this.step_timer, time_all);

            if (t < time0)
            {
                this.sprite.SetTexture(this.textures_carry[1]);
            }
            else
            {
                t -= time0;

                int texture_index = ((int)(t / 0.1f)) % this.textures_eating.Length;

                this.sprite.SetTexture(this.textures_eating[texture_index]);
            }
        }
        break;
        }
    }