Ejemplo n.º 1
0
    void    Update()
    {
        // ---------------------------------------------------------------- //

        this.step_timer_prev = this.step_timer;

        this.step_timer += Time.deltaTime;

        // ---------------------------------------------------------------- //
        // 检测状态迁移

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

        case STEP.PLAY:
        {
            // 如果碎片全部都被放置到正解的位置上,清空
            if (this.piece_finished_num >= this.piece_num)
            {
                this.next_step = STEP.CLEAR;
            }
        }
        break;
        }

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

        if (this.next_step != STEP.NONE)
        {
            switch (this.next_step)
            {
            case STEP.PLAY:
            {
                // 由于 this.active_pieces = this.all_pieces ,数组的引用都已经被拷贝,
                // 一个一个进行拷贝
                for (int i = 0; i < this.all_pieces.Length; i++)
                {
                    this.active_pieces[i] = this.all_pieces[i];
                }

                this.piece_finished_num = 0;

                this.shuffle_pieces();

                foreach (PieceControl piece in this.active_pieces)
                {
                    piece.Restart();
                }

                // 设置碎片的绘制顺序
                //
                this.set_height_offset_to_pieces();
            }
            break;

            case STEP.CLEAR:
            {
            }
            break;
            }

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

            this.step_timer = 0.0f;
        }

        // ---------------------------------------------------------------- //
        // 执行处理

        switch (this.step)
        {
        case STEP.CLEAR:
        {
            // 完成时的音乐

            const float play_se_delay = 0.40f;

            if (this.step_timer_prev < play_se_delay && play_se_delay <= this.step_timer)
            {
                this.game_control.playSe(GameControl.SE.COMPLETE);
                this.is_disp_cleared = true;
            }
        }
        break;
        }

        PazzleControl.DrawBounds(this.shuffle_zone);
    }
Ejemplo n.º 2
0
    void Update()
    {
        PazzleControl.DrawBounds(this.GetBounds(Vector3.zero));


        Color color = this.origin_color;

        switch (this.state)
        {
        case STATE.NONE:
        {
            this.next_state = STATE.RESTART;
        }
        break;

        case STATE.IDLE:
        {
            if (this.is_now_dragging)
            {
                this.next_state = STATE.DRAGING;
            }
        }
        break;

        case STATE.DRAGING:
        {
            // 鼠标放开时
            if (!this.is_now_dragging)
            {
                // 在吸附范围内
                if (this.is_in_snap_range())
                {
                    this.next_state      = STATE.SNAPPING;
                    this.snap_target     = this.finished_position;
                    this.next_state_snap = STATE.FINISHED;
                }
                // 在吸附范围外
                else
                {
                    this.next_state = STATE.IDLE;
                }
            }
        }
        break;

        case STATE.SNAPPING:
        {
            if ((this.transform.position - this.snap_target).magnitude < 0.0001f)
            {
                this.next_state = this.next_state_snap;
            }
        }
        break;
        }

        if (this.next_state != STATE.NONE)
        {
            switch (this.next_state)
            {
            //case STATE.IDLE:
            //    {
            //        // this.SetHeightOffset(this.height_offset);
            //    }
            //    break;
            case STATE.RESTART:
            {
                this.transform.position = this.start_position;
                // this.SetHeightOffset(this.height_offset);
                this.next_state = STATE.IDLE;
            }
            break;

            case STATE.DRAGING:
            {
                this.begin_dragging();
                this.pazzle_control.PickPiece(this);
            }
            break;

            case STATE.FINISHED:
            {
                this.transform.position = this.finished_position;
                this.pazzle_control.FinishPiece(this);
            }
            break;
            }

            this.state      = this.next_state;
            this.next_state = STATE.NONE;
        }

        this.transform.localScale = Vector3.one;

        switch (this.state)
        {
        case STATE.DRAGING:
        {
            this.do_dragging();

            if (this.is_in_snap_range())
            {
                color = Color.Lerp(color, Color.white, .5f);
            }

            this.transform.localScale = Vector3.one * 1.1f;
        }
        break;

        case STATE.SNAPPING:
        {
            Vector3 next_position, distance, move;
            distance = this.snap_target - this.transform.position;

            distance *= 0.25f * (60.0f * Time.deltaTime);

            next_position = this.transform.position + distance;
            move          = next_position - this.transform.position;

            float snap_speed_min = PieceControl.SNAP_SPEED_MIN * Time.deltaTime;
            float snap_speed_max = PieceControl.SNAP_SPEED_MAX * Time.deltaTime;

            if (move.magnitude < snap_speed_min)
            {
                this.transform.position = this.snap_target;
            }
            else
            {
                if (move.magnitude > snap_speed_max)
                {
                    move         *= snap_speed_max / move.magnitude;
                    next_position = this.transform.position + move;
                }
                this.transform.position = next_position;
            }
        }
        break;
        }

        this.GetComponent <Renderer>().material.color = color;
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        //-------------------------------------------------------------------------//

        this.step_timer_prev = this.step_timer;

        this.step_timer += Time.deltaTime;

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

        #region//检测状态迁移
        switch (this.step)
        {
        case STEP.NONE:
        {
            this.next_step = STEP.PLAY;
        }
        break;

        case STEP.PLAY:
        {
            //如果碎片全部都被放置到正解位置,清空
            if (this.piece_finished_num >= this.piece_num)
            {
                this.next_step = STEP.CLEAR;
            }
        }
        break;
        }
        #endregion

        //-------------------------------------------------------------------------//
        //迁移时的初始化
        //当next_step不为NONE时,意味着要改变当前游戏状态
        if (this.next_step != STEP.NONE)
        {
            switch (this.next_step)
            {
            case STEP.PLAY:
            {
                //Play时,进行游戏初始化
                for (int i = 0; i < this.all_pieces.Length; i++)
                {
                    this.active_pieces[i] = this.all_pieces[i];
                }

                this.piece_finished_num = 0;

                this.Shuffle_Piece();

                foreach (PieceControl piece in this.active_pieces)
                {
                    piece.Restart();
                }

                //设置碎片的绘制顺序
                this.Set_Height_Offset_To_Pieces();
            }
            break;
            }
            //给当前状态赋值
            this.step = this.next_step;
            //再把下一个状态赋值为NONE
            this.next_step = STEP.NONE;

            this.step_timer = 0.0f;
        }
        //----------------------------------------------------------------
        //执行处理

        switch (this.step)
        {
        case STEP.CLEAR:
        {
            //完成时的音乐

            const float play_se_delay = 0.4f;

            if (this.step_timer_prev < play_se_delay && play_se_delay <= this.step_timer)
            {
                this.game_control.PlaySe(GameControl.SE.COMPLETE);
            }
        }
        break;
        }

        PazzleControl.DrawBounds(this.shuffle_zone);
    }
