public void CheckForReflection(Paddle paddle1, Paddle paddle2) { Vector2 normal; if (Position.X < BallRadius + PaddleWidth) { if ((Position.Y > paddle1.Position.Y - 40) && (Position.Y < paddle1.Position.Y + 40)) { normal = new Vector2(1, 0); Velocity = Vector2.Reflect(Velocity, normal); } else { Player2Score++; this.ResetPosition(); } } if ((Position.X > graphics.PreferredBackBufferWidth - BallRadius - PaddleWidth)) { if ((Position.Y > paddle2.Position.Y - 40) && (Position.Y < paddle2.Position.Y + 40)) { normal = new Vector2(-1, 0); Velocity = Vector2.Reflect(Velocity, normal); } else { Player1Score++; this.ResetPosition(); } } if (Position.Y < BallRadius) { normal = new Vector2(0, -1); Velocity = Vector2.Reflect(Velocity, normal); return; } if (Position.Y > graphics.PreferredBackBufferHeight - BallRadius) { normal = new Vector2(0, 1); Velocity = Vector2.Reflect(Velocity, normal); return; } }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); ballTexture = Content.Load<Texture2D>("ballNew"); greenPaddleTexture = Content.Load<Texture2D>("newPaddleGreen"); bluePaddleTexture = Content.Load<Texture2D>("newPaddleBlue"); horizontalBlur = Content.Load<Effect>("BlurHorizontally"); verticalBlur = Content.Load<Effect>("BlurVertically"); font = Content.Load<SpriteFont>("ScoreFont"); pp = GraphicsDevice.PresentationParameters; blurHr = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth / 2, pp.BackBufferHeight / 2); blurVr = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth / 2, pp.BackBufferHeight / 2); wholeScene = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight); ball = new Ball(graphics, ballTexture); paddle1 = new Paddle(graphics, greenPaddleTexture, new Vector2((float) greenPaddleTexture.Width / 2, (float) graphics.PreferredBackBufferHeight / 2), Keys.A, Keys.Z); paddle2 = new Paddle(graphics, bluePaddleTexture, new Vector2((float) graphics.PreferredBackBufferWidth - bluePaddleTexture.Width / 2, (float) graphics.PreferredBackBufferHeight / 2), Keys.Up, Keys.Down); gameMessage = new GameMessageManager(paddle1, paddle2, ball); }
public GameMessageManager(Paddle paddle1, Paddle paddle2, Ball ball) { this.paddle1 = paddle1; this.paddle2 = paddle2; this.ball = ball; }