this game isn't completed yet, i've created the part where the ball hits the board, but there's problem in playing and that's the ball stucking in the board. For a better comprehension and understaning i've attached a video down below , plz watch it and lemme know of your take on this bug.
public partial class PingPong : Form
{
public PingPong()
{
InitializeComponent();
timer1.Enabled = true;
timer1.Interval = 30;
}
int mx = 5;
int my = 5;
private void timer1_Tick(object sender, EventArgs e)
{
if (ball.Bounds.IntersectsWith(boardCenter.Bounds))
{
mx = mx * -1;
my = my * 1;
}
else if (ball.Location.Y >= this.ClientSize.Height - ball.Height)
{
mx = mx * 1;
my = my * -1;
}
else if (ball.Location.Y <= 0)
{
mx = mx * 1;
my = my * -1;
}
else if (ball.Location.X >= this.ClientSize.Width - ball.Width)
{
mx = mx * -1;
my = my * 1;
}
ball.Location = new Point(ball.Location.X + mx, ball.Location.Y + my);
}
private void PingPong_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up)
{
board.Location = new Point(board.Location.X, board.Location.Y - 4);
}
else if (e.KeyCode == Keys.Down)
{
board.Location = new Point(board.Location.X, board.Location.Y + 4);
}
}
}