Ejemplo n.º 1
0
    //------------------------------------------------------------------------------------------
    // Update
    //------------------------------------------------------------------------------------------
    void Update()
    {
        jumpTiming = false;

        // 故障中の処理
        if (deathFlag)
        {
            DeathUpdate();
        }

        // 敵接触カウント
        if (hitCount > 0)
        {
            hitCount--;
        }

        if (autoControl)
        {
            bulletGenerator.DisableGuideLines();
            if (transform.position.x < targetPos.x - 0.1f)
            {
                Data.playerDir   = lastDir = dir = 1;
                stickSence       = 0.1f;
                autoMoveFinished = false;
            }
            else if (transform.position.x > targetPos.x + 0.1f)
            {
                Data.playerDir   = lastDir = dir = -1;
                stickSence       = 0.1f;
                autoMoveFinished = false;
            }
            else
            {
                dir              = 0;
                stickSence       = 0;
                autoMoveFinished = true;
            }

            return;
        }

        if (!canControl)
        {
            dir = Integer.ZERO;
            bulletGenerator.DisableGuideLines();
            return;
        }

        // プレイヤー操作系統 (入力が必要なもの)--------------------------------------------------
        // コントローラの接続チェック
        checkController = gamaepadManager.GetCheckGamepad();

        // 左右移動
        if (Input.GetAxis(Player.HORIZONTAL) < Integer.ZERO)
        {
            dir        = -1;
            dirCount   = turnCount;
            stickSence = Input.GetAxis(Player.HORIZONTAL);
        }
        else if (Input.GetAxis(Player.HORIZONTAL) > Integer.ZERO)
        {
            dir        = 1;
            dirCount   = turnCount;
            stickSence = Input.GetAxis(Player.HORIZONTAL);
        }
        else
        {
            dir = 0;
        }

        // バレットの発射
        bool releaseAttack = Input.GetButtonUp(Player.ATTACK);
        var  balloonFloor  = Input.GetAxis(GamePad.BUTTON_B);

        if (releaseAttack && Data.balloonSize >= bulletCost)
        {
            float angle = 0.0f;
            float v     = Input.GetAxis(Player.VERTICAL);
            float h     = Input.GetAxis(Player.HORIZONTAL);
            if (Mathf.Abs(h) > 0.1f || Mathf.Abs(v) > 0.1f)
            {
                angle = Mathf.Atan2(v, h);
            }
            else if (Data.playerDir < 0)
            {
                angle = Mathf.PI;
            }
            if (bulletGenerator.BulletCreate(transform.position, angle))
            {
                balloonController.UseBalloon(bulletCost);
            }
        }

        // バレットの発射ボタンを押している間、ガイドラインを表示する
        if (Input.GetButton(Player.ATTACK))
        {
            stickSence = 0.0f;
            dir        = 0;
            var inputDir = new Vector2(Input.GetAxis(Player.HORIZONTAL), Input.GetAxis(Player.VERTICAL));
            if (inputDir.magnitude > 0)
            {
                bulletGenerator.EnableGuideLines(transform.position, Mathf.Atan2(inputDir.y, inputDir.x));
            }
            else
            {
                bulletGenerator.EnableGuideLines(transform.position, (Data.playerDir >= 0 ? 0 : Mathf.PI));
            }
        }
        else
        {
            bulletGenerator.DisableGuideLines();
        }

        // 空中ブースト
        jumpButton  = Input.GetAxis(Player.JUMP);
        boostButton = Input.GetAxis(Player.BOOST);
        float sticV = Mathf.Abs(Input.GetAxis(Player.VERTICAL));

        if ((jumpButton > 0 && jumpButtonTrigger == 0.0f && boostCost <= Data.balloonSize && jumpCount > 0) || (boostButton > 0 && boostButtonTrigger == 0.0f && boostCost <= Data.balloonSize))
        {
            Vector2 direction = new Vector2(Input.GetAxis(Player.HORIZONTAL), Input.GetAxis(Player.VERTICAL));
            if (sticV <= 0.1f)
            {
                direction.y = 0;
            }
            direction.Normalize();

            Boost(direction);

            // エフェクトを生成する
            EffectGenerator.BoostTrailFX(new BoostTrailFX.Param(Color.white, 0.5f, rig), transform.position);
            balloonController.UseBoost(boostCost, 1.3f);

            SoundPlayer.Play(audios[(int)AudioType.Acceleration]);

            boostCount--;
        }

        // エネミーを利用したブースト(仮)
        if (isEnemyBoost)
        {
            Boost(Vector3.zero);
        }


        // ジャンプ
        if (hitCount == 0)
        {
            if (canJump && jumpButton > 0 && jumpButtonTrigger == 0.0f && isGround)
            {
                if (this.rig.velocity.y <= 0)
                {
                    jumpCount = 1;
                    rig.AddForce(new Vector2(0, jumpForce));
                    isGround     = false;
                    jumpStopFlag = false;
                    jumpTiming   = true;

                    SoundPlayer.Play(audios[(int)AudioType.Jump]);
                }
            }
        }

        // 前フレームのキー入力の情報保持
        // Jump
        jumpButtonTrigger = jumpButton;
        // Boost
        boostButtonTrigger = boostButton;
        // ------------------------------------------------------------------------------


        // 切り替えし(地上にいるときのみ)
        if (isGround)
        {
            if (lastDir > 0.0f && dir == -1)
            {
                bubbleGenerator.BubbleCreate(transform.position, 1, true);
                dirtManager.SweepDirt();
            }
            if (lastDir < 0.0f && dir == 1)
            {
                bubbleGenerator.BubbleCreate(transform.position, 1, true);
                dirtManager.SweepDirt();
            }
        }

        // 最終入力方向
        dirCount--;
        if (dirCount <= 0 || dir != 0)
        {
            lastDir = dir;
        }

        // プレイヤーの向き保持
        if (dir != 0)
        {
            Data.playerDir = dir;
        }

        // プレイヤーの速度取得
        Data.prePlayerVel     = Data.currentPlayerVel;
        Data.currentPlayerVel = this.rig.velocity;

        // 重力の変更(バブルの個数に応じて)
        float buoyancy = Mathf.Min(maxPowerBalloonSize, Data.balloonSize) / maxPowerBalloonSize;
        float t        = buoyancy * buoyancy;

        rig.gravityScale = Mathf.Lerp(5.0f, 1.5f, t);
        jumpForce        = defaultJumpForce * Mathf.Lerp(1.0f, 0.9f, t);
        playerSpeed      = accelForce * Mathf.Lerp(1.0f, 0.85f, t);

        // エネミーブーストのリセット
        isEnemyBoost = false;
    }