Ejemplo n.º 4
0
    void    Update()
    {
        // ---------------------------------------------------------------- //

        this.step_timer_prev = this.step_timer;

        this.step_timer += Time.deltaTime;

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

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

        case STEP.PLAY:
        {
            // ピースがすべて正解の位置に置かれたら、クリアー.
            if (this.piece_finished_num >= this.piece_num)
            {
                this.next_step = STEP.CLEAR;
            }
        }
        break;
        }

        // ---------------------------------------------------------------- //
        // 遷移時の初期化.

        if (this.next_step != STEP.NONE)
        {
            switch (this.next_step)
            {
            case STEP.PLAY:
            {
                // this.active_pieces = this.all_pieces としてしまうと配列への参照をコピー
                // してしまうので、中身をいっこづつコピーする.
                for (int i = 0; i < this.all_pieces.Length; i++)
                {
                    this.active_pieces[i] = this.all_pieces[i];
                }

                this.piece_finished_num = 0;

                this.shuffle_pieces();

                foreach (PieceControl piece in this.active_pieces)
                {
                    piece.Restart();
                }

                // ピースの描画順を設定する.
                //
                this.set_height_offset_to_pieces();
            }
            break;

            case STEP.CLEAR:
            {
            }
            break;
            }

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

            this.step_timer = 0.0f;
        }

        // ---------------------------------------------------------------- //
        // 実行処理.

        switch (this.step)
        {
        case STEP.CLEAR:
        {
            // 完成時のジングル.

            const float play_se_delay = 0.40f;

            if (this.step_timer_prev < play_se_delay && play_se_delay <= this.step_timer)
            {
                this.game_control.playSe(GameControl.SE.COMPLETE);
                this.is_disp_cleared = true;
            }
        }
        break;
        }

        PazzleControl.DrawBounds(this.shuffle_zone);
    }
Ejemplo n.º 5
0
    void Update()
    {
        this.state_timer_prev = this.state_timer;
        this.state_timer     += Time.deltaTime;

        switch (this.state)
        {
        case STATE.NONE:
        {
            this.next_state = STATE.PLAY;
        }
        break;

        case STATE.PLAY:
        {
            if (this.piece_finished_num >= this.piece_num)
            {
                this.next_state = STATE.CLEAR;
            }
        }
        break;
        }

        if (this.next_state != STATE.NONE)
        {
            switch (this.next_state)
            {
            case STATE.PLAY:
            {
                for (int i = 0; i < this.all_pieces.Length; i++)
                {
                    this.active_pieces[i] = this.all_pieces[i];
                }

                this.piece_finished_num = 0;

                this.shuffle_pieces();

                foreach (PieceControl piece in this.active_pieces)
                {
                    piece.Restart();
                }
            }
            break;

            case STATE.CLEAR:
            {
            }
            break;
            }

            this.state       = this.next_state;
            this.next_state  = STATE.NONE;
            this.state_timer = 0.0f;
        }

        switch (this.state)
        {
        case STATE.CLEAR:
        {
            this.is_disp_cleared = true;
        }
        break;
        }

        PazzleControl.DrawBounds(this.shuffle_zone);
    }