2

編集2: フルボール、バット、AIbatクラスへのPastebinリンク。

編集:私はターボコードを更新しました、そしてちょうどそれをもう少し良くコメントしました。このページをあふれさせたくなかったので、PastebinのすべてのGameplayScreenコードへのリンクもあります。

ポンタイプのゲームを作っています。私は3つのことを引き起こすパワーアップを作成しています:

1)ボールが遅くなる(動作する)2)画面が白黒に変わる(動作する)3バットが遅くなる(動作しない

「速度」変数を使用してボールの速度を調整するだけで、すべて正常に機能します。コウモリでも同じことをしようとしていますが、ゲーム中に速度に変化は見られません。ただし、デバッグすると、電源投入がアクティブになった後、速度変数にカーソルを合わせると、デフォルトの速度である7.0fから30.0fに変更されていることがわかりますが、ゲーム自体に目に見える変化はありません。

また、バットとボールの速度を表示するデバッグを画面上で実行していますが、それに応じてボールの速度が変化することに気付きました。彼の右バット(AiBat)も同様です。30に移動します。

しかし、何らかの理由で、左のバット(プレイヤーがコントロールしたバット)は同じ速度のままです。奇数。

私はここで何か間違ったことをしていますが、私の一生の間それを理解することはできません。ある場所で速度を変更でき、それが正常に機能するのに、別の場所では機能しないのはなぜですか?

Class bat
{

        /// <summary>
    /// Controls the bat moving up the screen
    /// </summary>
    public void MoveUp()
    {
        SetPosition(Position + new Vector2(0, -moveSpeed * elapsedTime));

    }

        /// <summary>
    /// Updates the position of the AI bat, in order to track the ball
    /// </summary>
    public virtual void UpdatePosition(Ball ball, GameTime gameTime)
    {
        size.X = (int)Position.X;
        size.Y = (int)Position.Y;

        elapsedTime = 50.0f * (float)gameTime.ElapsedGameTime.TotalSeconds;

        // Just here for debugging. Hitting Z WORKS FINE and slows the bats down
        previous = current;
        current = Keyboard.GetState();
        if (current.IsKeyDown(Keys.Z))
        {
            elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds * 5.0f;
        }
    }
 }

Class GameplayScreen
{

  .......
  private int disableCooldown;
  private int coolDown;
  private int powerDisableCooldown = 2000;
  private int powerEnableCooldown = 5000;
  ......


        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)

                // Updating bat position
                leftBat.UpdatePosition(ball, gameTime);
                rightBat.UpdatePosition(ball, gameTime);

                if (gScaleActivated == true)
                {
                    leftBat.moveSpeed = 30.0f;
                    rightBat.moveSpeed = 30.0f;
                }


                // If spaceBar is down and the turbo bar is not empty, activate turbo. If not, turbo remains off 
                if (input.ActivateTurbo(ControllingPlayer))
                {
                    if (disableCooldown > 0)
                    {
                        leftBat.isTurbo = true;
                        coolDown = powerEnableCooldown;
                        leftBat.moveSpeed = 30.0f;
                        disableCooldown -= gameTime.ElapsedGameTime.Milliseconds;
                    }
                    else
                    {   
                        leftBat.DisableTurbo();
                    }
                }

                    // If spacebar is not down, begin to refill the turbo bar
                else
                {
                    leftBat.DisableTurbo();
                    coolDown -= gameTime.ElapsedGameTime.Milliseconds;
                    // If the coolDown timer is not in effect, then the bat can use Turbo again
                    if (coolDown < 0)
                    {
                        disableCooldown = powerDisableCooldown;
                    }
                }

                // Makes sure that if Turbo is on, it is killd it after () seconds
                if (leftBat.isTurbo)
                {
                    disableCooldown -= gameTime.ElapsedGameTime.Milliseconds;
                }

    /// <summary>
    /// Logic to trigger Powerups
    /// </summary>
    private void PowerupActivated(object sender, PowerupEventArgs e)
    {
       ...........
                           case PowerupType.SlowMo:
                    {
                        this.SlowMo(gScaleActivated);
                        gScaleActivated = true;
                        break;
                    }
       ...........
    }


    // Activates the SlowMo and grayscale effect for the powerup.
    public void SlowMo(bool gScaleActivated)
    {
                    gScaleActivated = true;
                    ball.SlowMoBall();
                    AudioManager.Instance.PlaySoundEffect("SlowMotion1");
    }
}
4

2 に答える 2

0

まあ、それは奇妙です。私はそれを解決しました。ターボコードをコメントアウトしただけです。なぜslowMoと関係があるのか​​わかりません。これは、スペースバーを押したときにのみアクティブになるためです。

                    #region Turbo stuff
                // If spaceBar is down and the turbo bar is not empty, activate turbo. If not, turbo remains off 
                if (input.ActivateTurbo(ControllingPlayer))
                {
                    if (disableCooldown > 0)
                    {
                        leftBat.isTurbo = true;
                        coolDown = powerEnableCooldown;
                        leftBat.moveSpeed = 30.0f;
                        disableCooldown -= gameTime.ElapsedGameTime.Milliseconds;
                    }
                    else
                    {
                        leftBat.DisableTurbo();
                    }
                }

                    // If spacebar is not down, begin to refill the turbo bar
                else
                {
                    leftBat.DisableTurbo();
                    coolDown -= gameTime.ElapsedGameTime.Milliseconds;
                    // If the coolDown timer is not in effect, then the bat can use Turbo again
                    if (coolDown < 0)
                    {
                        disableCooldown = powerDisableCooldown;
                    }
                }

                // Makes sure that if Turbo is on, it is killd it after () seconds
                if (leftBat.isTurbo)
                {
                    disableCooldown -= gameTime.ElapsedGameTime.Milliseconds;
                }

                if (disableCooldown < 0)
                {
                    leftBat.isTurbo = false;
                }

                #endregion 
于 2012-07-03T10:53:16.360 に答える
0

すべてのクラスが表示されない場合、UpdateでmoveSpeedを設定する前にUpdatePositions呼び出しを行うため、左側のバットはmoveSpeedをさらに下にリセットし、各サイクルでUpdatePosition呼び出しを行うときに一時的にリセット値のままになると推測されます。これをテストするには、位置を更新する前にmoveSpeedを設定してみてください。

            leftBat.UpdatePosition(ball, gameTime);
            rightBat.UpdatePosition(ball, gameTime);

            if (gScaleActivated == true)
            {
                leftBat.moveSpeed = 30.0f;
                rightBat.moveSpeed = 30.0f;
            }
于 2012-07-02T10:47:40.840 に答える