XNA - Pong Clone - Refletindo a bola quando atinge uma parede?
Estou tentando fazer a bola ricochetear nas paredes da parte superior e inferior da minha interface do usuário ao criar um clone Pong 2D. Este é o meu Game.cs
public void CheckBallPosition()
{
if (ball.Position.Y == 0 || ball.Position.Y >= graphics.PreferredBackBufferHeight)
ball.Move(true);
else
ball.Move(false);
if (ball.Position.X < 0 || ball.Position.X >= graphics.PreferredBackBufferWidth)
ball.Reset();
}
No momento eu estou usando isso no meu Ball.cs
public void Move(bool IsCollidingWithWall)
{
if (IsCollidingWithWall)
{
Vector2 normal = new Vector2(0, 1);
Direction = Vector2.Reflect(Direction,normal);
this.Position += Direction;
Console.WriteLine("WALL COLLISION");
}
else
this.Position += Direction;
}
Funciona, mas estou usando um Normal digitado manualmente e quero saber como calcular o normal das partes superior e inferior da tela?