/// <summary> /// Update the specified gameTime and gameObjects. /// </summary> /// <returns>The update.</returns> /// <param name="gameTime">Game time.</param> /// <param name="gameObjects">Game objects.</param> public override void Update(GameTime gameTime, GameObjects gameObjects) { var touchState = TouchPanel.GetState(); foreach (var touch in touchState) { //Fire the ball if (touch.State != TouchLocationState.Released && attachedToPaddle != null) { ///<summary> /// Ball Reflects off of walls /// </summary> if (touch.Position.Y < (TouchPanel.DisplayWidth / 2)) { var newVelocity = new Vector2(BALL_SPEED_X, attachedToPaddle.Velocity.Y * 1.2f); Velocity = newVelocity; attachedToPaddle = null; } } } if (attachedToPaddle != null) { Location.X = attachedToPaddle.Location.X + attachedToPaddle.Width; Location.Y = attachedToPaddle.Location.Y; } else { ///<summary> /// Classification for the collision of the Ball with a game paddle /// </summary> if (BoundingBox.Intersects(gameObjects.PlayerPaddle.BoundingBox) || BoundingBox.Intersects(gameObjects.ComputerPaddle.BoundingBox)) { Velocity = new Vector2(-Velocity.X, Velocity.Y); } } base.Update(gameTime, gameObjects); }
/// <summary> /// Update the specified gameTime and gameObjects. /// </summary> /// <returns>The update.</returns> /// <param name="gameTime">Game time.</param> /// <param name="gameObjects">Game objects.</param> public override void Update(GameTime gameTime, GameObjects gameObjects) { var touchState = TouchPanel.GetState(); if (playerTypes == PlayerTypes.COMPUTER) { var random = new Random(); var reactionThreshold = random.Next(30, 130); //computer logic if (gameObjects.Ball.Location.Y + gameObjects.Ball.Heigth < Location.Y + reactionThreshold) { Velocity = new Vector2(0, -PADDLE_SPEED); } if (gameObjects.Ball.Location.Y > Location.Y + Heigth + reactionThreshold) { Velocity = new Vector2(0, PADDLE_SPEED); } } if (playerTypes == PlayerTypes.HUMAN) { foreach (var touch in touchState) { if (touch.State != TouchLocationState.Released) { if (touch.Position.Y < (TouchPanel.DisplayWidth / 2)) { Velocity = new Vector2(0, -PADDLE_SPEED); } if (touch.Position.Y > (TouchPanel.DisplayWidth / 2)) { Velocity = new Vector2(0, PADDLE_SPEED); } } } } base.Update(gameTime, gameObjects); }
}/// <summary> /// Update the specified gameTime and gameObjects. /// </summary> /// <returns>The update.</returns> /// <param name="gameTime">Game time.</param> /// <param name="gameObjects">Game objects.</param> public virtual void Update(GameTime gameTime, GameObjects gameObjects) { Location += (Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds); CheckBounds(); }