嗨,所以我在视觉工作室中使用 c# 制作这个自上而下的射击游戏,由于某种原因,我无法阻止图片框移出边界,现在发生的情况是,如果我将图片框放在右下角手角然后它可以工作,但如果我将图片框放在中心则不起作用这是我的代码:
private void Level_1_of__desolor_KeyDown(object sender, KeyEventArgs e)
{
int xpos = CharacterMain.Location.X;
int ypos = CharacterMain.Location.Y;
if (e.KeyCode == Keys.A)
{
this.CharacterMain.Load(@"../Graphics\Energy L.png");
}
else if (e.KeyCode == Keys.D)
{
this.CharacterMain.Load(@"../Graphics\Energy R.png");
CharacterMain.Left += speed;
}
else if (e.KeyCode == Keys.W)
{
this.CharacterMain.Load(@"../Graphics\Energy F.png");
CharacterMain.Top -= 10;
}
else if (e.KeyCode == Keys.S)
{
this.CharacterMain.Load(@"../Graphics\Energy B.png");
CharacterMain.Top += 10;
}
if (xpos > 12 && xpos < 1096 && ypos == 523)
{
if (ypos == 523)
{
CharacterMain.Top -= 10;
}
}
if (CharacterMain.Location.Y < 523 && CharacterMain.Location.Y > 12)
{
if (CharacterMain.Location.X == 12)
{
CharacterMain.Left += 10;
}
}
if (CharacterMain.Location.Y < 523 && CharacterMain.Location.Y > 12)
{
if (CharacterMain.Location.X == 12)
{
CharacterMain.Left += 10;
}
}
if (CharacterMain.Location.X > 12 && CharacterMain.Location.X < 1102)
{
if (CharacterMain.Location.Y == 12)
{
CharacterMain.Top += 10;
}
}
}