我有一个名为玩家的图片框和4个图片框,它们在游戏开始时充当边界。我有这个代码,如果按下一个键,就会执行:
private void HorrorForm_KeyDown(object sender, KeyEventArgs e)
{
int x = player.Location.X;
int y = player.Location.Y;
if (e.KeyCode == Keys.D)
x += 7;
if (e.KeyCode == Keys.A)
x -= 7;
if (e.KeyCode == Keys.S)
y += 7;
if (e.KeyCode == Keys.W)
y -= 7;
if (player.Bounds.IntersectsWith(openspot1.Bounds) || player.Bounds.IntersectsWith(openspot2.Bounds) || player.Bounds.IntersectsWith(openspot3.Bounds) || player.Bounds.IntersectsWith(openspot4.Bounds))
{
player.Location = new Point(player.Location.X - 1, player.Location.Y - 1);
}
player.Location = new Point(x, y);
}
如何移动玩家,但阻止他离开边界?
跃然一笑
相关分类