protected override void Initialize() { //Add your initialization logic here player = new Paddle(); player2 = new Paddle(); ball = new Ball(); MediaPlayer.Volume = 0.25f; MediaPlayer.IsRepeating = true; random = new Random(); base.Initialize(); }
void Input(GameTime gameTime, Ball ball) { StartPos(); var t = gameTime.ElapsedGameTime.TotalSeconds; Position.Y = MathHelper.Clamp(Position.Y, 0, Game1.graphics.GraphicsDevice.Viewport.Height - Height); // System.Diagnostics.Debug.WriteLine(Game1.graphics.GraphicsDevice.Viewport.Height + " - " + Height * spriteScale + " - " + paddlePos.Y); switch (inputType) { case (int)InputType.Arrows: if (Keyboard.GetState().IsKeyDown(Keys.Up)) Position.Y -= moveSpeed * (float)t; if (Keyboard.GetState().IsKeyDown(Keys.Down)) Position.Y += moveSpeed * (float)t; break; case (int)InputType.WASD: if (Keyboard.GetState().IsKeyDown(Keys.W)) Position.Y -= moveSpeed * (float)t; if (Keyboard.GetState().IsKeyDown(Keys.S)) Position.Y += moveSpeed * (float)t; break; case (int)InputType.AI: Position.Y = ball.Position2D.Y; break; default: //None break; } }
public void Update(GameTime gameTime, Ball ball) { Input(gameTime, ball); }