예제 #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        var d = hpBar.dimensions;

        d.Set(d.x + (dimensionsX - d.x) * .3f, hpBar.dimensions.y);
        hpBar.dimensions = d;
        Vector3 p = hpEff.transform.position;

        p.x = hpBar.transform.position.x + d.x / 100;
        hpEff.transform.position = p;
        if (BeatGame.instance.playState != BeatGame.PLAY_STATE.PLAYING || !alive)
        {
            return;
        }

        //runTime+= Time.fixedDeltaTime;
        runTime = BeatGame.instance.audioSource.time;
        #region 添加箭头
        for (int i = beatIndex, c = curBeats.Length; i < c; i++)
        {
            SongTime songTime = curBeats[i];
            if (runTime >= (songTime.showTime - moveToTopTime))
            {
                if (i >= beatIndex)
                {
                    beatIndex = i + 1;
                }
                Arrow arrow;
                if (songTime is LongSongTime)
                {
                    arrow = PrefabPool.instance(longArrowPrefab).GetComponent <LongPressArrow>();
                    (arrow as LongPressArrow).subState = Arrow.STATE.READY;
                }
                else
                {
                    arrow = PrefabPool.instance(arrowPrefab).GetComponent <Arrow>();
                }
                arrow.SetState(Arrow.STATE.READY);
                arrow.gameObject.SetActive(true);
                arrow.gameObject.transform.parent = arrowContainer.transform;


                if (beatIndex == curBeats.Length)
                {
                    arrow.isLastOne = true;
                }

                GameObject targetArrow = null;
                switch (songTime.direction)
                {
                case SongInfo.DIRECTION.DOWN:
                    targetArrow = downArrow;
                    break;

                case SongInfo.DIRECTION.LEFT:
                    targetArrow = leftArrow;
                    break;

                case SongInfo.DIRECTION.RIGHT:
                    targetArrow = rightArrow;
                    break;

                case SongInfo.DIRECTION.UP:
                    targetArrow = upArrow;
                    break;
                }


                if (songTime is LongSongTime)
                {
                    arrow.GetComponent <LongPressArrow>().SetType(songTime.direction, (songTime as LongSongTime).PressTime * unitSpeedPerFrame * Application.targetFrameRate * 100);
                }
                else
                {
                    arrow.GetComponent <Arrow>().SetType(songTime.direction);
                }
                arrow.transform.localPosition = new Vector3(targetArrow.transform.localPosition.x, bornPosY, 0);
                arrow.SetSongTime(songTime);
                arrows.Add(arrow);
                arrow.Init(runTime - PRESS_DELAY_TIME, unitSpeedPerSec);
            }
            else
            {
                break;
            }
        }



        #endregion

        #region 移动、删除箭头
        for (int i = 0, c = arrows.Count; i < c; i++)
        {
            if (!alive)
            {
                return;
            }
            Arrow a = arrows[i];
            a.Move(runTime);

            bool isLongPress = a is LongPressArrow;

            //超出底线,干掉
            if ((!isLongPress && a.transform.localPosition.y >= (Global.SCREEN_HEIGHT + 1f)) ||
                (isLongPress && a.transform.localPosition.y >= (Global.SCREEN_HEIGHT + 1f + (a as LongPressArrow).height / 100))
                )
            {
                KillArrow(arrows[i]);
            }
            else if ((a.transform.position.y > (END_POSITION_Y + HIT_DISTANCE))) //超过顶部图标,判定MISS
            {
                if (a.state != Arrow.STATE.FAILED)
                {
                    a.SetState(Arrow.STATE.FAILED);
                    SetArrowResult(Global.TIMING_JUAGE_TYPE.MISS, a);
                }
                else if (isLongPress && (a as LongPressArrow).subState != Arrow.STATE.FAILED)
                {
                    Vector3 pos = (a as LongPressArrow).GetSecondArrowPos();
                    if (pos.y > (END_POSITION_Y + HIT_DISTANCE))
                    {
                        (a as LongPressArrow).subState = Arrow.STATE.FAILED;
                        SetArrowResult(Global.TIMING_JUAGE_TYPE.MISS, a);
                    }
                }
            }
            else if (DataUtils.isAutoMode && DataUtils.mode == Global.MODE.MODE_1P) //自动模式
            {
                if (a is LongPressArrow)
                {
                    LongPressArrow l = a as LongPressArrow;
                    switch (l.state)
                    {
                    case Arrow.STATE.READY:
                        if ((a as LongPressArrow).IsPerfectTime(true))
                        {
                            PressKey(a.songTime.direction, JoystickManager.JOYSTICK_KEY_STATE.KEY_DOWN);
                            //Debug.Log("长按:" + a.songTime.direction + "时间:" + runTime);
                        }
                        break;

                    case Arrow.STATE.PRESSING:
                        if (GetJuade(Mathf.Abs(l.GetSecondArrowPos().y - END_POSITION_Y)) == Global.TIMING_JUAGE_TYPE.PREFECT)
                        //if ((a as LongPressArrow).IsPerfectTime(false))
                        {
                            PressKey(a.songTime.direction, JoystickManager.JOYSTICK_KEY_STATE.KEY_UP);
                            //Debug.Log("长按结束:" + a.songTime.direction + "时间:" + runTime);
                        }
                        break;
                    }
                }
                else
                {
                    if (a.IsPerfectTime())
                    {
                        PressKey(a.songTime.direction, JoystickManager.JOYSTICK_KEY_STATE.KEY_DOWN);
                    }
                }


                if (a is LongPressArrow)
                {
                    LongPressArrow l = a as LongPressArrow;
                    if (a.state == Arrow.STATE.PRESSING)
                    {
                        if (l.pressingTime != 0 && (runTime - l.pressingTime) > 0.25f)
                        {
                            SetArrowResult(Global.TIMING_JUAGE_TYPE.PREFECT, a, false);
                            l.pressingTime = runTime;
                        }
                    }
                }
            }
        }

        if (deleteArrows.Count > 0)
        {
            for (int i = 0, c = deleteArrows.Count; i < c; i++)
            {
                arrows.Remove(deleteArrows[i]);
            }
            deleteArrows.Clear();
        }

        #endregion
    }
