public override void Update(GameTime gameTime, GameObjects gameObjects) { if (playerType == PlayerTypes.Computer) { var random = new Random(); var reactionTreshold = random.Next(30, 130); if(gameObjects.Ball.Location.Y + gameObjects.Ball.Height < Location.Y + reactionTreshold) Velocity = new Vector2(0, -3.5f); if (gameObjects.Ball.Location.Y > Location.Y + Height + reactionTreshold) Velocity = new Vector2(0, 3.5f); } if (playerType == PlayerTypes.Human) { // move paddle up if (Keyboard.GetState().IsKeyDown(Keys.Left)) Velocity = new Vector2(0, -3.5f); // move paddle down if (Keyboard.GetState().IsKeyDown(Keys.Right)) Velocity = new Vector2(0, 3.5f); } base.Update(gameTime, gameObjects); }
public override void Update(GameTime gameTime, GameObjects gameObjects) { if(Keyboard.GetState().IsKeyDown(Keys.Space) && attachedToPaddle != null) { var newVelocity = new Vector2(5.0f, attachedToPaddle.Velocity.Y * 0.65f); Velocity = newVelocity; attachedToPaddle = null; } if(attachedToPaddle != null) { Location.X = attachedToPaddle.Location.X + attachedToPaddle.Width; Location.Y = attachedToPaddle.Location.Y; } else { if (BoundingBox.Intersects(gameObjects.PlayerPaddle.BoundingBox) || BoundingBox.Intersects(gameObjects.ComputerPaddle.BoundingBox)) { Velocity = new Vector2(-Velocity.X, Velocity.Y); } } base.Update(gameTime, gameObjects); }
public void Update(GameTime gameTime, GameObjects gameObjects) { if (gameObjects.Ball.Location.X + gameObjects.Ball.Width < 0) { ComputerScore++; gameObjects.Ball.AttachTo(gameObjects.PlayerPaddle); } if (gameObjects.Ball.Location.X > gameBoundaries.Width) { PlayerScore++; gameObjects.Ball.AttachTo(gameObjects.PlayerPaddle); } }
public virtual void Update(GameTime gameTime, GameObjects gameObjects) { Location = Location + Velocity; checkBounds(); }