Paddle handles its own position.
예제 #1
0
 public PongMain()
 {
     InitializeComponent();
     float paddleWidth = 15;
     float paddleHeight = 60;
     paddleLeft = new Paddle(Brushes.White, 0, RenderHeight / 2 - paddleHeight / 2, paddleWidth, paddleHeight);
     paddleRight = new Paddle(Brushes.White, RenderWidth - paddleWidth, RenderHeight / 2 - paddleHeight / 2, paddleWidth, paddleHeight);
     float ballRadius = 15;
     ball = new Ball(Brushes.White, ballRadius, RenderWidth, RenderHeight);
     ball.Spawn();
     scoreLeft = 0;
     scoreRight = 0;
     showSkeletons = false;
 }
예제 #2
0
 public void DetectCollision(Paddle pLeft, Paddle pRight)
 {
     if (y < 0 || y > fieldHeight - r) dy = -dy;
     if ((y >= pLeft.y - r) && (y <= pLeft.y + pLeft.h) && (x <= pLeft.x + pLeft.w)) dx = -dx;
     if ((y >= pRight.y - r) && (y <= pRight.y + pRight.h) && (x + r >= pRight.x)) dx = -dx;
 }