예제 #2
0
    /// <summary>
    /// 按键
    /// </summary>
    /// <param name="d"></param>
    /// <param name="keyState"></param>
    public void PressKey(SongInfo.DIRECTION d, JoystickManager.JOYSTICK_KEY_STATE keyState)
    {
        Arrow      a;
        GameObject targetArrow = null;


        for (int i = 0, c = arrows.Count; i < c; i++)
        {
            a = arrows[i];
            if (a.songTime.direction != d)
            {
                continue;
            }

            switch (a.songTime.direction)
            {
            case SongInfo.DIRECTION.UP:
                targetArrow = upArrow;
                break;

            case SongInfo.DIRECTION.DOWN:
                targetArrow = downArrow;
                break;

            case SongInfo.DIRECTION.LEFT:
                targetArrow = leftArrow;
                break;

            case SongInfo.DIRECTION.RIGHT:
                targetArrow = rightArrow;
                break;
            }
            float dis = Vector3.Distance(a.transform.position, targetArrow.transform.position);
            Global.TIMING_JUAGE_TYPE type = GetJuade(dis);

            if (a is LongPressArrow)
            {
                LongPressArrow l = a as LongPressArrow;
                switch (l.state)
                {
                case LongPressArrow.STATE.READY:
                    //准备好时,如果按下相应的链接又在区域内,改变为按下状态
                    if (type != Global.TIMING_JUAGE_TYPE.NONE && keyState == JoystickManager.JOYSTICK_KEY_STATE.KEY_DOWN)
                    {
                        l.SetState(LongPressArrow.STATE.PRESSING);
                        l.pressingTime = runTime;
                        SetArrowResult(type, a);
                        float offset = targetArrow.transform.position.y - a.transform.position.y;
                        a.transform.position = targetArrow.transform.position;
                        l.height            += offset * 100;
                        l.AddLongEff(targetArrow.transform.position);
                        return;
                    }
                    break;

                case LongPressArrow.STATE.PRESSING:
                    //如果按下状态时弹起,改为失败状态
                    if (keyState == JoystickManager.JOYSTICK_KEY_STATE.KEY_UP)
                    {
                        dis = Vector3.Distance(l.GetSecondArrowPos(), targetArrow.transform.position);
                        Global.TIMING_JUAGE_TYPE secondType = GetJuade(dis);
                        if (secondType != Global.TIMING_JUAGE_TYPE.NONE)
                        {
                            l.SetState(LongPressArrow.STATE.SUCCESS);
                            l.subState = Arrow.STATE.SUCCESS;
                            KillArrow(a);
                            SetArrowResult(secondType, a, false);
                            Eff.instance.AddArrowEff(targetArrow.transform.position, a.songTime.direction);
                        }
                        else
                        {
                            l.SetState(LongPressArrow.STATE.FAILED);
                        }
                        return;
                    }
                    break;
                }
            }
            else
            {
                if (keyState == JoystickManager.JOYSTICK_KEY_STATE.KEY_DOWN)
                {
                    if (type != Global.TIMING_JUAGE_TYPE.NONE)
                    {
                        KillArrow(a);
                        SetArrowResult(type, a);
                        Eff.instance.AddArrowEff(targetArrow.transform.position, a.songTime.direction);
                        return;
                    }
                }
            }
        }
    }