2
这个游戏还没有完成,我创造了球击中板的部分,但是在比赛中有问题,那就是板上的球。为了更好的理解和支持,我已经在下面附上了一张图片,请观看它,并让我知道你对这个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);
}
}
}
为了更好的理解和支持我已经把视频https://youtu.be/WSZxw42qR-E –