public Paddle(int width, int height, int speed, Vector2 positon, int scale, Court court, Keys up, Keys down) { _paddleWidth = width; _paddleHeight = height; _paddleSpeed = speed; currentPosition = positon * scale; originalPosition = currentPosition; this.scale = (float)scale; this.court = court; moveUp = up; moveDown = down; }
protected override void Initialize() { graphics.PreferredBackBufferWidth = WindowsWidth; graphics.PreferredBackBufferHeight = WindowsHeight; graphics.ApplyChanges(); pongMenu = new Menu(MenuWidth, MenuHeight, menuStartPoint, Scale); pongCourt = new Court(CourtWidth, CourtHeight, Scale, CourtBorder); ballDirection = new Point(rad.Next(1, 2), rad.Next(1, 3)); pongBall = new Ball(BallWidthAndHeight, Scale, ballSpeed, ballStartPosition, pongCourt, ballDirection); pongPaddleOne = new Paddle(PaddleWidth, PaddleHeight, paddleSpeed, paddleOneStartPosition, Scale, pongCourt, Keys.W, Keys.S); pongPaddleTwo = new Paddle(PaddleWidth, PaddleHeight, paddleSpeed, paddleTwoStartPosition, Scale, pongCourt, Keys.Up, Keys.Down); pongHUD = new HUD(HUDBoardWidth, HUDBoardHeight, Scale, HUDStartPosition); PaddleOneColor = Color.White; PaddleTwoColor = Color.White; base.Initialize(); }
public Ball(int widthAndHeight, int scale, int ballSpeed, Vector2 startPosition, Court court, Point direction) { int vectorX = 0; int vectorY = 0; this._widthAndHeight = widthAndHeight; this.scale = (float)scale; this.ballSpeed = ballSpeed; originalSpeed = this.ballSpeed; this.currentPosition = startPosition * scale; this.court = court; if (direction.X == 1) { vectorX = 1; } else if (direction.X == 2) { vectorX = -1; } if (direction.Y == 1) { vectorY = 0; } else if (direction.Y == 2) { vectorY = 1; } else if (direction.Y == 3) { vectorY = -1; } if (vectorX != 0 || vectorY != 0) { this.ballDirection = new Vector2(vectorX, vectorY); } else { this.ballDirection = new Vector2(1, 1); } }