/// <summary> /// /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { if (Input.XInputHelper.GamePads[PlayerIndex.One].APressed) { this.mStickedToVausSecs = 0f; } float dt = (float)gameTime.ElapsedGameTime.TotalSeconds; switch (mBallState) { case eBallState.Normal: if (mStickedToVausSecs > 0) { this.mPosition = mGame.mVaus.mPosition + this.mStickedToVausOffset; mStickedToVausSecs -= dt; } else { mStickedToVausSecs = 0f; this.CheckCollisions(dt); // Refresh ball position this.mPosition.X = (float)this.mPosition.X + (this.mDir.X * this.mSpeed * this.mMultVelocidad * dt); this.mPosition.Y = (float)this.mPosition.Y + (this.mDir.Y * this.mSpeed * this.mMultVelocidad * dt); // Check fallen ball if (this.mPosition.Y > (mGame.mGameRectangle.Y + mGame.mGameRectangle.Height - mRadiusPixels)) { Sound.Sound.Play(eSounds.Death); this.mBallState = eBallState.Dying; this.mDyingColor = new Vector4(1f, 1f, 1f, 1f); this.mDyingTime = 2; } } // Balls will be drawn with Pos in the center of the sprite, instead of top left // corner. Just to make calcs easier mDrawingRectangle = new Rectangle((int)(this.mPosition.X - mRadiusPixels), (int)(this.mPosition.Y - mRadiusPixels), (int)this.mDiameterPixels, (int)this.mDiameterPixels); break; case eBallState.Dying: this.mDyingTime -= dt; this.mDyingColor.W -= dt; if (this.mDyingTime <= 0) { this.mBallState = eBallState.Dead; } break; } base.Update(gameTime); }
/// <summary> /// Balls are created dynamically inside a game or when the game is reset, not when /// game starts. Thats why I pass the texture and spriteBatch as a parameter in the constructor /// instead of assigning them in the LoadGraphicsContent, which will be called just once at game start /// </summary> public Ball(XNArkanoidGame pGame) : base(pGame) { this.mGame = pGame; this.mDiameterPixels = 16; this.mRadiusPixels = 8; this.mDir = new Vector2(1f, -1f); this.mDir.Normalize(); this.mSpeed = cSpeedNormal; this.mBallState = eBallState.Normal; //XNArkanoid.mKeyboard.KeyDown += new global::XNArkanoid.Input.KeyboardInput.KeyDelegate(mKeyboard_KeyDown); }